Why does quatrotate() produce negative rotations?

Code
% YPR angles to rotate
yaw = pi/4;
pitch = 0;
roll = 0;
% Point to rotate
A = [ 1 0 0]
% Rotate (Negative)
Q = angle2quat(yaw, pitch, roll);
B = quatrotate(Q, A)
% Rotate (Expected result)
Q = angle2quat(-yaw, -pitch, -roll);
C = quatrotate(Q, A)
Results:
A =
1 0 0
B =
0.7071 -0.7071 0
C =
0.7071 0.7071 0

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 19 Sep. 2014

2 Stimmen

Hello Dereck, there is a difference between a) rotating a reference frame (e.g. relative to a "fixed" vector) and b) rotating a vector relative to a reference frame. Check out this answer for reference.
angle2quat converts rotation angles [to quaternions]. Rotation angles in turn are used to rotate reference frames a), not vectors b). To illustrate, if you do not convert to quaternions but keep working with rotation angles and matrices you could do the same by computing the direction cosine matrix, DCM:
DCM = angle2dcm(yaw,pitch,roll)
DCM =
0.707106781186548 0.707106781186547 0
-0.707106781186547 0.707106781186548 0
0 0 1.000000000000000
rotate_Frame = DCM*A'
ans =
0.707106781186548
-0.707106781186547
0
which, as pointed out above, rotates the reference frame relative to the vector.
If you need to rotate the vector instead, use rotx and equivalent:
rotate_Vector = rotz(yaw*180/pi)*roty(pitch*180/pi)*rotx(roll*180/pi)*A'
ans =
0.707106781186547
0.707106781186547
0

3 Kommentare

Dereck
Dereck am 19 Sep. 2014
That makes sense now, especially considering the fact this function was written for aerospace applications where as the body of the aircraft rotates, you are really changing the coordinate frame of the aircraft and want all of your external targets to stay in the same location in the world frame so to speak....
Would you mind pointing me to relevant MATLAB documentation that states this behavior/definition for my better understanding? It would be much appreciated.
Also, What would be the best way of rotating a large set of vectors by a set of quaternions? Should I develop my own rotation function? I am currently using quaternions because I need to perform many linear interpolations between rotations.
Thanks again.
You could rotate your vectors by the inverse quaternion:
c = quatrotate(quatinv(Q), A)
See also this post. The quatrotate function should probably use the phrase "coordinate system transformation" instead of the phrase "rotated vector".

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by