Words
48
Reading
1 min
Listen
Play
7y
By the way: The following construct can be simplified to not use the slow trigonometric functions because:
cos(atan(Δy/Δx)) = cos(α), in the right triangle with the legs of Δx and Δy.
In the same triangle cos(α) = Δy/r
→cos(atan(Δy/Δx)) = Δy/r
So the following can be simplified to:
// slow form:
double accelX = -(Math.cos(Math.atan2(yDist, xDist)) * gravityConstant)/ (squaredDistanceFromPlanet);
// Simplified form:
double accelX = -(yDist * gravityConstant)/ (squaredDistanceFromPlanet*Math.sqrt(squaredDistanceFromPlanet));
RE: Planets | A Multiplayer Planet Gravity Game