Added Python demo of calculating Jupiter's moons.

The demo shows how to correct for light travel
time to render Jupiter's moons as they appear
from the Earth.

Created an addition operator for the Vector
class in the Python code, because it is handy.

Corrected a bug in the string representation
of the Python StateVector class.
This commit is contained in:
Don Cross
2021-04-15 20:54:37 -04:00
parent 1e2763af63
commit 5a8daba7d5
8 changed files with 107 additions and 4 deletions

View File

@@ -162,6 +162,9 @@ class Vector:
"""Returns the length of the vector in AU."""
return math.sqrt(self.x**2 + self.y**2 + self.z**2)
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y, self.z + other.z, self.t)
class StateVector:
"""A combination of a position vector, a velocity vector, and a time.
@@ -197,7 +200,7 @@ class StateVector:
self.t = t
def __repr__(self):
return 'StateVector[pos=({}, {}, {}), vel=({}, {}, {}), t{}]'.format(
return 'StateVector[pos=({}, {}, {}), vel=({}, {}, {}), t={}]'.format(
self.x, self.y, self.z,
self.vx, self.vy, self.vz,
str(self.t))