RE: RE: Planets | A Multiplayer Planet Gravity Game
You are viewing a single comment's thread from:

RE: Planets | A Multiplayer Planet Gravity Game

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));
@quantumdeveloper: By the way: The | Ecency