add print method to Body object
This commit is contained in:
17
lib/class.py
Normal file → Executable file
17
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
|
||||
"""
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Body:
|
||||
|
||||
|
||||
|
||||
def __init__(self, mass, position, velocity):
|
||||
self.m = mass
|
||||
self.q = position
|
||||
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,8 +54,7 @@ class System:
|
||||
return L
|
||||
|
||||
|
||||
#def initialize(self):
|
||||
|
||||
if __name__ == "__main__":
|
||||
# initialisation mass
|
||||
m1 = 10
|
||||
m2 = 1
|
||||
@@ -82,4 +86,3 @@ tribody = System([star1,star2,star3])
|
||||
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