I want to rotate a point using Quaternion function

조회 수: 6 (최근 30일)
Hassan Bosha
Hassan Bosha 2020년 4월 6일
편집: James Tursa 2020년 4월 6일
i want to rotate point (1,2,3) about x-axis by 45 using quaternion function
i tried to put it in identity matrix and rotate it but it's not working also i want to plot is q.plot()
here is the function of the matlab
P = [1 2 3];
R = transl(P)*eul2tr([0 0 0])
q = Quaternion(R)
R1 = R * trotx(45);
q1 = Quaternion(R1)
  댓글 수: 2
James Tursa
James Tursa 2020년 4월 6일
편집: James Tursa 2020년 4월 6일
I read through the link you provided, and unfortunately like 99% of all quaternion stuff I read online this one also lacks in specifying the quaternion convention used. There is no description of the Quaternion(R) algorithm used or the Quaternion.R method algorithm. Can you generate a random direction cosine matrix, perform both these operations, and post the results? Then maybe I can figure it out.
EDIT Nevermind ... I found a different link that has the direction cosine matrix to quaternion conversion code. I can figure it out from that.
James Tursa
James Tursa 2020년 4월 6일
Can you give a numeric example of the inputs and desired output? I.e., give us the starting vectors and angles, and tell us what you would expect to get as output.

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 4월 6일
편집: James Tursa 2020년 4월 6일
I took a look at this related link:
In there is the code for converting a direction cosine matrix to quaternion called tr2q.m. Based on that code I get the following comparison:
>> q = rand(1,4)*2-1 % start with a random quaternion
q =
0.6294 0.8116 -0.7460 0.8268
>> q = q/norm(q)
q =
0.4155 0.5357 -0.4925 0.5457
>> dcm = quat2dcm(q) % Aerospace Toolbox conversion to dcm
dcm =
-0.0807 -0.0741 0.9940
-0.9812 -0.1697 -0.0923
0.1755 -0.9827 -0.0590
>> tr2q(dcm) % Peter Corke published code conversion dcm to quaternion
ans =
0.4155 -0.5357 0.4925 -0.5457
>> dcm2quat(dcm) % Aerospace Toolbox conversion dcm to quaternion
ans =
0.4155 0.5357 -0.4925 0.5457
And a comparison with the Robotics Toolbox functions:
>> quat2dcm(q) % Aerospace Toolbox
ans =
-0.0807 -0.0741 0.9940
-0.9812 -0.1697 -0.0923
0.1755 -0.9827 -0.0590
>> quat2rotm(q) % Robotics Toolbox
ans =
-0.0807 -0.9812 0.1755
-0.0741 -0.1697 -0.9827
0.9940 -0.0923 -0.0590
>> dcm2quat(dcm) % Aerospace Toolbox
ans =
0.4155 0.5357 -0.4925 0.5457
>> rotm2quat(dcm) % Robotics Toolbox
ans =
0.4155 -0.5357 0.4925 -0.5457
So you can see that the quaternion conversions are conjugates of each other. So you need to be very careful how you use the Peter Corke code or the Robotics Toolbox code when comparing with or using MATLAB quaternion functions from the Aerospace Toolbox.
If I were to guess, maybe the Peter Corke and Robotics Toolbox code is intended for active vector rotations (rotating a vector within the same coordinate frame). But that is just a guess on my part since I have never used this code.
See this link for a discussion of the MATLAB toolbox quaternion conventions:

추가 답변 (2개)

Matt J
Matt J 2020년 4월 6일
  댓글 수: 4
Hassan Bosha
Hassan Bosha 2020년 4월 6일
it works just fine on 2014 but not my version 2017
q = Quaternion( rpy2tr(0.1, 0.2, 0.3) )
Matt J
Matt J 2020년 4월 6일
Well, it's 3rd party code, so you will probably have to consult with the person who wrote it.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2020년 4월 6일
You could also try this FEX submission instead of the Quaternion class
>> AxelRot([1;2;3], 45, [1 0 0], [])
ans =
1.0000
-0.7071
3.5355

카테고리

Help CenterFile Exchange에서 Coordinate Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by