add print method to Body object
This commit is contained in:
61
lib/class.py
Normal file → Executable file
61
lib/class.py
Normal file → Executable file
@@ -1,13 +1,12 @@
|
||||
import numpy as np
|
||||
|
||||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Class definition for physical atribute
|
||||
"""
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Body:
|
||||
|
||||
|
||||
|
||||
def __init__(self, mass, position, velocity):
|
||||
self.m = mass
|
||||
@@ -15,6 +14,12 @@ class Body:
|
||||
self.v = velocity
|
||||
self.p = velocity*mass
|
||||
|
||||
def __repr__(self): # Called upon "print(body)"
|
||||
return "Body of mass: {0:.2f}kg, position: {1}, velocity: {2}".format(self.m, self.p, self.v)
|
||||
|
||||
def __str__(self): # Called upon "str(body)"
|
||||
return "Body of mass: {0:.2f}kg, position: {1}, velocity: {2}".format(self.m, self.p, self.v)
|
||||
|
||||
|
||||
class System:
|
||||
|
||||
@@ -49,37 +54,35 @@ class System:
|
||||
return L
|
||||
|
||||
|
||||
#def initialize(self):
|
||||
if __name__ == "__main__":
|
||||
# initialisation mass
|
||||
m1 = 10
|
||||
m2 = 1
|
||||
m3 = 1
|
||||
|
||||
# initialisation position
|
||||
q1 = np.array([0, 0, 0])
|
||||
q2 = np.array([1, 0, 0])
|
||||
q3 = np.array([2, 0, 0])
|
||||
|
||||
# initialisation mass
|
||||
m1 = 10
|
||||
m2 = 1
|
||||
m3 = 1
|
||||
|
||||
# initialisation position
|
||||
q1 = np.array([0, 0, 0])
|
||||
q2 = np.array([1, 0, 0])
|
||||
q3 = np.array([2, 0, 0])
|
||||
|
||||
# initialisation velocity
|
||||
v1 = np.array([0, 0, 0])
|
||||
v2 = np.array([1, 1, 0])
|
||||
v3 = np.array([2, 0, 0])
|
||||
# initialisation velocity
|
||||
v1 = np.array([0, 0, 0])
|
||||
v2 = np.array([1, 1, 0])
|
||||
v3 = np.array([2, 0, 0])
|
||||
|
||||
|
||||
star1 = Body(m1,q1,v1)
|
||||
star2 = Body(m2,q2,v2)
|
||||
star3 = Body(m3,q3,v3)
|
||||
star1 = Body(m1,q1,v1)
|
||||
star2 = Body(m2,q2,v2)
|
||||
star3 = Body(m3,q3,v3)
|
||||
|
||||
Lbodylist = [star1,star2]
|
||||
Lbodylist = [star1,star2]
|
||||
|
||||
array = np.zeros((len(Lbodylist),3))
|
||||
array[0]=star3.q
|
||||
array = np.zeros((len(Lbodylist),3))
|
||||
array[0]=star3.q
|
||||
|
||||
|
||||
tribody = System([star1,star2,star3])
|
||||
tribody = System([star1,star2,star3])
|
||||
|
||||
print("list=",Lbodylist)
|
||||
|
||||
print(tribody.Lval(Lbodylist))
|
||||
print("list=",Lbodylist)
|
||||
|
||||
print(tribody.Lval(Lbodylist))
|
||||
|
||||
0
lib/plots.py
Normal file → Executable file
0
lib/plots.py
Normal file → Executable file
Reference in New Issue
Block a user