-1

I am currently working on a 2D space simulator where I have two bodies; one is still and other is an orbiting object, which I can also control like a rocket.

I'm using the Newton's gravity: $F = \dfrac{G m_1 m_2}{r^2}$, and I want to calculate the trajectory of that moving object.

Is this even possible?

I think that if I calculate the $x, y$ position of the apogee and perigee it will be easy to determine an ellipse, and then show the path. Or is there any other good approach?

I have the distance $r$ from $m_1$ to $m_2$, the velocity vector of $m_2$, and the positions of $m_1$ to $m_2$. I also have the masses and $G$.

How can I calculate the elliptical trajectory of $m_2$ around $m_1$?

note: assume that $m_2$ is a rocket that I can also change its velocity.

It would be really really helpful if any one helped me to solve this problem; please tell me if I have explained my problem clearly or not.

user325
  • 29
  • 5

4 Answers4

5

The eccentricity vector has a magnitude equivalent to the orbital eccentricity of the ellipse, and points along the line of apsides in the direction from the central body towards the periapsis.

Given:

parameter symbol
radial distance vector $\vec{r}$
velocity vector $\vec{v}$
gravitational parameter $\mu$

As Roger Wood mentions, calculate the specific orbital energy $\varepsilon$ to get the semi-major axis a:

$$\varepsilon = \frac{\|\vec{v}\|^2}{2}-\frac{\mu}{\|\vec{r}\|}$$

$$a = \frac{\mu}{2\varepsilon}$$

If you're using three-dimensional vectors, you can calculate the specific angular momentum $\vec{h}$:

$$\vec{h} = \vec{r} \times \vec{v}$$

Then the eccentricity vector is:

$$\vec{e}=\frac{\vec{v}×\vec{h}}{μ}−\frac{\vec{r}}{\|{r}\|}$$

If you're not using angular momentum as a vector quantity, perhaps because you're doing a 2D simulation, the above equation is equivalent to: $$\vec{e} = \left(\frac{\vec{v}}{\mu} - \frac{1}{\|\vec{r}\|} \right)\vec{r}-\frac{\vec{r} \cdot \vec{v}}{\mu}\vec{v}$$

And, as previously mentioned, orbital eccentricity $e$ is the magnitude of the eccentricity vector:

$$e = \|\vec{e}\|$$

From that, you can get the perifocal unit vector $\hat{p}$ which points in the same direction as the eccentricity vector: $$\hat{p} = \frac{\vec{e}}{e}$$

If your central body is the origin of your coordinate system, then the position vector of the periapsis is:

$$\vec{r_q} = a(1-e)\hat{p}$$

And the one towards the apoapsis is:

$$\vec{r_Q} = -a(1+e)\hat{p}$$

notovny
  • 5,439
  • 1
  • 17
  • 26
  • Whoops, forgot to flip the sign on the apoapsis equation. Fixed now. – notovny Jan 23 '22 at 12:44
  • Thanks for your formulas and detailed explanation. But I dont understand the eccentricity formula. How can we calculate reciprocal of the absolute vector? – user325 Jan 23 '22 at 16:34
  • It would be really helpful to understand if you give a simple example of eccentricity vector calculation. Thanks! – user325 Jan 23 '22 at 16:36
  • @Sarthak I got a bit lax in my notation, perhaps. $|\vec{r}|$ is just the magnitude of the radial distance vector $\vec{r}$ – notovny Jan 23 '22 at 18:56
  • @notovny nice answer, I wasn't aware of the eccentricity vector and the useful closed form – Roger Wood Jan 24 '22 at 03:36
  • Thanks @notovny , I understood the eccentricity vector equation better from this answer. And also i think the $a$ is always considered as positive. – user325 Jan 24 '22 at 06:16
  • @Sarthak Not necessarily. If you're working with hyperbolic trajectories, a number of the elliptical orbital equations work without modifications if semi-major axis is a negative value. The vis-viva equation, the equation for the periapsis listed above, calculating specific orbital energy from semi-major axis, among others. It's a convention I've typically used when throwing together Keplerian orbital simulations of my own; less code to maintain. – notovny Jan 24 '22 at 12:51
  • That said, the sign I forgot to flip was the one inside the parentheses; before I edited it, the equation claimed that the periapsis and apoapsis were at the same distance from the central body. – notovny Jan 24 '22 at 12:56
4

From the initial radius and velocity you can calculate the orbital energy and the angular momentum of the rocket. Both quantities are conserved. The orbital energy is also equal to $-GMm/2a$ which gives you the semimajor axis, $a$. The angular momentum is also equal to $m\sqrt{GMa(1-e^2)}$ which gives you the eccentricity, $e$. You now have the equation of the generic elliptical orbit. To set its orientation, you have to solve to find where the starting point is on the ellipse.

Roger Wood
  • 3,864
  • 15
  • 31
2

Finally made my way through it.....

enter image description here

enter image description here

user325
  • 29
  • 5
1

30 years ago (pre-internet, pre-smart phones) I wrote a very simple numerical 2D orbital simulation program. I calculated the velocity and acceleration separately for the x and y components.

The massive body was at the origin (0,0). I picked an arbitrary iteration interval (10 seconds of flight time).

I fed in a starting position and a starting velocity. For instance, a position in Km (0,7000) and scalar velocity (7.8,0) in Km/sec. This would be an object in LEO travelling parallel to the x-axis.

Next, calculate the gravitational acceleration separately for each axis. For the first 10 sec iteration cycle, there would be no acceleration in the x-axis, but for the y-axis it would be 10 sec*9.8m/sec^2. Calculate the delta-v (0,-98) and the resulting velocity (7.8, -0.098). Update position (78,6922).

Update the display. Repeat the loop. Calculations are all arithmetic, using similar triangles. No trig or vector operations needed.

For LEO you can leave acceleration constant. For higher orbits, adjust acceleration for increasing radius using the (x,y) position.

This simplistic program produced very nice elliptical orbits and Hohmann transfers. An “Earth orbit” took about 10 seconds of processor time, running on an i386.

I could hit “pause”, insert a delta-v, then resume to see the result develop.

This programming approach works for 3 Body problems as well, but I gave up trying to achieve lunar transfers.

If you wish to save data (say, phase angle at apogee or velocity at perigee) it needs a few more programming lines.

To answer your question of how to find the position of apogee and perigee, you plug in your current position and velocity and hit the start button.

I extend a pre-emptive apology to all the real mathematicians and programmers out there for this kindergarten approach and the inevitable mistakes I have made dredging it from my memory.

Woody
  • 21,532
  • 56
  • 146