increasing performances

in newton_law d*d*d is faster than d**3
This commit is contained in:
Crizomb 2023-02-15 13:40:18 +01:00 committed by GitHub
parent 8b2b2a9c34
commit 052870b7de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):