Programming the forces the sun applies on earth

Click For Summary
SUMMARY

This discussion focuses on programming a 2D simulation of Earth's orbit around the Sun, emphasizing the gravitational force formula \( F = \frac{GMm}{R^2} \) and momentum calculations. Key concepts include breaking down momentum into vector components, calculating angular velocity, and using the Euler method for numerical integration. Participants recommend studying Kepler's laws for long-term simulations and suggest using Cartesian coordinates for initial implementations to simplify calculations.

PREREQUISITES
  • Understanding of gravitational force calculations using \( F = \frac{GMm}{R^2} \)
  • Familiarity with vector decomposition in physics
  • Knowledge of numerical integration methods, specifically the Euler method
  • Basic understanding of Kepler's laws of planetary motion
NEXT STEPS
  • Research the Runge-Kutta method for improved numerical integration
  • Study Kepler's laws of planetary motion for accurate long-term simulations
  • Learn about polar coordinates and their application in orbital mechanics
  • Explore advanced simulation techniques for multi-body gravitational systems
USEFUL FOR

Physics enthusiasts, software developers creating simulations, and anyone interested in celestial mechanics and orbital dynamics.

salimwtf
Messages
1
Reaction score
0
Hey guys,

I am trying to create a 2d simulation of the Earth going around the sun. However I am facing an issue. I am not sure what are the forces that apply on the Earth in a 2d aspect.

I know there is the gravitational pull GM1M2/R^2.

I know there is momentum, which is P = V * R, but I have questions regarding it. How do I break it down to a vector? Pi + Pj.. I realize I could probably do something like calculating P and then just doing Pcose(theta)i + Psin(theta)J but what is theta? how do I calculate it? or more like which angle is it?

Also does angular velocity have to do with anything here? if so how do I calculate it?.


Sorry for the many questions. Its sad to admit.. but I took all the calculus based physics classes like 1.5 years ago plus a quantum mechanics class.. And I forgot most of the stuff after I got a job..
 
Physics news on Phys.org
What you do is you choose an initial position and velocity, x and y components for both, and a small timestep \Delta t

Then you update the position

x = x + v_x \Delta t

same for y.

update the velocity:

v_x = v_x + a_x \Delta t
Where
a_x = \frac {F_x} {m}

now F_x = F cos { \phi }

F is what you wrote, and

cos {\phi} = \frac {x_s - x_e} {R}

updating v_y is identical except that F_y = F sin(phi) and

sin {\phi} = \frac {y_s - y_e} {R}

you can find R with pythagoras.

Of course you'll be making error, because the position and velocity will change during the timestep.
This is a rather primitive method (euler method) where the error is proportional to the timestep.
Look up runge-kutta method
 
In 2D, the position, the velocity and the force are vectors with 2 components. It is convenient to set up your coordinate system so that the Sun is at its origin. The position of the Earth is then simply ##x## and ##y##, its velocity is ##v_x## and ##v_y##, and the force is ##F_x## and ##F_y##. The magnitude of the force depends on ##r##, the distance from the Sun, which is given by Pythagoras ## r = \sqrt {x^2 + y^2} ##; thus the magnitude of the force is $$ F = G {mM \over x^2 + y^2 }. $$ The direction of the force is the direction opposite to the position vector, so the direction cosines are obtained from the position vector: $$ \cos \alpha = - {x \over \sqrt{x^2 + y^2}}, \cos \beta = - {y \over \sqrt{x^2 + y^2}} $$ so the components of the force are $$ F_x = F \cos \alpha = - {x \over \sqrt{x^2 + y^2}} G {mM \over x^2 + y^2 } = - G mM x \left(x^2 + y^2 \right)^{-{3 \over 2}} $$ and $$ F_y = F \cos \beta = - G mM y \left(x^2 + y^2 \right)^{-{3 \over 2}} $$ This can be re-formulated in polar coordinates, but that will probably confuse you rather than help at this stage. Stick with the Cartesian coordinates for now, take a stab at integrating your equations numerically with the simple method (Euler's), then things will starting making a lot more sense.
 
Hello Salim,

Depending on the purposes of your simulation you want to put an adequate amount of advance knowledge in it. Just integrating in x and y may be fine for a short period, but if you need something that is stable for a few centuries of simulated time, it would be better to first study and understand Kepler's[/PLAIN] laws. You can then decide to ignore or take into account the eccentricity of Earth's orbit.

If your simulation is a start towards something that includes the moon and perhaps also other planets, do some more research, or be prepared to throw away lots of rapid prototypes...

I came upon this thread via willem2
 
Last edited by a moderator:

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
4K
  • · Replies 77 ·
3
Replies
77
Views
6K
  • · Replies 28 ·
Replies
28
Views
2K
  • · Replies 62 ·
3
Replies
62
Views
6K