Relative motion between Quaternions
8 views (last 30 days)
Show older comments
I'm working on Quaternions. I wanna find out the relative motion between quaternions in MATLAB.
For example, I've
QuatA = [1283842729 -831786718 1290396116 1271562329] and
QuatB = [1313190417 1274713520 -845615766 1306114950]
How can I find how much QuatB is rotated with respect to QuatA?
Any help is appreciated.
Thanks.
5 Comments
Answers (2)
James Tursa
on 24 Sep 2015
Edited: James Tursa
on 24 Sep 2015
In general, for unit quaternions you would multiply the conjugate of one times the other, and then extract the angle and rotation axis from that. Be sure to do a quaternion multiply, not a regular multiply. Also be sure the quaternion multiply routine you are using assumes the scalar is in the same spot (1st or 4th) as the quaternions you have. You would have to divide your quaternions above by their respective norms to apply this technique, but not knowing what these quaternions represent I can't advise if this is the correct procedure or not.
8 Comments
Aitor Burdaspar
on 17 Dec 2019
Hello Manikya,
I have exactly the same problem as yours. Did you finally solve it?
Best regards,
James Tursa
on 17 Dec 2019
Edited: James Tursa
on 17 Dec 2019
There is a fundamental misunderstanding of how to work with quaternions and Euler Angle sequences. In the first place, Euler Angle sequences do not behave linearly. That is, if you have a (yaw1,pitch1,roll1) sequence followed by a (yaw2,pitch2,roll2) sequence, you should not be expecting the result to be the same as a (yaw1+yaw2,pitch1+pitch2,roll1+roll2) sequence. Sequential rotations simply do not behave that way. So the subtractions you are doing (30-10, 40-10, 50-10) to get your "expected" result is simply not true with regards to sequential rotations.
In particular, I will use a couple of example coordinate frames to illustrate the issue.
Suppose q1 and q2 are both ECI_to_BODY quaternions. I.e.,
q1 = ECI_to_BODY1 (BODY1 being the BODY frame orientation for q1)
q2 = ECI_to_BODY2 (BODY2 being the BODY frame orientation for q2)
Then
q3 = conj(ECI_to_BODY2) * ECI_to_BODY1
= BODY2_to_ECI * ECI_to_BODY1
= BODY2_to_BODY1
So q3 represents a rotation between the two end BODY frames for the quaternions. Note that q3 is not another ECI_to_BODY quaternion. Since it is not another ECI_to_BODY quaternion, you should not expect the angles associated with it to be the same as what you get from a straight subtraction of your q1 and q2 angles.
Side note: The default order for the angles is y,p,r and not r,p,y.
Mo
on 3 Jun 2018
How is this method used for a matrix? It seems "norm(A)" for a quaternion matrix is different. I appreciate any help.
1 Comment
Luca Pozzi
on 11 Jun 2018
If A is an nx4 matrix (a 'column' of quaternions) the following code should work:
for i=1:size(A,1) % for each row of A
Anorm(i,:)=norm(A(i,:)); % dividing a row by its norm
end
norm(A) returns the norm of the whole matrix A, the for cycle here above allows you to normalize every single row of the matrix (i.e. every quaternion) instead. Hope this helps!
See Also
Categories
Find more on Coordinate Transformations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!