iphone - Is there a fast way to calculate the smallest delta between two rotation values? -
There are two views:
viewA
and viewB
. Both are hanging
The coordinate system for rotation is weird: it goes from 0 to 17, 99 99 99 or -179 99 99 degrees. Therefore, essentially 17 9, 99 99 and -179 99 99 are very close!
I want to calculate how many degrees or radians between these rotations.
For example:
The scene is rotated at 20 degrees
the visible B is rotated at 30 degrees
I just do it Could: rotationB - rotationA = 10
But the problem with this formula:
The scene rotates at 17 17 degrees on viewB -179 degrees
This would be wrong: Rotation B - Rotation A = -179 - 179 = -358
358 Simple is wrong, because they are very close in reality, one thing I can do is to check whether the correct result value is greater than 180 , And if so, then calculate it in another way to get it less true delta. But I think this possible temporary point due to errors and ineffective, this is wrong and wrong. So if two scenes essentially revolve around 17 9, 99 99 99 99 99 99 degrees, then if I'm lucky, I can be 180 or strange weird.
Perhaps a talented style to solve this problem with mathematics, PI, sign or other useful stuff?
Edit: The original answer (with Mod) was incorrect. In some circumstances, 180 - the correct answer would be (For example, 30 and -20 for example 130 would have to answer, not the correct answer of 50):
Two correct answers for all scenarios:
If A1
and A2
are two angles (between -179.999 99 and 179.999 99, and Abs
) are full Value, angular distance between them, expressed by:
= angle between 180 - abdomen (ABS (A1 - A2) - 180)
Or, the use of the C-style Terrorist operator Taxes:
Angle = A1 and LT; 180 + A2? A1 - A2: 360 + A1 - A2
Comments
Post a Comment