Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.