<p>I solved the issue.</p>
<p>Everything I posted in the OP was correct; I made a simple, stupid sign error when transcribing the expressions into code.</p>
<p>It should also be noted that in the OP, the expression for Pk is wrong.  The correct expression is</p>
<p>Pk =   sin (inc) sin (aop)</p>
<p>Just in case anybody is trying to pull this off themselves!</p>
<p>Thanks for the ideas everyone!</p>
<p>Correct Orbits:</p>
<p><a href="https://i.sstatic.net/zEhfy.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zEhfy.jpg" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2020-08-19T01:46:28.177Z
@uhoh it's not, I answered it in both places
Keegan
CC BY-SA 4.0
2020-08-19T07:04:44.080Z
Oh I thought I'd deleted that about five minutes after I posted it after I re-read this, sorry about that, and *well done!*
uhoh
CC BY-SA 4.0
2020-08-20T01:22:34.807Z
by the way it's also okay to accept one's own answer if one feels it's correct, as it seems it is in this case.
uhoh
CC BY-SA 4.0
2020-08-19T00:19:37.583Z
2020-08-19T00:19:37.583Z
Keegan
<p>I am attempting to render orbital ellipses in software.  Given a set of orbital elements, I am using the Perifocal system to determine a set of points along the curve of the ellipse.  I am using the equation:</p>
<p><strong>r</strong> = r cos(<em>v</em>) <strong>P</strong> + r sin(<em>v</em>) <strong>Q</strong>,</p>
<p>where <em>v</em> is the angle, <strong>P</strong> and <strong>Q</strong> are the perifocal vectors correspondent to <strong>I</strong> and <strong>J</strong>, and r is the polar equation of the conic:</p>
<p>r = p / 1 + e cos(<em>v</em>),</p>
<p>where p is the semi-latus rectum, e is eccentricity, and <em>v</em>, in both equations, is the angle.</p>
<p>I am determining the vectors <strong>P</strong> and <strong>Q</strong> using the following equations:</p>
<pre><code>Pi =   cos (lan) cos (aop) - sin (lan) cos (inc) sin (aop)
Pj =   sin (lan) cos (aop) + cos (lan) cos (inc) sin (aop)
Pk =   sin (inc) cos (aop)

Qi = - cos (lan) sin (aop) - sin (lan) cos (inc) cos (aop)
Qj = - sin (lan) sin (aop) + cos (lan) cos (inc) cos (aop)
Qk =   sin (inc) cos (aop)

</code></pre>
<p>where <em>lan</em> is the Longitude of Ascending Node, <em>aop</em> is the Argument of Periapsis, and <em>inc</em> is the inclination.</p>
<p><strong>This process yields the correct ellipse!</strong>  However, the ellipse does not seem to be centered correctly on its focus; the focus appears to be far too close to the center of the ellipse.  Here is an example:</p>
<p><a href="https://i.sstatic.net/XBoCI.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XBoCI.jpg" alt="enter image description here" /></a></p>
<p>You can see that these two highly eccentric ellipses have their shared center of mass at their centers - not at their respective foci.</p>
<p>Is there some step in my process that I'm missing?  I could just apply an offset to the ellipses, but that would be a hack, I want to solve the problem.</p>
<p>Any help is appreciated!  Thank you!</p>
<p><strong>QUESTION EDITS AND CLARIFICATIONS:</strong></p>
<p>This image is taken from a vantage point nearly normal to the orbital plane; there is almost no perspective here.</p>
<p>Second, a helpful user has pointed out an issue in the equation for Pk. The correct expression is:</p>
<p>Pk = sin (inc) sin (aop)</p>
<p>Unfortunately, this was correct in my code - so while the correction was a good one, it was not the source of my problems.</p>

CC BY-SA 4.0
2020-08-18T19:56:35.323Z
@antispinwards - yes!  I can actually maneuver the camera wherever I need it.  The provided view is nearly dead-on.  You can actually see a really faint coordinate grid to get your bearings.  We are probably like 15-20 degrees off the plane's normal.

