0

I tried to calculate the angle between my start position and end position, but it keeps a number between 2 and -2. I got this code from stack overflow (http://stackoverflow.com/questions/2676719/calculating-the-angle-between-the-line-defined-by-two-points) and intergrated it in my GridClass. Does anyone know what's wrong with this code?

public static double getAngle(GeoPosition startPosition, GeoPosition endPosition)
{

double a_x = endPosition.getLatitude() - startPosition.getLatitude();
double a_y = endPosition.getLongitude() - startPosition.getLongitude();

return Math.atan2(a_y, a_x);
}
Rob
  • 1

1 Answers1

0

but it keeps a number between 2 and -2

The trigonometry methods in Java use radians. If you need degrees (0-360) use Math.toDegrees:

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

aioobe
  • 413,195
  • 112
  • 811
  • 826