How to convert euler angles to rotation matrix and back to euler angles consistently?
Mostra commenti meno recenti
I want to compare the rotations from two different sources. However, I can do it only in R3, using Euler angles. However, it seems even for an elementary conversion, we don't get matching euler vectors. I know that there can be non-unique representations for the same rotation matrix, but is there a way, where I can enforce some particular angle range output so that the vectors match? Maybe a constraint like rotation in Z has to be positive.
For eg.
%% Euler Angle -> Rotation Matrix -> Euler Angle
Rzc = -0.0030; Ryc = -2.4788; Rxc = 0.0180;
eul_seq_c_in = [Rzc, Ryc, Rxc]
rotm_c = eul2rotm(eul_seq_c_in);
eul_seq_c_out = rotm2eul(rotm_c)
%% Many to One Mapping for Euler Angle
eul2rotm(eul_seq_c_in)
eul2rotm(eul_seq_c_out)
For my application, all I get is a sequence of euler angles as an input. Then, I get a rotation transform independently, whose Euler sequence is calculated. And then I verify, if they represent the same rotation transform.
Risposta accettata
Più risposte (1)
"While I am aware of the intermediate steps, I kind of expected the inbuilt matlab functions to be consistent during the to-and-fro conversion."
I don't see how that's possible. There are an infinite number of Euler angle triplets (for a given sequence) that will yield the same rotation matrix with eul2rotm. How would rotm2eul know which one of those triplets is the "right" one. Even setting aside multiple-of-two-pi cases, there's still ambiguity unless another constraint is applied, typically that the absolute value of the middle rotation is less than or equal to pi/2, which is the affect we're seeing in the question (Ryc > pi/2). It appears that rotm2eul applies this convention (for its first output, and see below), though that's not stated in the documentation. Tthere's also ambiguity, in principal, for angles that could be either +pi or -pi.
It's probably best to construct the rotation matrix from the input sequence of Euler angles and compare to the independent rotation matrix.
BUT, I just discovered that rotm2eul provides a second output that matches what you want for this particular example
Rzc = -0.0030; Ryc = -2.4788; Rxc = 0.0180;
eul_seq_c_in = [Rzc, Ryc, Rxc]
rotm_c = eul2rotm(eul_seq_c_in);
[eul_seq_c_out,eulalt] = rotm2eul(rotm_c)
Unfortunately, the documentation of rotm2eul is silent on what exactly is the difference between its first and second outputs (or why that second output is even offered), so I can't say for sure that one of the outputs will always match your Euler angles in eul_seq_c_in, though I suspect that's the case, as long as none of abs(angle_seq_c_in) is greater than pi.
Apparently this second output was introduced in 2020a, but it's not showing in the documentation for 2021b.
2 Commenti
Manish Kumar Nayak
il 8 Ago 2024
Paul
il 8 Ago 2024
I'm pretty sure that the first output of rotm2eul uses the convention that the middle angle is constrained to have absolute value less than or equal to pi/2. And the first and third angles in the first output of rotm2eul will never have absolute value greater than pi. So those would be the constraints to enforce on the angles in eul_seq_c_in if you want to continue down the path of comparing the input Euler angles to that output of rotm2eul.
The second output of rotm2eul is documented, as shown at the link in the original answer and in this comment.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!