However, these two ellipses should be in a drastically different formation.  Even from this slightly ambiguous perspective they're definitely way off.  They should have significant overlap.
Keegan
CC BY-SA 4.0
2020-08-18T23:11:33.677Z
This was [cross-posted in Space SE](https://space.stackexchange.com/q/46059/12102) You didn't know this but cross-posting the same question in multiple SE sites is strongly discouraged because it can lead to answer fragmentation; a future reader may find one copy of the question and the information there (comments, answers) and not find the other copy with more important information. You can no longer delete the copy in Space SE because there is now an answer posted, so let's close this one in such a way that people finding it will be guided to the other copy where answers are accumulating.
uhoh
CC BY-SA 4.0
2020-08-18T23:12:00.573Z
@antispinwards [I wondered about that as well](https://space.stackexchange.com/questions/46059/apparent-centering-problem-when-using-the-perifocal-system-to-draw-orbital-ellip#comment149943_46059) but now there is a [math-based answer](https://space.stackexchange.com/a/46061/12102)
uhoh
CC BY-SA 4.0
2020-08-18T23:16:19.300Z
I’m voting to close this question because it was also [cross-posted in Space SE](https://space.stackexchange.com/q/46059/12102) where answers are currently accumulating.
uhoh
CC BY-SA 4.0
2020-08-18T23:51:13.823Z
Hey guys, I didn't realize that crossposting wasn't allowed - my apologies.  It turns out unfortunately that the math based answer in space SE, was not the source of my issues.
Keegan
<solar-system><astrophysics><orbital-mechanics><binary-star><orbital-elements>
Apparent Centering Problem When Using the Perifocal System to Draw Orbital Ellipses
Keegan
# Apparent Centering Problem When Using the Perifocal System to Draw Orbital Ellipses

(Asked by: username_0 on 2020-08-18)

I am attempting to render orbital ellipses in software. Given a set of orbital elements, I am using the Perifocal system to determine a set of points along the curve of the ellipse. I am using the equation:

**r** = r cos(*v*) **P** + r sin(*v*) **Q**,

where *v* is the angle, **P** and **Q** are the perifocal vectors correspondent to **I** and **J**, and r is the polar equation of the conic:

r = p / 1 + e cos(*v*),

where p is the semi-latus rectum, e is eccentricity, and *v*, in both equations, is the angle.

I am determining the vectors **P** and **Q** using the following equations:

```
Pi =   cos (lan) cos (aop) - sin (lan) cos (inc) sin (aop)
Pj =   sin (lan) cos (aop) + cos (lan) cos (inc) sin (aop)
Pk =   sin (inc) cos (aop)

Qi = - cos (lan) sin (aop) - sin (lan) cos (inc) cos (aop)
Qj = - sin (lan) sin (aop) + cos (lan) cos (inc) cos (aop)
Qk =   sin (inc) cos (aop)

```

where *lan* is the Longitude of Ascending Node, *aop* is the Argument of Periapsis, and *inc* is the inclination.

**This process yields the correct ellipse!** However, the ellipse does not seem to be centered correctly on its focus; the focus appears to be far too close to the center of the ellipse. Here is an example:

[![enter image description here](https://i.sstatic.net/XBoCI.jpg)](https://i.sstatic.net/XBoCI.jpg)

You can see that these two highly eccentric ellipses have their shared center of mass at their centers - not at their respective foci.

Is there some step in my process that I'm missing? I could just apply an offset to the ellipses, but that would be a hack, I want to solve the problem.

Any help is appreciated! Thank you!

**QUESTION EDITS AND CLARIFICATIONS:**

This image is taken from a vantage point nearly normal to the orbital plane; there is almost no perspective here.

Second, a helpful user has pointed out an issue in the equation for Pk. The correct expression is:

Pk = sin (inc) sin (aop)

Unfortunately, this was correct in my code - so while the correction was a good one, it was not the source of my problems.

**Tags:** solar-system, astrophysics, orbital-mechanics, binary-star, orbital-elements

> **Comments:**
> **username_0**: @antispinwards - yes!  I can actually maneuver the camera wherever I need it.  The provided view is nearly dead-on.  You can actually see a really faint coordinate grid to get your bearings.  We are probably like 15-20 degrees off the plane's normal.  However, these two ellipses should be in a drastically different formation.  Even from this slightly ambiguous perspective they're definitely way off.  They should have significant overlap.  
> **username_1**: This was [cross-posted in Space SE](https://space.stackexchange.com/q/46059/12102) You didn't know this but cross-posting the same question in multiple SE sites is strongly discouraged because it can lead to answer fragmentation; a future reader may find one copy of the question and the information there (comments, answers) and not find the other copy with more important information. You can no longer delete the copy in Space SE because there is now an answer posted, so let's close this one in such a way that people finding it will be guided to the other copy where answers are accumulating.  
> **username_1**: @antispinwards [I wondered about that as well](https://space.stackexchange.com/questions/46059/apparent-centering-problem-when-using-the-perifocal-system-to-draw-orbital-ellip#comment149943_46059) but now there is a [math-based answer](https://space.stackexchange.com/a/46061/12102)  
> **username_1**: I’m voting to close this question because it was also [cross-posted in Space SE](https://space.stackexchange.com/q/46059/12102) where answers are currently accumulating.  
> **username_0**: Hey guys, I didn't realize that crossposting wasn't allowed - my apologies.  It turns out unfortunately that the math based answer in space SE, was not the source of my issues.  

---

## 1 answers

### Answer by username_0 on 2020-08-19. Score: 2 | Accepted answer

I solved the issue.

Everything I posted in the OP was correct; I made a simple, stupid sign error when transcribing the expressions into code.

It should also be noted that in the OP, the expression for Pk is wrong. The correct expression is

Pk = sin (inc) sin (aop)

Just in case anybody is trying to pull this off themselves!

Thanks for the ideas everyone!

Correct Orbits:

[![enter image description here](https://i.sstatic.net/zEhfy.jpg)](https://i.sstatic.net/zEhfy.jpg)

> **Comments:**
> **username_0**: @username_1 it's not, I answered it in both places  
> **username_1**: Oh I thought I'd deleted that about five minutes after I posted it after I re-read this, sorry about that, and *well done!*  
> **username_1**: by the way it's also okay to accept one's own answer if one feels it's correct, as it seems it is in this case.  

---

