Help with Orbit Sim: 2-Body Anomalous Motion Problem

  • Thread starter Thread starter check
  • Start date Start date
  • Tags Tags
    Orbit
Click For Summary
The discussion revolves around creating a 2D orbit simulator, focusing on the issue of anomalous motion observed in a two-body system. The user is experiencing unexpected movement of the heavier mass, which drifts to the right despite having no initial velocity. The solution involves adjusting the initial velocities of both masses relative to the system's barycenter to ensure they balance out. Suggestions include using realistic units and potentially adding a z-axis for improved accuracy. The user expresses gratitude for the insights gained during the discussion.
check
Messages
144
Reaction score
0
I’ve been trying to make a multiple body 2D orbit simulator off and on for a few years now. Just as sort of a hobby, nothing too serious (ie, doesn’t have to model what would happen in a reality exactly but the body motions should be more or less correct)

Well anyway, I’m not a programmer by any sense of the word. The only language I am somewhat okay at is Qbasic.

I recently started work on a simulator again using a more realistic approach. My previous attempts all looked very nice and were simple enough as to allow up to a thousand bodies to be smoothly calculated and displayed. Because of the calculations required in my latest attempt, only about 40 interacting objects at a time can be smoothly done.

Anyway, things are looking pretty nice except I have one major nagging problem:
When testing on 2 bodies (one mass orbiting another much heavier mass) there seems to be an anomalous motion to the system. Now, I expect the centre, heavy mass to wobble as the lighter mass orbits it, however, the wobble is not complete as I would expect. Please see diagram:
http://img142.exs.cx/img142/3865/grav19fe.gif
(Note, because I’m running the program in DOS, I can’t take a screen shot)

The diagram shows 2 complete orbits of m1 about m2. You’ll notice the wobble of m2 is not a complete circle/oval as is expected. This is my problem, I don’t know why. You see that the system also moves to the right for some reason. In this example, m1 is given an initial velocity in the horizontal direction to the right, but m2 is not. Yet for some reason, m2 moves continually rightward. The graphs at the side of the diagram approximates the x and y component velocities of both m1 and m2 during one orbit. You’ll notice that m1 looks just about as it should while m2 never has a negative x velocity. I have no idea why. I’ve tried changing the order in which the forces are calculated, the initial position of m1 with respect to m2 and I still get the same strange incomplete wobble. If I start m1 to the left of m2 and give it an initial vertical velocity, then the wobble of m2 is incomplete, but in the y direction and the motion of the system is now in the y direction.

The way I program is really gross and incoherent, but that’s just my style. The program is attached if anyone can make sense of it. I’ve checked over the calculations and they all seem to be fine. The problem is always with the greater mass.

*Actually while I was writing this, I realized that the problem may be that the forces are added twice (and thus changing velocities) during a loop. I fixed that and now the lighter masses don’t spiral into the heavier ones, but the weird motion of the system still remains.
 

Attachments

Astronomy news on Phys.org
Here's what's happening.

Even though you don't give M2 any initial velocity, the velocity you give to M2 is with respect to M1, not the system barycenter. As you guessed, M2 will not sit still. So it is not the stationary point in your system. That's why it drifts. M2 needs to have a little bit of of leftward motion to counter M1's rightward motion. So that the combined motions on the x-axis = 0. But it must be a weighted calculation unless your masses are the same. For example, if M1 has a velocity of 4 km/s in the x direction relative to M2, and M1 is half the mass of M2, then you should give m1 an initial velocity 2.667 km/s to the right, and M2 an initial velocity of 1.333 km/s to the left. These velocities still add to 4, so m1 will still be moving 4 km/s relative to 2. But now the speeds are relative to the system barycenter, which does not move.

I encountered this problem in Gravity Simulator, a program I wrote in Visual Basic and C++ that is similar to what you're trying to do. ( www.gravitysimulator.com )

By the way, it's not much more work to add the z axis to your computations. If you do this, and you use real units and numbers instead of ones you make up, your system should be quite accurate. ie: Use 6.672e-11 for G, 5.98e24 kg for Earth's mass, express your distances in meters, and your velocity in m/s, and you'll notice that the period of an object at the moon's orbit behaves just like the real moon. Low Earth satellites too.
 
tony873004 said:
Here's what's happening.

Even though you don't give M2 any initial velocity, the velocity you give to M2 is with respect to M1, not the system barycenter. As you guessed, M2 will not sit still. So it is not the stationary point in your system. That's why it drifts. M2 needs to have a little bit of of leftward motion to counter M1's rightward motion. So that the combined motions on the x-axis = 0. But it must be a weighted calculation unless your masses are the same. For example, if M1 has a velocity of 4 km/s in the x direction relative to M2, and M1 is half the mass of M2, then you should give m1 an initial velocity 2.667 km/s to the right, and M2 an initial velocity of 1.333 km/s to the left. These velocities still add to 4, so m1 will still be moving 4 km/s relative to 2. But now the speeds are relative to the system barycenter, which does not move.

I encountered this problem in Gravity Simulator, a program I wrote in Visual Basic and C++ that is similar to what you're trying to do. ( www.gravitysimulator.com )

By the way, it's not much more work to add the z axis to your computations. If you do this, and you use real units and numbers instead of ones you make up, your system should be quite accurate. ie: Use 6.672e-11 for G, 5.98e24 kg for Earth's mass, express your distances in meters, and your velocity in m/s, and you'll notice that the period of an object at the moon's orbit behaves just like the real moon. Low Earth satellites too.


Oh my! Thank you very much. It all makes sense now :biggrin:
Yeah, I was going to add realistic units a bit later on...maybe I'll add a z-axis. But thanks a lot!

EDIT

Just checked out your program. It's great!
 
Last edited:
UC Berkely, December 16, 2025 https://news.berkeley.edu/2025/12/16/whats-powering-these-mysterious-bright-blue-cosmic-flashes-astronomers-find-a-clue/ AT 2024wpp, a luminous fast blue optical transient, or LFBOT, is the bright blue spot at the upper right edge of its host galaxy, which is 1.1 billion light-years from Earth in (or near) a galaxy far, far away. Such objects are very bright (obiously) and very energetic. The article indicates that AT 2024wpp had a peak luminosity of 2-4 x...

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 19 ·
Replies
19
Views
11K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K