Is there a source for vrrotvec algorithm: axis = cross-product, angle = acos(dot product)

Please cite a source in the Matlab help page for vrrotvec. Or is there no traceable earliest source?

 Accepted Answer

This is the public Matlab forum. We cannot modify the contents of the Matlab files. Please contact MathWorks directly using the "Contact US" button to send an enhancement request.
Applying the cross and the dot products is elementary math. I do not think that you can find a reference for this. By the way, using the dot product to determing the angle is instable. Use atan2 instead.

3 Comments

Jan,
Thanks for your response. I have submitted a service request with Mathworks as you recommended.
Unrelatedly, I do not agree that using the dot product is unstable/ambiguous in determining the angle of rotation, when it is coupled with a knowledge of the axis determined using the cross-product, as vrrotvec does. This is the basis of the widely used quaternion formulation for rotations. This formulation can be abused of course, but that is a subjective opinion. That comment in your answer is the reason I am hesitating from accepting your answer.
Yujendra.
@Yujendra Mitikiri: As long as vrrotvec uses the default value of 1e-12 to treat values as zero, 4 significant digits are lost for small angles in any way. But the ACOS approach is even worse than this limit:
You can easily try it by your own:
x = [1; 0; 0]; % A test vector
a = 1e-8; % A small angle
R = [cos(a), -sin(a),0; ... % Create 2nd test vector by rotating
sin(a), cos(a), 0; ... % around the Z axis
0, 0, 1];
y = R * x;
format long g
ac = acos(dot(x, y) / (norm(x)*norm(y)))
as = asin(norm(cross(x, y)) / (norm(x)*norm(y)))
aa = atan2(norm(cross(x, y)), dot(x, y))
You get these results:
0 % total cancellation with ACOS !!!
1e-08 % Accurate with ASIN
1e-08 % Accurate with ATAN2
Now check it with an angle near to pi/2:
a = pi/2 - 1e-8;
... % See above
1.5707963167949 % Accurate with ACOS
1.5707963267949 % Off by 1e-8: exactly pi/2 with ASIN !!!
% ^
1.5707963167949 % Accurate with ATAN2
You see, that the lack of accuracy using the ACOS or ASIN methods is not a "subjective opinion", but a well known fact. The knowledge of the axes does not matter here and even if ACOS is mathematically correct and "widely used [for] quaternion formulation for rotations", its numerical implementation is instable. 1e-8 is a huge deviation - for a small angle a relative error of 100%!
By the way, W. Kahan suggested in his paper "Mindeless.pdf":
angle = 2 * atan(norm(x*norm(y) - norm(x)*y) / norm(x * norm(y) + norm(x) * y))
The results are exactly the output of the atan2 method.
See also:
I wonder if the three first elements of vrrotvec result is supposed to be the cross product, then if we have for example two vectors [0;0;-1] and [0;0;1], their cross product should be [0;0;0], while the three first elements of vrrotvec is 0 -1.0000 0, can one help please?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!