# How to convert two 3D coordinates to Euler angles?

63 views (last 30 days)
Andrew Poissant on 4 Mar 2018
Edited: Jim Riggs on 6 Mar 2018
I have two vectors representing (lat, long, alt). I need to calculate the Euler angles (roll, pitch, yaw) required to go from vec1 to vec2. I tried making a rotations matrix and then use rotm2eul() function but I keep getting an error, seen below? The rotation matrix is not of the same format that rot2eul() expects but I am unsure how to fix it. Also, my altitude is in meters, and lat long is in degree so would I need to convert to a common unit?
Error message: Error using rotm2eul Expected R to be of size 3x3xM, but it is of size 1x4.
Error in robotics.internal.validation.validateRotationMatrix (line 21) validateattributes(R, {'single','double'}, {'nonempty', ...
Error in rotm2eul (line 33) robotics.internal.validation.validateRotationMatrix(R, 'rotm2eul', 'R');
Error in S1_NoAcc_3_glide3 (line 346) eul = rotm2eul(rotm);
x_earth = 76.9470;
y_earth = 38.9948;
xnew = 76.9492;
ynew = 38.9935;
hi = 150; % m
hf = 0;
vec1 = [x_earth, y_earth, hi];
vec2 = [xnew, ynew, hf];
rotm = vrrotvec(vec1, vec2); % generate rotation matrix
eul = rotm2eul(rotm);

Jan on 5 Mar 2018
Please post the complete error message, such that we do not have to guess, which error occurs where. Thanks.
There is no "common unit" for meters and degrees. You need a reference system to determine the rotation matrix and in your case there is a translation also.
Andrew Poissant on 5 Mar 2018
Thank you, I have updated the question to include the error message.

Jim Riggs on 5 Mar 2018
Edited: Jim Riggs on 5 Mar 2018
According to the documentation for function vrrotvec, the output of this function is a rotation vector, not a rotation matrix. vrrotvec provides a 4-element row vector output; the first three elements are the rotation vector axis, and the fourth element is the rotation angle.
Function rotm2eul is expecting a 3x3 rotation matrix (i.e. a direction cosine matrix) as the input argument.