Quaternions, Transformation Matrix

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.

 採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 11 日
編集済み: Bruno Luong 2018 年 11 月 11 日

0 投票

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 件のコメント

Bruno Luong
Bruno Luong 2018 年 11 月 11 日
I suspect there is an error
in
C(2,3) = 2*(q2.*q3-q1.*q4)
By symmetry it should be
2*(q2.*q3+q1.*q4)
hknatas
hknatas 2018 年 11 月 11 日
編集済み: hknatas 2018 年 11 月 11 日
Thanks for the code. It is working and calculating something. But i don't get the idea. So can you explain to me what we did in here? This is my first time seeing reshape command. Also in C matrix there are points (.) after some notations (i.e q1.) what does that mean? Actually I couldn't figure out what kind a loop we used here. I would love to learn what's going on here if you want to explain. In addition, how can i see C matrix for any specific "i" value in command window? For example I want to see C matrix for i = 4567.
Bruno Luong
Bruno Luong 2018 年 11 月 11 日
編集済み: Bruno Luong 2018 年 11 月 11 日
If you want to learn the best place is reading MATLAB doc. The point in front of operator indicated they are "pointwise" operators:
help mdivide
help ldivide
help rdivide
help power
The RESHAPE is something essential when working with MATLAB
help reshape
Bruno Luong
Bruno Luong 2018 年 11 月 11 日
how can i see C matrix for any specific "i" value in command window? For example I want to see C matrix for i = 4567.
C(:,:,4567)
hknatas
hknatas 2018 年 11 月 11 日
Thanks for your effort, I guess I understood what we did finally.
James Tursa
James Tursa 2020 年 5 月 8 日
編集済み: James Tursa 2020 年 5 月 8 日
@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)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2018 年 11 月 11 日

編集済み:

2020 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by