Error in calculating the angle of a line
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)
{
dou开发者_如何学JAVAble a_x = endPosition.getLatitude() - startPosition.getLatitude();
double a_y = endPosition.getLongitude() - startPosition.getLongitude();
return Math.atan2(a_y, a_x);
}
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.
精彩评论