-
Notifications
You must be signed in to change notification settings - Fork 0
/
planet.py
61 lines (52 loc) · 1.43 KB
/
planet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Vector:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __add__(self, other):
return Vector(
x=self.x + other.x,
y=self.y + other.y,
z=self.z + other.z,
)
def __truediv__(self, scalar):
return Vector(
x=self.x / scalar,
y=self.y / scalar,
z=self.z / scalar,
)
def __mul__(self, scalar):
return Vector(
x=self.x * scalar,
y=self.y * scalar,
z=self.z * scalar,
)
def __rmul__(self, scalar):
return self * scalar
def __sub__(self, other):
return Vector(
x=self.x - other.x,
y=self.y - other.y,
z=self.z - other.z,
)
def magnitude(self):
return (self.x**2 + self.y**2 + self.z**2)**0.5
class Planet:
def __init__(self, name, mass, radius, x, y, z, vx, vy, vz):
self.name = name
self.mass = mass
self.radius = radius
self.position = Vector(x, y, z)
self.velocity = Vector(vx, vy, vz)
def copy(self):
return Planet(
name=self.name,
mass=self.mass,
radius=self.radius,
x=self.position.x,
y=self.position.y,
z=self.position.z,
vx=self.velocity.x,
vy=self.velocity.y,
vz=self.velocity.z,
)