35 lines
779 B
Python
35 lines
779 B
Python
from enum import Enum
|
|
import numpy as np
|
|
|
|
from ..units import Position, Velocity, Mass, Acceleration
|
|
|
|
class Body:
|
|
"""
|
|
Base class for any orbital body
|
|
"""
|
|
def __init__(self, X: Position, V: Velocity, m: Mass, name: str = ""):
|
|
"""
|
|
x (position) and v (velocity)
|
|
"""
|
|
self.X = X
|
|
self.V = V
|
|
self.A = Acceleration([0,0,0])
|
|
self.m = m
|
|
self.name = name
|
|
|
|
def save(self):
|
|
return (self.X, self.V, self.m)
|
|
|
|
@classmethod
|
|
def load(cls, tup):
|
|
return cls(tup[0], tup[1], tup[2])
|
|
|
|
def step(self, step_size: float):
|
|
self.X = step_size*self.V
|
|
self.V = step_size*self.A
|
|
|
|
def __str__(self):
|
|
return str(f"{self.name}: X = {self.X}, V = {self.V}")
|
|
|
|
|