skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.43k stars 213 forks source link

Position of complete Orbit of planets #302

Open skynoob-new opened 4 years ago

skynoob-new commented 4 years ago

Hello, Skyfield looks really interesting, i would like to know whether it is possible to get the position of orbits of all planets for a specific time and date in ecliptic coordinates. Thank you

brandon-rhodes commented 4 years ago

If you ask for a planet's position at a given time t, you should be able to take that velocity vector and ask for the equivalent Keplerian orbit using:

https://rhodesmill.org/skyfield/api.html#osculating-orbital-elements

Using its reference_frame= parameter, you could, I think, ask for ecliptic instead of the standard J2000 coordinates.

skynoob-new commented 4 years ago

if possible, can you pleas post an example for this, since i am new to this, just trying to start

brandon-rhodes commented 4 years ago

Could you clarify what you mean when you need "the position" of an orbit? Without knowing what number you want for "position", sample code cannot correctly target your specific question. Could you give an example of a planet, date, and the number you want the program to print out?

skynoob-new commented 4 years ago

For any point in time, any planet will have a position in space, but they have an orbit in which they are travelling, i need that orbit data in ecliptic coordinates. Foe example , in the attached image, the red line is orbit of jupiter, yellow line is orbit of sun or rather ecliptic line, i need those points jupandsun

brandon-rhodes commented 4 years ago

The best approach at the moment might simply be to ask the planet for its positions for exactly 1 year following the date. While the end of its orbit won't exactly match its beginning, since all the other Solar System masses that affect its trajectory will have moved, the gap probably won't be visible on this scale.

Hopefully Skyfield will soon learn how to propagate an orbit to produce positions (I'm not sure anyone's written that yet?) so I don't think you can currently use the orbital parameters to produce a curve like this in the sky. But I'll let you know if I run across anything that would make it possible.

ghost commented 4 years ago

Propagating an orbit from osculating elliptical parameters would require solving Kepler's Equation, which has no close form but can be approximated fairly well. Possibly useful links:

https://en.wikipedia.org/wiki/Kepler%27s_equation https://math.stackexchange.com/questions/388134/how-to-calculate-ellipse-sector-area-from-a-focus

If you're into pain, you can look at my Mathematica code that does this using a series of rotations (the only really hard part is converting mean anomaly to true anomaly):

https://github.com/barrycarter/bcapps/blob/master/ASTRO/bc-elliptical-orbit.m#L74

(you'll need to look at ../bclib.m if you go with this approach)