Correct radius dimensions
This commit is contained in:
parent
3ebf5b9baf
commit
d54c95347f
2 changed files with 5 additions and 3 deletions
|
@ -8,10 +8,12 @@ def rotations(a: np.ndarray):
|
|||
a2 = np.concatenate((a, a))
|
||||
for i in range(1, len(a)):
|
||||
yield np.split(a2, [i, i + len(a)])[1]
|
||||
# TODO: Compare performance
|
||||
# yield np.roll(a, i)
|
||||
|
||||
|
||||
def n_body(pos: np.ndarray, vel: np.ndarray, mass: np.ndarray):
|
||||
for (o_pos, o_mass) in zip(rotations(pos), rotations(mass[:, np.newaxis])):
|
||||
for (o_pos, o_mass) in zip(rotations(pos), rotations(mass)):
|
||||
dist = o_pos - pos
|
||||
vel += G * (dist / np.linalg.norm(dist, axis=1)[:, np.newaxis]) * o_mass / np.sum(dist ** 2, axis=1)[:, np.newaxis]
|
||||
pos += vel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue