How to calculate the Euler angles between X, Y and Z axes (in Deg) between two 3D points

33 次查看(过去 30 天)
Hi,
I have two 3D points, Tx (Tx,Ty,Tz) and Rx (Rx,Ry,Rz). I want to calculate the rotation angles in terms of yaw, roll and pitch. How can I do this in matlab? Do we have any direct function that does it, otherwise how to program for the same?
TIA

回答(1 个)

Aditya Singh
Aditya Singh 2023-7-5
Hi Rizwana,
To my understanding, you have two points and want to calculate the Euler angles between them.
You need to do is first convert these cartesian vectors to rotation matrix and then to Euler system. Below is the brief code for the reference
% Lets take first 2 points and find Spherical coordinates.
P1 = [-426159, 501913, 845131];
P2 = [-48717.2, 499318, 847679];
v = P1-P2;
% Let's define si and theta in such a way that.
v = [r*cos(si)*cos(theta), r*sin(theta), r*sin(si)*cos(theta)]
r = norm(v);
si = atan2(v(3),v(1));
theta = atan2(v(2),sqrt(v(1).^2+v(3).^2));
j = [cos(si)*cos(theta), sin(theta), sin(si)*cos(theta)];
% Correspond to j vector you can also find orthonormal vector to j
i = [sin(si), 0, -cos(si)];
k = [cos(si)*sin(theta), -cos(theta), sin(si)*sin(theta)];
% Rotation matrix;
m = [i',j',k'];
% You can use MATLAB inbuilt function to convert rotation matrix to Euler system
eul = rotm2eul(m);
For more information you can refer to the MATALB question Euler angle from 3d points? - MATLAB Answers - MATLAB Central (mathworks.com).
Hope it helps.
  1 个评论
Rizwana Ahmad
Rizwana Ahmad 2023-7-5
Hi Aditya,
Thank you for your response. I am bit confused about step 4,5 and 6 as they seem inter depdndent. we cant calculate 4th without knowing 5th and 6th, pls correct me if I am wrong.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by