2
$\begingroup$

I am trying to plot an orbit and am having some success. I have directly calculated the orbital parameters so I am able to plot the ellipse. I am also plotting a path of the orbit as a sanity check. The ellipse from orbital parameters is red and the sanity check is white.

When I only apply tangential velocity such that vp.x=0, things match up exactly.

Pic 1

However, when I add some radial velocity, such that vp.x>0, I have a bit of an issue. It rotates correctly with the "Argument of Periapsis" and maintains the same shape but I need to shift the ellipse to match what I should be getting in white.

Pic 2

Can anyone advise how to calculate the x and y shift required so the red ellipse matches the white?

I am making use of the code shown in the following question and answer to calculate orbital parameters so I can plot the orbital ellipse (in red).

How to calculate the time to apoapsis & periapsis, given the orbital elements?

How to programmatically calculate orbital elements using position/velocity vectors?

Thanks.

$\endgroup$
  • 1
    $\begingroup$ Just curious - are the displayed images from your own code, or from a stand alone program or a web site? If it is public, a link would be helpful! I can't tell what "radial velocity is added to the orbital velocity" actually means here, because the addition is happening inside a program. It looks like the orbit is calculated and then another velocity is just added to the solution - as if the two bodies are just set adrift together in space. $\endgroup$ – uhoh Apr 16 '17 at 3:09
  • 1
    $\begingroup$ Hi uhoh, I thought it would be better to link the code at the end of my question instead of sharing my own, mine is a bit messy atm. If you look at the first link I shared the velocity I was talking about is "Vector3 vel2 = planet.velocity;". The first picture I have shared just includes a Y component and the second picture includes an X and Y component for initial velocity. You can see this under vp in the dat.gui control in the picture. Addition is probably the wrong word it is just a different initial velocity. Does that clear things up a bit? $\endgroup$ – viciouskinid Apr 16 '17 at 4:02
  • 1
    $\begingroup$ Oh, I see! I should have noticed that. I'm going to make some small edits to your question to help point it out for others like me who may have read to quickly. If you click the "edited" icon, you can always select "roll back" if you don't like it, or would like to do it differently. $\endgroup$ – uhoh Apr 16 '17 at 4:07
  • 1
    $\begingroup$ Go ahead. I am very new to all this so I would appreciate that! $\endgroup$ – viciouskinid Apr 16 '17 at 4:37
2
$\begingroup$

Actually quite a simple fix. The "Argument of Periapsis" rotates the ellipse around the primary (sun). As the sun is at one focus of the ellipse all you need is a little trigonometry to calculate the shift for the center of the ellipse.

Pic 3.1

var scale = 10000000;
var rotation = this.ω;

var y = -Math.sin(rotation)*this.x0/scale;
var x = this.x0/scale-Math.abs(Math.cos(rotation)*this.x0/scale);

I had actually tried this before but was incorrectly thinking it was rotating around the orbiting body so instead of using x0 I was using a.

As you can see in the below image it is still not perfect. I seem to have a bit too much energy when calculating the semi-major axis for the ellipse in red.

//Semi-Major Axis
var a = 1 / ((2 / math.norm(r)) - (Math.pow(math.norm(v), 2) / µ));

Pic3.2

Update.

I have found this spreadsheet that also does the calc.

I used this to try to figure out where the error was. Using the input data I used above, m1,m2,v,r it was breaking it so I tried using the input data used in the spreadsheet. This seems to have worked so I assume my input data was the problem.

This form will only let me post 2 links because of my reputation so I will post the others for this update as a comment. Done!

Hopefully a few more people will up vote your question and answer and send you on your way to more rep!

Pic 3.3

$\endgroup$

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.