How Do You Calculate Orbital Dynamics in a Simple Java Simulation?

AI Thread Summary
To simulate orbital dynamics in a Java program, it is essential to calculate the velocities of both the Earth and the Sun relative to their common center of mass. Starting with the Sun at rest at the origin allows for the application of Newton's law of gravitation to determine their movements. The center of mass should remain stationary if the initial conditions are set correctly, and any discrepancies in its motion indicate integration errors. It's crucial to understand that both bodies must orbit the center of mass with the same period, which is tied to the Earth's orbital period of 365.2475 days. This ensures that the simulation accurately reflects the gravitational relationship between the two bodies.
whatisreality
Messages
286
Reaction score
1
I'm an undergrad (so my simulation is VERY simple), writing a java program to simulate the solar system. And I'm a bit stuck on how to calculate a couple of important things.

I'm literally right at the start of this, with just a sun and an earth. Initially I had my Earth going round my stationary sun in circles. It worked fine, in the sense that after a year the Earth was back where it started - or the same distance away at least.

Now I've tried to get the Earth and sun to orbit a common centre of mass. This has not worked. It was fairly easy to work out where their centre of mass is, and adjust their initial positions so that the centre of mass is at the origin.
Now it's occurred to me that I don't know what their velocities relative to this centre of mass are. Will Earth's velocity be its orbital velocity? How do I find the velocity of the sun about this common centre of mass? Will the centre of mass stay in the same place?

Thanks for any help!
 
Physics news on Phys.org
Both the sun and the Earth need to orbit that point once every 365.2475 days. So 2πR / 365.2475 days.
 
There are several ways to do this.

One simple way is to start with the sun at rest at the origin, just like you did before, but now let all bodies (Sun and Earth) accelerate according to Newtons law of gravitation. If you then calculate the center of mass and plot it over time you should see the center of mass move in a straight line to within your error of integration. If it does, you can now simply plot the orbit of the bodies relative to the center of mass. If it doesn't, you know you should check your integration procedure.

If you want to start with center of mass in the origin and (hopefully) not moving (as you asked for), then from the position and velocity of all bodies relative to the Sun you can calculate the position and velocity of the center of mass (if you don't know how to do this then please write up the equation for center of mass and ask specific questions where you get stuck). You can now just subtract the position and velocity of the center of mass from all other velocities (including the Sun) before you start integration. Now you should observe that the center of mass stays at the origin. Any (accumulated) error in integration will be even more apparent in this case if the center of mass starts to gain a velocity that do no average to zero.
 
.Scott said:
Both the sun and the Earth need to orbit that point once every 365.2475 days. So 2πR / 365.2475 days.
Why 365 days? I know it's an Earth year obviously, but it's not obvious to me why that should also be the sun's orbital period about this point.
 
How are you going to keep the common center of gravity in the same place if they orbit at different periods?
 
whatisreality said:
Why 365 days? I know it's an Earth year obviously, but it's not obvious to me why that should also be the sun's orbital period about this point.
Imagine a very large man and a very small woman, arms locked together, pirouetting around each other on a dance floor. If she orbits him once every second, how often will he have to orbit her?
 
I have recently been really interested in the derivation of Hamiltons Principle. On my research I found that with the term ##m \cdot \frac{d}{dt} (\frac{dr}{dt} \cdot \delta r) = 0## (1) one may derivate ##\delta \int (T - V) dt = 0## (2). The derivation itself I understood quiet good, but what I don't understand is where the equation (1) came from, because in my research it was just given and not derived from anywhere. Does anybody know where (1) comes from or why from it the...
Back
Top