# Rotation equality

This topic is 4265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there any good way to test the equality between two 3D rotations, other than just comparing floats per component? I want to know if two 3D rotations are equal or nearly equal.

##### Share on other sites
For rotation matrices R1 and R2 you can simply calculate R1-1R2 and convert the result to axis/angle form, then see if the angle is below a certain threshold. There are various simplifications you can do, such that the math is really very simple.

##### Share on other sites
If the rotations are represented by quaternions, you can check how close the dot product is to 1 or -1.

##### Share on other sites
Thanks all! Dot product of quaternions seems like a faster method though.

##### Share on other sites
Quote:
 Original post by SneftelFor rotation matrices R1 and R2 you can simply calculate R1-1R2 and convert the result to axis/angle form, then see if the angle is below a certain threshold. There are various simplifications you can do, such that the math is really very simple.

Perhaps the factorization to axis/angle is overkill? R1 is a rotation, so Inverse(R1) = Transpose(R1). If R1 and R2 are the same, then Transpose(R1)*R2 = I, where I is the identity matrix. This suggests testing for closeness to the zero matrix of M = Transpose(R1)*R2 - I = [m[r][c]]. One such test is to compute the maximum of the 9 entries |m[r][c]| and see how small it is. If you have decided that a maximum larger than a specified epsilon, e, rules out (numerical) equality, you need only multiply rows of Transpose(R1) and columns of R2 until you reach an entry that is larger in magnitude than e. That is, you do not have to perform the entire matrix multiplication first and iterate over entries second. Bail out once an entry is too large.

The quaternion approach is appealing, but if you are storing your rotations as matrices, then you have to convert first to quaternions to compute the dot product.

##### Share on other sites
Dave's method can be improved a little bit if we recall that for any given rotation matrix, the following holds:

(*) trace(R) = 1+2cos(a),

where a is the angle of rotation.

And so, given our two matrices, R1 and R2, define:
R = transpose(R1)*R2.

The two matrices are close enough iff |3 - trace(R)| < 2eps.
Note, that you only need the diagonal entries of R to find the trace.

By the way, (*) can be proven by using Rodrigue's formula.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013154
×