Created
September 28, 2019 19:22
-
-
Save WhiteBlackGoose/5e6aa75764bfaebb744373fdf6090231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InteractionField: | |
def __init__(self, F): | |
self.points = [] | |
self.F = F | |
def move_all(self, dt): | |
for p in self.points: | |
p.move(dt) | |
def intensity(self, coord): | |
proj = Vector(*[0 for i in range(coord.dim())]) | |
single_point = Point(Vector(), mass=1.0, q=1.0) | |
for p in self.points: | |
if coord % p.coords < 10 ** (-10): | |
continue | |
d = p.coords % coord | |
fmod = self.F(single_point, p, d) * (-1) | |
proj = proj + (coord - p.coords) / d * fmod | |
return proj | |
def step(self, dt): | |
self.clean_acc() | |
for p in self.points: | |
p.accinc(self.intensity(p.coords) * p.q) | |
p.accelerate(dt) | |
p.move(dt) | |
def clean_acc(self): | |
for p in self.points: | |
p.clean_acc() | |
def append(self, *args, **kwargs): | |
self.points.append(Point(*args, **kwargs)) | |
def gather_coords(self): | |
return [p.coords for p in self.points] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment