-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassiveBody.py
68 lines (48 loc) · 2.33 KB
/
massiveBody.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
62
63
64
65
66
67
68
#######################################################################################################################
# Author: Toren Wallengren
#######################################################################################################################
class massiveBody:
"""This class represents a single massive body with mass, position (coordinate), velocity, and acceleration. Keeps
track of coordinate change over time with the path instance variable."""
def __init__(self,
mass = 1,
coordinate = (0, 0),
velocity = (0, 0),
acceleration = (0, 0)):
"""Initialize instance variables."""
self.mass = mass
self.path = [[],[]]
self.setCoordinate(coordinate)
self.setVelocity(velocity)
self.setAcceleration(acceleration)
def getVelocity(self):
"""Velocity getter method."""
return self.velocity
def setVelocity(self, velocity):
"""Velocity setter method."""
self.velocity = velocity
def getCoordinate(self):
"""Position/coordinate getter method."""
return self.coordinate
def setCoordinate(self, coordinate):
"""Position/coordinate setter method - updates path instance variable as well."""
self.path[0].append(coordinate[0])
self.path[1].append(coordinate[1])
self.coordinate = coordinate
def getMass(self):
"""Mass getter method."""
return self.mass
def getAcceleration(self):
"""Acceleration getter method."""
return self.acceleration
def setAcceleration(self, acceleration):
"""Acceleration setter method."""
self.acceleration = acceleration
def __eq__(self, other):
"""Define equality between two massive bodies. This definition is utilized in nBodySystem.py to prevent the
program from trying to compute the force of gravity of an object on itself (which would be singular)."""
equalCoordinates = self.getCoordinate() == other.getCoordinate()
equalMasses = self.getMass() == other.getMass()
equalVelocities = self.getVelocity() == other.getVelocity()
equalAccelerations = self.getAcceleration() == other.getAcceleration()
return equalCoordinates & equalMasses & equalVelocities & equalAccelerations