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

In summary, both the sun and the Earth need to orbit that point once every 365.2475 days in order for everything to stay in balance. If you don't do this, then you will see errors in your calculations. To keep the center of mass in the same place, you can use one of several methods.
  • #1
whatisreality
290
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
  • #2
Both the sun and the Earth need to orbit that point once every 365.2475 days. So 2πR / 365.2475 days.
 
  • #3
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.
 
  • #4
.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.
 
  • #5
How are you going to keep the common center of gravity in the same place if they orbit at different periods?
 
  • #6
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?
 

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

1. What is the solar system?

The solar system is the collection of planets, moons, asteroids, and comets that orbit around the sun. It also includes the sun itself, which is a star. Our solar system is located in the Milky Way galaxy and is just one of billions of systems in the universe.

2. How do the planets in our solar system move?

The planets in our solar system move in elliptical (oval) orbits around the sun. This means that they do not move in perfect circles, but rather in a slightly elongated path. This is due to the gravitational pull of the sun and other objects in the solar system.

3. What causes the seasons on Earth?

The tilt of Earth's axis is what causes the seasons on our planet. As Earth orbits around the sun, different parts of the planet are tilted towards or away from the sun, resulting in changes in temperature and weather patterns.

4. How do scientists study the dynamics of the solar system?

Scientists study the dynamics of the solar system through a variety of methods, including observations with telescopes and spacecraft, computer simulations, and mathematical models. They also use data collected from past missions and historical records to better understand the movements and interactions of objects in our solar system.

5. Are the planets in our solar system always in the same order?

No, the planets in our solar system are not always in the same order. Because they are constantly moving in their orbits, the planets can appear in different positions in the sky at different times. However, the order of the planets from the sun (Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune) does not change.

Similar threads

  • Introductory Physics Homework Help
Replies
18
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
19
Views
1K
  • Mechanics
Replies
11
Views
2K
  • Classical Physics
Replies
7
Views
1K
  • Astronomy and Astrophysics
Replies
27
Views
2K
Replies
4
Views
1K
  • Sci-Fi Writing and World Building
Replies
21
Views
2K
  • Astronomy and Astrophysics
2
Replies
52
Views
4K
  • STEM Academic Advising
Replies
4
Views
981
Back
Top