1
$\begingroup$

I'm trying to write an orbital simulation with patched conics. For my sources I'm using https://orbital-mechanics.space/ and Fundamentals of Astrodynamics (Second Edition).

Both sources suggest to use the following method for determining the position with orbital elements and true anomaly.

  1. Calculate the position in the perifocal frame $$ r = \frac{h^2}{\mu} \frac{1}{1 + e\cos{v}} $$ $$ p = r \cos{v} q = r \sin{v} $$

  2. Rotate the perifocal coordinates by performing 3 rotations:

By performing 3 rotations in order:

  1. Around the Z (up) axis by $-\omega$ (argument of periapsis)
  2. Around the X (right) axis by $-i$ (inclination)
  3. Around the Z (up) axis by $-\Omega$ (longitude of the ascending node)

Now using these methods - no matter what I do I can't get my orbits to look right. I'm comparing them using NASA Orbit Viewer - mostly looking at Mercury and Mars orbits due to their high eccentricity.

And either my orbits are flipped or moving clockwise.

For comparison here's how they should look like: enter image description here

And here's how they actually look like (Mercury orbit is white, Mars orbit is red): enter image description here

Cleary flipped.

The obvious solution seems to be to flip $\sin$ and $\cos$ in the perifocal position calculation. But this then breaks in other palces (i.e. calculating the position of the ascending node as the position at $v = \omega$) and I would rather not stray away from the literature.

What am I missing here?

The project in question is open source, the relevant pieces of code are:

Calculating position at true anomaly

Conversion from perifocal to equatorial

$\endgroup$
5
  • 1
    $\begingroup$ Check your rotation matrices. Are they like the ones here? en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions I suspect you've transposed them. $\endgroup$
    – PM 2Ring
    Nov 30, 2023 at 22:17
  • 3
    $\begingroup$ Is your graphics rendering system right-handed or left-handed (e.g. Unity is left handed). This might account for the difference, depending on where you put the camera. See nbodyphysics.com/blog/gravity-engine-doc-1-3-2-2-2/… for more. $\endgroup$ Nov 30, 2023 at 22:25
  • 1
    $\begingroup$ @nbodyphysics My coordinate system is right-handed y-up. The calculations are done in right-handed z-up. But no matter what I do here the planets either move clockwise or the system is flipped. $\endgroup$
    – Dzejkop
    Nov 30, 2023 at 23:13
  • 1
    $\begingroup$ @PM2Ring matrices seem to be correct I've even pasted the cell-by-cell matrix from the book and it was the same as generated by my code. $\endgroup$
    – Dzejkop
    Nov 30, 2023 at 23:15
  • 1
    $\begingroup$ I edited the question to include code links $\endgroup$
    – Dzejkop
    Nov 30, 2023 at 23:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.