dcm2quat is returning invalid quaternions
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Noah Gordon
el 31 de Mayo de 2018
Editada: James Tursa
el 17 de Jul. de 2023
I am using dcm2quat to convert multiple direction cosine matrices to quaternions. For several, it is working fine, but for others I am getting results that violate the fundamental constraint on quaternions--that q1²+q2²+q3²+q4²=1.
Here is one example of a DCM I'm having trouble with:
>> ACB
ACB =
0.4970 0.8638 -0.0824
0.8677 -0.4951 0.0435
0.0032 0.0932 0.9956
>> q = dcm2quat(ACB)
q =
0.7067 -0.0176 0.0303 -0.0014
>> q(1)^2+q(2)^2+q(3)^2+q(4)^2
ans =
0.5006
This is a valid DCM. Its transpose is equal to its inverse, multiplying it by its transpose yields the identity matrix, and the sum of the squares of each row and column is 1. Why is MATLAB returning invalid quaternions?
Edit: Also tried running quat2dcm on the result from dcm2quat and got a different DCM than I started with. Something's very wrong.
0 comentarios
Respuesta aceptada
James Tursa
el 31 de Mayo de 2018
Editada: James Tursa
el 31 de Mayo de 2018
ACB is not a valid direction cosine matrix. You can see that its determinant is not close to 1:
>> ACB = [ 0.4970 0.8638 -0.0824
0.8677 -0.4951 0.0435
0.0032 0.0932 0.9956]
ACB =
0.4970 0.8638 -0.0824
0.8677 -0.4951 0.0435
0.0032 0.0932 0.9956
>> det(ACB)
ans =
-0.9999
Hence the problems occur when feeding this matrix into the dcm2quat function. So whatever process you are using to construct this dcm is flawed.
3 comentarios
Ivan Lisun
el 16 de Jul. de 2023
The dcm2quat function incorrectly takes the sign of cos and sin into account when calculating quaternion's parts. Simple code based on rotm2axang works fine. The code is redundant to make it clear what's going on
r2a = rotm2axang(DCM);
rot_axes = r2a(:,1:3);
q_a = cos(r2a(4)/2);
q_sin = sin(r2a(4)/2);
q_bcd=q_sin*rot_axes;
q = quaternion (q_a,q_bcd(1),q_bcd(2),q_bcd(3))
James Tursa
el 17 de Jul. de 2023
Editada: James Tursa
el 17 de Jul. de 2023
How can this possibly "work fine" on an invalid DCM matrix? If this code always produces a normalized quaternion result regardless of how bad the input might be, I don't see that necessarily as an advantage. E.g.,
DCM = rand(3); % arbitrary matrix not even close to valid rotation matrix
det(DCM)
r2a = rotm2axang(DCM);
rot_axes = r2a(:,1:3);
q_a = cos(r2a(4)/2);
q_sin = sin(r2a(4)/2);
q_bcd=q_sin*rot_axes;
q = quaternion (q_a,q_bcd(1),q_bcd(2),q_bcd(3))
norm(q)
Examining q, the user has no clue this is a garbage result.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!