Clear Filters
Clear Filters

Quaternions, Transformation Matrix

5 views (last 30 days)
hknatas
hknatas on 11 Nov 2018
Edited: James Tursa on 8 May 2020
Hello.
As you see in the figure, my C matrix depends on q1, q2, q3 and q4 quaternions. I caculated all the q1(i),q2(i),q3(i),q4(i) values when i = 0:1:54000. Namely for 54000 iteration, I have 54000 different q1, q2, q3, q4 values. Right now, I want to calculate C matrix for i = 0:1:54000. As a result, I need 54000 different C matrices. For i = 1, q1(1), q2(1), q3(1) and q4(1) should be used and so on i need to reach i = 54000. As i say above, i have the code to calculate all q1,q2,q3 and q4. Just i need to insert these values to matrix respectively. I guess for matrices, i can't use the same plan as I calculated quternions.
Thanks for the help already.

Accepted Answer

Bruno Luong
Bruno Luong on 11 Nov 2018
Edited: Bruno Luong on 11 Nov 2018
Such thing is straight forward in MATLAB
q1 = reshape(q1,1,1,[]);
q2 = reshape(q2,1,1,[]);
q3 = reshape(q3,1,1,[]);
q4 = reshape(q4,1,1,[]);
% The matrix is i C(:,:,i) for i=1,..., 54000
C = [q1.^2-q2.^2-q3.^2+q4.^2, 2*(q1.*q2+q3.*q4), 2*(q1.*q3-q2.*q4);
2*(q1.*q2-q3.*q4), -q1.^2+q2.^2-q3.^2+q4.^2, 2*(q2.*q3-q1.*q4);
2*(q1.*q3+q2.*q4), 2*(q2.*q3-q1.*q4), -q1.^2-q2.^2+q3.^2+q4.^2]
  6 Comments
hknatas
hknatas on 11 Nov 2018
Thanks for your effort, I guess I understood what we did finally.
James Tursa
James Tursa on 8 May 2020
Edited: James Tursa on 8 May 2020
@Bruno: Correct on that error catch. The C(2,3) term should have a + instead of a -.
Also, for the benefit of other readers, note that the quaternion to direction cosine matrix formula above (with the correction) assumes the following:
Quaternion is vector-scalar order. I.e., the vector is [q1;q2;q3] and the scalar is q4. Note that this does not match either the Aerospace Toolbox or the Robotics Toolbox, which have the scalar first and vector last.
Quaternion is either Right Chain right-handed Hamilton convention or Left Chain left-handed JPL convention. I.e., it must be one of the following:
v_body = q^-1 * v_ref * q with right-handed Hamilton convention (ij=k, jk=i, ki=j)
or
v_body = q * v_ref * q^-1 with left-handed JPL convention (ij=-k, jk=-i, ki=-j)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!