7 views (last 30 days)

Show older comments

(For a little bit of context, I'm working with an attitude-determination algorithm called TRIAD and the software called STK, and I'm trying to make their results consistent.)

Let's say I have this rotation matrix:

BN = [0.7505 0.1707 -0.6384

0.1574 0.8921 0.4236

0.6418 -0.4184 0.6427];

(It could be verified that it has a determinant of 1.)

If I convert it to quaternions with the first component being the scalar,

quat = rotm2quat(BN)

the result is [0.9063 0.2323 0.3532 0.0037].

However, my desired representation (from the STK output) is [-0.9063 -0.2323 -0.3532 -0.0037].

It could be verified that these two representations yield the same Euler angles using the "quat2eul" function.

What can I do to achieve the desired quaternion representation? The issue isn't as simple as adding a negative sign, because for the rotation matrix,

rotm = [0.8138 0.4698 -0.3420

-0.4410 0.8826 0.1632

0.3785 0.0180 0.9254];

the converted quaternion representation is exactly the same as the desired quaternion representation.

Thanks so much in advance!

Here's a potentially useful reference from STK:

James Tursa
on 28 Jun 2021

As you already know, both q and -q represent the same rotation. Which sign to pick is entirely up to the underlying algorithm. So the only way to match STK exactly in all cases is to know exactly how STK picks these signs in all cases. Unless you have access to their underlying algorithms, how do you expect to do this? Has STK published this algorithm for you to use? Short of that, you would probably have to run a bunch of constructed test cases to try and figure it out. What is the reason you must match STK?

The sign choice can affect downstream calculations, so it is important to be consistent. E.g., if this is being passed off to a control system you might want to ensure the quaternion scalar element is non-negative so that the physical rotation the control system commands is the "short" way in instead of the "long" way. Or if you are generating a sequence of quaternions from a sequence of rotation matrices the choice may be to ensure that the largest magnitude quaternion element does not change sign from one q to the next q. Etc.

Bottom line is you will need to figure out what type of consistency makes sense for your application and work with that.

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

Start Hunting!