add print method to Body object
This commit is contained in:
59
lib/class.py
Normal file → Executable file
59
lib/class.py
Normal file → Executable file
@@ -1,20 +1,25 @@
|
|||||||
import numpy as np
|
#!/usr/bin/python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Class definition for physical atribute
|
Class definition for physical atribute
|
||||||
"""
|
"""
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class Body:
|
class Body:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, mass, position, velocity):
|
def __init__(self, mass, position, velocity):
|
||||||
self.m = mass
|
self.m = mass
|
||||||
self.q = position
|
self.q = position
|
||||||
self.v = velocity
|
self.v = velocity
|
||||||
self.p = velocity*mass
|
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:
|
class System:
|
||||||
|
|
||||||
@@ -49,37 +54,35 @@ class System:
|
|||||||
return L
|
return L
|
||||||
|
|
||||||
|
|
||||||
#def initialize(self):
|
if __name__ == "__main__":
|
||||||
|
# initialisation mass
|
||||||
|
m1 = 10
|
||||||
|
m2 = 1
|
||||||
|
m3 = 1
|
||||||
|
|
||||||
# initialisation mass
|
# initialisation position
|
||||||
m1 = 10
|
q1 = np.array([0, 0, 0])
|
||||||
m2 = 1
|
q2 = np.array([1, 0, 0])
|
||||||
m3 = 1
|
q3 = np.array([2, 0, 0])
|
||||||
|
|
||||||
# initialisation position
|
# initialisation velocity
|
||||||
q1 = np.array([0, 0, 0])
|
v1 = np.array([0, 0, 0])
|
||||||
q2 = np.array([1, 0, 0])
|
v2 = np.array([1, 1, 0])
|
||||||
q3 = np.array([2, 0, 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)
|
star1 = Body(m1,q1,v1)
|
||||||
star2 = Body(m2,q2,v2)
|
star2 = Body(m2,q2,v2)
|
||||||
star3 = Body(m3,q3,v3)
|
star3 = Body(m3,q3,v3)
|
||||||
|
|
||||||
Lbodylist = [star1,star2]
|
Lbodylist = [star1,star2]
|
||||||
|
|
||||||
array = np.zeros((len(Lbodylist),3))
|
array = np.zeros((len(Lbodylist),3))
|
||||||
array[0]=star3.q
|
array[0]=star3.q
|
||||||
|
|
||||||
|
|
||||||
tribody = System([star1,star2,star3])
|
tribody = System([star1,star2,star3])
|
||||||
|
|
||||||
print("list=",Lbodylist)
|
print("list=",Lbodylist)
|
||||||
|
|
||||||
print(tribody.Lval(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