MATLAB Answers

rotate a vector by orientation defined by Euler angles

8 views (last 30 days)
Manikanta Kotaru
Manikanta Kotaru on 15 Jul 2016
Edited: James Tursa on 8 May 2020
I want to rotate a vector according to given Euler angles - yaw, pitch and roll. Here is the code I tried:
yawPlane = 30; pitchPlane = 0; rollPlane = 0;
quatPlane = eul2quat([yawPlane*pi/180, pitchPlane*pi/180, rollPlane*pi/180]);
rotPoint2 = quatrotate(quatPlane, [cosd(120) sind(120) 0])
sprintf('Expected rotPoint2 is [cosd(120+yawPlane) sind(120+yawPlane) 0] = [%f %f %f]', [cosd(120+yawPlane) sind(120+yawPlane) 0])
sprintf('Code returns rotPoint2 as [cosd(120-yawPlane) sind(120-yawPlane) 0] = [%f %f %f]', rotPoint2)
OUTPUT:
Expected rotPoint2 is [cosd(120+yawPlane) sind(120+yawPlane) 0] = [-0.866025 0.500000 0.000000]
Code returns rotPoint2 as [cosd(120-yawPlane) sind(120-yawPlane) 0] = [0.000000 1.000000 0.000000]
It seems like the code is rotating the vector clockwise by 30 degrees whereas I want to rotate it anti-clockwise by 30 degrees. Please help by explaining why the the code is rotating in clockwise direction.

  0 Comments

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 8 May 2020
Edited: James Tursa on 8 May 2020
MATLAB uses two different quaternion conventions in their toolboxes. The Aerospace Toolbox quaternion convention is essentially the conjugate of the Robotics Toolbox convention. If you try mixing and matching functions from these two toolboxes you can easily end up with the opposite answer you were expecting. For more discussion on this see these links:
In your case, the eul2quat( ) function comes from the Robotics Toolbox, and the quatrotate( ) function comes from the Aerospace Toolbox. So you are using functions with two different convention assumptions, hence the inconsistency in the results.

  0 Comments

Sign in to comment.


Translated by