1
0

add print method to Body object

This commit is contained in:
Thibault Barnouin
2021-10-22 11:25:14 +02:00
parent b452bee164
commit f10f23bdbc
2 changed files with 32 additions and 29 deletions

59
lib/class.py Normal file → Executable file
View 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,37 +54,35 @@ class System:
return L
#def initialize(self):
if __name__ == "__main__":
# initialisation mass
m1 = 10
m2 = 1
m3 = 1
# 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 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
View File