Lets say I'm using atan2
to get the angle between two vectors.
atan2
gives a value in radians. I convert it to degrees using a built in function in Java. This gives me a value between 0
and 180
degrees or between 0
and -180
(the nature of atan2).
Is there a way to convert the value received with this function (after it's been converted to degrees), to the standard 360-degree-system, without changing the angle - only the way it's written? It would make it easier for me to work with.
Thanks
atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.
Arc tangent of two numbers, or four-quadrant inverse tangent. ATAN2(y,x) returns the arc tangent of the two numbers x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result. The result is an angle expressed in radians.
The atan2() function returns a value in the range -π to π radians. If both arguments of the atan2() function are zero, the function sets errno to EDOM, and returns a value of 0.
The quantity atan2(y,x) is the angle measure between the x-axis and a ray from the origin to a point (x, y) anywhere in the Cartesian plane. The signs of x and y are used to determine the quadrant of the result and select the correct branch of the multivalued function Arctan(y/x).
Try this:
double theta = Math.toDegrees(atan2(y, x));
if (theta < 0.0) {
theta += 360.0;
}
To convert it to a North referenced 0 - 360 degree value:
double degrees = 90.0d - Math.toDegrees( Math.atan2( y, x ) );
if( degrees < 0.0d )
{
degrees += 360.0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With