From 052870b7de94705a37e8343f1731ae80bdce4792 Mon Sep 17 00:00:00 2001 From: Crizomb <62544756+Crizomb@users.noreply.github.com> Date: Wed, 15 Feb 2023 13:40:18 +0100 Subject: [PATCH] increasing performances in newton_law d*d*d is faster than d**3 --- barnes-hut-galaxy-new.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barnes-hut-galaxy-new.py b/barnes-hut-galaxy-new.py index 939ee35..11a38a4 100644 --- a/barnes-hut-galaxy-new.py +++ b/barnes-hut-galaxy-new.py @@ -24,7 +24,8 @@ G = 10 def newton_law(mass1: float, mass2: float, vec_diff: Vec3) -> Vec3: """Return the force applied by mass1 on mass2.""" - return G * vec_diff * (mass1 * mass2 / (vec_diff.norm + SMOOTHING) ** 3) + d = vec_diff.norm + SMOOTHING + return G * vec_diff * (mass1 * mass2 / (d*d*d)) def get_time(func): def wrapper(*args, **kwargs):