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
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!