Atan2(y,x) will return a float between -pi and pi. I want to calculate the distance between two angles, but the non-continuity is throwing me off.
See this for better understanding.
I want to be able to calculate the distance between Angle 1 and Angle 2.
The whole point of this is to be able to create a cone from the center to a specified angle. Essentially I will be evaluating:
if(DistanceFromAngle1 < pi/4 [45°])
{
Angle2 is part of cone
}
If by distance you mean the straight line joining the two interception points, you can calculate the distance by doing this:
SQRT( ( ABS|cos(A) - cos(B)| )^2 + ( ABS|sin(A) - sin(B)| )^2 )
SQRT = square root
ABS = Absolute value
If the distance is the angle, you calculate it by doing (pseudo-code)
var angle = ABS(A - B)
if(angle > pi) angle = 2*pi - angle
return angle
dAngle1 = //convert angle1 to degrees
dAngle2 = // convert to degrees
delta = Math.Max(dAngle1, dAngle2) - Math.Min(dAngle1, dAngle2)
if (180 < delta) {
delta = 360 - delta;
}
// convert delta to radians if you want
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