I have a python program that I use to calculate the xyz positions of a point in a kepler orbit.


It takes the following values to define the orbit.

  • semi-major axis
  • orbit period
  • eccentricity
  • longitude of the ascending node
  • inclination
  • longitude of the pericenter

I can then get a position by supplying a time value.

The solution to my problem would be A javascript function that takes the same values as the python one above, and if given a time returns an xyz.

I have not been able to find such a script - if one exists that could be pointed out to me that would solve my problem.

There is one that comes close:


but this takes different values to calculate the orbit:

  • GM
  • semi_major_axis
  • eccentricity
  • inclination
  • longitude_of_ascending_node
  • argument_of_periapsis
  • time_of_periapsis

It will then give an xyz position if supplied with a time.

However I only have the values that I give to the python script above.

I can see how it might be possible, with minor modifications, that orb.js might be tweaked to perform as keplerOrbit.py but I am neither a javascript programmer or a mathematician.

Any help really appreciated - Thanks.

  • 1
    $\begingroup$ Can you clarity "longitude of the pericenter"? The term does not appear in your code. $\endgroup$ Apr 4 '20 at 13:16
  • $\begingroup$ "longitude of the pericenter" is Argument of periapsis. $\endgroup$
    – deMangler
    Apr 12 '20 at 17:07

Seeing that you already have the orbital period, you can use the mean anomaly directly to calculate the time parameter. This should work if you set time_of_periapsis to 0, as you have all the other required parameters. (GM is 1 since your python program assumes a unit mass system)

Combine everything to a wrapper function, containing nothing but parameter translation and a call to the kepler.js function (kepler.js already has a method of calculating mean anomaly, so you don't need to port any code)

//somewhat pseudocode-ish, as it depends on how you actually want to supply the parameters
function keplerOrbitPy_xyz(/*keplerOrbitPy parameters*/){
  let GM = 1;
  let semi_major_axis = keplerOrbitPy.semi_major_axis;
  let eccentricity = keplerOrbitPy.eccentricity;
  let inclination = keplerOrbitPy.inclination;
  let longitude_of_ascending_node = keplerOrbitPy.longitude_of_ascending_node;
  let argument_of_periapsis = keplerOrbitPy.argument_of_periapsis;
  let time_of_periapsis = 0;
  let time = keplerOrbitPy.orbital_period * /*(kepler.js mean anomaly calculation here)*/ / (2*Math.PI);
  return //call to kepler.js xyz here
  • 1
    $\begingroup$ Thank you. This perfectly gave me what I need. I am in the process of refining my code but from my initial dirty hack the figures are good - already I understand how to do so because of your clarity. $\endgroup$
    – deMangler
    Apr 4 '20 at 17:06

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .