- #1
Jozefina Gramatikova
- 64
- 9
I have a project to make the solar system. I am trying to start from somwhere. On the notes it says that we need to start by creating a System of Particles
I have to use the Euler's method.
I have my code from last week where we had to simulate a projectile with constant acceleration.
Here is my code:
Pls help!
- Two-body simulation (Circular motion)
- Implement Gravitational acceleration
Each particle (planet) could have its own field.- I.e. Each particle loops over all the other bodies to get the effect of all the other fields on it.
- Extend to three body system
I have to use the Euler's method.
I have my code from last week where we had to simulate a projectile with constant acceleration.
Here is my code:
Python:
import numpy as np
class Particle:
position = np.array([0,0,0])
velocity = np.array([0,0,0])
acceleration = np.array([0,0,0])
def __init__(self, initialPosition, initialVelocity, initialAcceleration, Name, mass):
self.position = initialPosition
self.velocity = initialVelocity
self.acceleration = initialAcceleration
self.Name = Name
self.mass = mass
def update(self, deltaT):
self.position = self.position + self.velocity*deltaT
self.velocity = self.velocity + self.acceleration*deltaT
def __repr__(self):
return 'Particle: %10s, Mass: %.5e, Position: %s, Velocity: %s, Acceleration:%s'%
(self.Name,self.mass,self.position, self.velocity,self.acceleration)