# rotate a vector by orientation defined by Euler angles

8 views (last 30 days)
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.