63 views (last 30 days)

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);

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.

Jim Riggs
on 6 Mar 2018

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/386321-how-to-convert-two-3d-coordinates-to-euler-angles#comment_542123

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/386321-how-to-convert-two-3d-coordinates-to-euler-angles#comment_542123

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/386321-how-to-convert-two-3d-coordinates-to-euler-angles#comment_542132

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/386321-how-to-convert-two-3d-coordinates-to-euler-angles#comment_542132

Sign in to comment.