How to compare two rotations?

I’m working on an AR app and I want to compare the rotations of two image markers, which are successfully being rendering into world space and I have their transforms. The two rotations are expected to be very similar on two axis and only majorly differ on a third axis.

What I’ve tired so far:

Using Quaternion.Angle

private float compare(Quaternion quatA, Quaternion quatB)
{
    return Quaternion.Angle(quatA, quatB)
}

This nearly gives me exactly what I want, the angle matches my expectations except it never gives me negative angles so I can’t tell the difference between 90 degrees and -90 degrees (as an example)

private float compare(Quaternion quatA, Quaternion quatB)
{
    return (quatA * quatB).eulerAngles.y;
}

This seems like it might work, but I’m not sure that the y-axis will always be the axis that I want. Also I’m not sure how to know if I should be doing quatB * quatA (since that operation is non-commutative for quaternions). Does anyone have any guidance? I’ve tried to search for this but wasn’t able to find any threads that seemed to quite match what I’m trying to do.

I think perhaps you want this:

But you need the third vector that is the axis around which you consider the rotation to be plus or minus. This might be the gaze vector from your player to the objects, or it might be the normal to whatever these objects are sitting on.

2 Likes

Thanks Kurt

Dot product might help here. The dot product of two unit vectors is basically the cosine of the angle separating them, so it will be 1 if they’re right on top of each other, 0 if they’re 90 degrees apart, and -1 if they’re 180 degrees apart (facing away from each other). It’s also extremely cheap to compute. Take a look at this applet to get a feel for it: Dot Product

1 Like

Hi,
Please don’t necro post .
If you want to show appreciation use the Like button.
Thread locked.

1 Like