MATLAB Answers

How to convert two 3D coordinates to Euler angles?

63 views (last 30 days)
Andrew Poissant
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
Andrew Poissant on 5 Mar 2018
Thank you, I have updated the question to include the error message.

Sign in to comment.

Answers (1)

Jim Riggs
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.


Show 5 older comments
Andrew Poissant
Andrew Poissant on 6 Mar 2018
Excuse my ignorance, but this is not as straightforward as using trigonometry to find the pitch angle required of the aircraft to reach vec2?
Jim Riggs
Jim Riggs on 6 Mar 2018
@Andrew: In this case, you are assuming that the aircraft is at position 1 given by vec1 and some time later it is at position 2, located by vec2. The course of the aircraft is along the vector (vec2-vec1), but this does not really specify the attitude of the aircraft. If you assume that the aircraft traveled in a straight line from (1) to (2), zero angle of attack, and zero sideslip then the aircraft attitude will align with the course line (but only if there also is no wind). You will also need to assume a bank angle in order to completely define the set of Euler angles. So you see, it takes a lot of assumptions to get from a course line to the attitude.

Sign in to comment.

Sign in to answer this question.