3
$\begingroup$

I'm writing a little project that simulates an orbit by converting from initial state vectors $\vec{r}$ and $\vec{v}$ to Keplerian elements, then converting back to $\vec{r}$ and $\vec{v}$ from those Keplerian elements, but stepped one frame ahead. I'm having some trouble with that last part.

I've been using René Schwarz's conversion guide quite a lot, but the transformations and rotations at the end honestly just confuse me, so I ended up just using the True Anomaly and $|\vec{r}|$ to calculate the new $\vec{r}$, which does seem to work, but I'm stumped on how to calculate $\vec{v}$, I have the equation for the velocity at any point on an orbit with

$$v^2 = \mu \left(\frac{2}{|\vec{r}|}-\frac{1}{a}\right)$$

Where I just plug in the new $|\vec{r}|$ and I get $|\vec{v}|$, but trying to use this equation for the tangent vector to any point on an ellipse given the angle, $$-a \cos\theta i + b \cos\theta j$$

Where $a$ is the semi major axis, $b$ is the semi minor axis, and $\theta$ is the angle around the ellipse (I've been using the True Anomaly as input for that angle, is that correct?) doesn't seem to work to find the vector tangent to the ellipse. So my questions are:

  • How do I find the vector tangent to a 2D orbital ellipse given $e$ and $a$, as well as $|\vec{r}|$, $|\vec{v}|$, and the True, Eccentric, and Mean anomaly at that point? (I also have some additional elements that I haven't used yet such as the argument of periapsis if that's useful.)

  • How do I determine which direction that vector should face (so it doesn't point toward retrograde when it should point towards prograde) given the same values as above?

$\endgroup$
2
$\begingroup$

Assuming that the direction of the periapsis is the positive direction of the x-axis, then the vector $-a\sin E\cdot \mathbb{i} + b\cos E\cdot \mathbb{j}$ is tangent to the orbit at the point with the eccentric anomaly $E$. The velocity is codirectional with this vector if the orbit goes counter-clockwise, and contradirectional if the orbit goes clockwise.

If the angle between the positive direction of the x-axis and the direction of the periapsis is $\omega$ (measured counter-clockwise), then you need to rotate the vector by this angle, and the result is $(-a\sin E\cos \omega - b\cos E\sin \omega)\mathbb{i} + (b\cos E\cos\omega - a\sin E\sin\omega)\mathbb{j}$.

$\endgroup$
  • $\begingroup$ For the y component of that last equation you're giving me the output goes between -a and a, does that mean I'm calculating the argument of periapsis wrong? I used this equation from wikipedia: $\omega =\arctan 2({e_{y}},{e_{x}})$. The x value also ranges from some really low value to another. $\endgroup$ – PrimarySecondary Jul 4 '17 at 11:01
  • $\begingroup$ Are $e_x$ and $e_y$ the coordinates of the periapsis relative to the main focus? Then it's correct. But I don't why the $y$-component of the last expression would change between $-a$ and $a$. If you fix $\omega$ and vary $E$, then it should change between $-\sqrt{(a\sin\omega)^2+(b\cos\omega)^2}$ and $\sqrt{(a\sin\omega)^2+(b\cos\omega)^2}$. $\endgroup$ – Litho Jul 4 '17 at 11:18
  • $\begingroup$ Fixed those problems, just random bugs that appeared because of my constant tweaking. The result still doesn't look right. I'm starting with a state vector of (0,-350) (m/s) and (0,~200) (km) from my main mass, so the velocity shouldn't have a magnitude above 350 (periapsis is where I start), but using $\vec{v} = |\vec{v}| \cos(t)i + |\vec{v}| \sin(t)j$ where $t$ is the heading of the vector you gave has magnitude that ranges from 0 to 700. Looking at the numbers, it makes $\vec{v}_x$ oscillate oppositely to $\vec{v}_y$, like one is at apoapsis while the other is at periapsis. $\endgroup$ – PrimarySecondary Jul 4 '17 at 19:46
  • $\begingroup$ Also, my coding library has a vector rotation function, using that on $-a\sin E\cdot \mathbb{i} + b\cos E\cdot \mathbb{j}$ should work, correct? From what I can tell from the source, it rotates by converting the vector to an angle, adding the input angle, then converting back to a vector, is that an equivalent rotation? $\endgroup$ – PrimarySecondary Jul 4 '17 at 20:00
  • $\begingroup$ "I'm starting with a state vector of (0,-350) (m/s) and (0,~200) (km) from my main mass": does the starting velocity point toward the main mass? Then it's not a periapsis, About the rotation: yes, the way you describe should work. $\endgroup$ – Litho Jul 4 '17 at 21:11
1
$\begingroup$

To calculate the velocity vector in a two-body problem, you can use the flight path angle $\phi_{fpa}$ (from Fundamental of Astrodynamics and Applications, D. Vallado). $\phi_{fpa}$ is the angle measured from the local horizon to the velocity vector. For this end, calculate the angular momentum, which is constant: $$ \vec{h} = \vec{r}_0\times \vec{v}_0$$

The position vector norm $||r||$ is: $$||r|| = \frac{a\sqrt{1-e^2}}{1+e\cos{f}}$$ where $f$ is the true anomaly. As you previously showed, the velocity norm as a function of $r$ is $$v^2 = \mu \left(\frac{2}{||r||}-\frac{1}{a} \right)$$

So, $\phi_{fpa}$ is calculated is as such: $$ \cos{\phi_{fpa}} = \frac{||h||}{||r||||v||} $$ $$ \sin{\phi_{fpa}} = \frac{||h||}{||r||||v||}\times\frac{e\sin{f}}{1 + e\cos{f}} $$ $$ \phi_{fpa} = \text{atan2}(\sin{\phi_{fpa}}, \cos{\phi_{fpa}}) $$

Before I show you the velocity vector expression, we need to define the following direction vectors:

Directions

Where $\hat{r}$ is the direction of $\vec{r}$, $\hat{t}$ is in the velocity direction, and $\hat{n}$ is normal to the orbit and to $\hat{t}$. Furthermore, the directions $\hat{r}$ and $\hat{s}$ are perpendicular. Thus, the velocity vector $\vec{v}$ can be expressed as: $$\vec{v} = ||v||\hat{t} = ||v||(\hat{s}\cos{\phi_{fpa}} + \hat{r}\sin{\phi_{fpa}})$$

The calculation of $\vec{r}$ and $\hat{s}$ as a function of some inertial direction is an easy task, using the true anomaly angle $f$.

$\endgroup$
  • $\begingroup$ I'll try this one out tomorrow, but it looks like you have a little typo at first glance, when you show $\vec{v} = v\hat{t}$ do you mean that $\vec{v} = |\vec{v}|\cos(\hat{t})i + |\vec{v}|\sin(\hat{t})k$ ? $\endgroup$ – PrimarySecondary Jul 4 '17 at 11:28
  • $\begingroup$ No. $\hat{t}$ is a unit vector, not a scalar. So, calculating its sine or cosine has no meaning. $v = ||v||$ is the norm of $\vec{v}$ and $\hat{t}$ is a unit vector in $\vec{v}$ direction. $\endgroup$ – Orbital Fun Jul 4 '17 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.