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

33 Ansichten (letzte 30 Tage)
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

Antworten (1)

Aditya Singh
Aditya Singh am 5 Jul. 2023
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 Kommentar
Rizwana Ahmad
Rizwana Ahmad am 5 Jul. 2023
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by