# Programming the forces the sun applies on earth

1. Feb 17, 2014

### salimwtf

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..

2. Feb 17, 2014

### willem2

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

3. Feb 17, 2014

### voko

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.

4. Feb 18, 2014

### BvU

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] [Broken] laws. You can then decide to ignore or take into account the eccentricity of earths 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: May 6, 2017