I am writing a Python script ( GitHub LINK ) to render asteroids / comets / meteoroid orbits. The script also displays the position of the planets and their orbits.
It works correctly for orbits with a small semi-small axis (ie, "smaller" orbits). But when I have an orbit that goes beyond Neptune (for example, Halley's comet), and from some points of view there is a strange effect of "deception" (due to the lack of a better word).
Let me show you what I mean:
Image compilation: http://i.imgur.com/onSZG8s.png

, . "" , .
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
def orbitalElements2Cartesian(a, e, I, peri, node, E):
""" Convert orbital elements to Cartesian coordinates in the Solar System.
Args:
a (float): semi-major axis (AU)
e (float): eccentricity
I (float): inclination (degrees)
peri (float): longitude of perihelion (degrees)
node (float): longitude of ascending node (degrees)
E (float): eccentric anomaly (radians)
"""
if e >=1:
e = 0.99999999
I, peri, node = map(np.radians, [I, peri, node])
theta = 2*np.arctan(np.sqrt((1.0 + e)/(1.0 - e))*np.tan(E/2.0))
r = a*(1.0 - e*np.cos(E))
x = r*(np.cos(node)*np.cos(peri + theta) - np.sin(node)*np.sin(peri + theta)*np.cos(I))
y = r*(np.sin(node)*np.cos(peri + theta) + np.cos(node)*np.sin(peri + theta)*np.cos(I))
z = r*np.sin(peri + theta)*np.sin(I)
return x, y, z
if __name__ == '__main__':
orb_elements = np.array([
[2.363, 0.515, 4.0, 205.0, 346.1],
[0.989, 0.089, 3.1, 55.6, 21.2],
[0.898, 0.460, 1.3, 77.1, 331.2],
[104.585332285, 0.994914, 89.3950, 130.8767, 282.4633]
])
fig = plt.figure()
ax = fig.gca(projection='3d')
E = np.linspace(-np.pi, np.pi, 100)
for i, orbit in enumerate(orb_elements):
a, e, I, peri, node = orbit
if a > 50:
E = np.linspace(-np.pi, np.pi, (a/20.0)*100)
x, y, z = orbitalElements2Cartesian(a, e, I, peri, node, E)
ax.plot(x, y, z, c='#32CD32')
ax.set_xlim3d(-5,5)
ax.set_ylim3d(-5,5)
ax.set_zlim3d(-5,5)
plt.tight_layout()
plt.show()
. !