Sign in to follow this  
JakeM

Rotation equality

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
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.


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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this