# Trajectory in gravitational field

1. Sep 1, 2014

### GhostLoveScore

So, I'm attempting to programm orbit in Unity game engine. So I need equation that shows r and phi depending on time.

Equation for gravitational potential is

U(r)=-k/r+M^2/(2*μ*r^2). Force is -1*derivation of U(r) by r. So I get lots of stupid stuff.

If anybody could help me to integrate this equation to get r(t) I would be grateful.

2. Sep 1, 2014

### ShayanJ

It doesn't work that way. You should integrate the differential equations of motion numerically.

3. Sep 1, 2014

### GhostLoveScore

Can you please explain, what differential equations? Is it m*d^2(x)/dt^2=gravitational force + centrifugal force?

4. Sep 1, 2014

### ShayanJ

If you use polar coordinates $(\rho,\varphi)$, then the equations are:

$\rho^3\ddot \rho+GM \rho=R^4 \omega^2$
and
$\rho^2 \dot\varphi=R^2 \omega$

where $R$ is the initial distance from the centre of force and $\omega$ is the initial angular speed.

5. Sep 1, 2014

### GhostLoveScore

Actually I'm using spherical coordinate system

6. Sep 1, 2014

### ShayanJ

Well, there is absolutely no difference. Because the orbits of an inverse-square field lie on a plane and so the problem is two dimensional and spherical coordinates reduce to polar coordinates in two dimensions.

7. Sep 1, 2014

### vanhees71

Don't forget that
$$M=\mu r^2 \dot{\varphi}=\text{const}.$$
Then you can use the energy-conservation Law
$$\frac{\mu}{2} \dot{r}^2 +U(r)=E=\text{const}$$
substitute
$$\dot{r}=\frac{\mathrm{d}r}{\mathrm{d} \varphi} \dot \varphi=\frac{\mathrm{d}r}{\mathrm{d} \varphi} \frac{M}{\mu r^2}.$$
With this you get a differential equation for the orbit in terms of polar coordinates $r=r(\varphi)$.

To integrate it, just substitute
$$s=\frac{1}{r}$$
into this differential equation.

You find the calculation in my mechanics FAQ (which is, however, in German, but with a lot of equations, so that you should be able to follow the arguments with the above given summary).

http://theory.gsi.de/~vanhees/faq/mech/node42.html

8. Sep 1, 2014

### GhostLoveScore

Thanks guys, that will help.

vanhees71 - in the end I get r=r(phi), but I need r=r(t) and phi=phi(t).

From shyan's equation I get

d$\varphi$/dt=R^2*$\omega$/ρ^2. I don't know how to get dρ/dt

Last edited: Sep 1, 2014
9. Sep 1, 2014

### ShayanJ

The equations I gave are already proper for being integrated numerically. You don't need to change them. You only need to learn about some methods of numerically solving differential equations.

10. Sep 1, 2014

### GhostLoveScore

OK, I will look into that. Few years ago we were solving it in Sage (python).