calc the angle between two orientations?

Hi all,

I’m trying to determine the difference in angle between two orientations in Cesium, which I’m sure is just my lack of quaternion math knowledge, but this seems like a common operation which could be considered for an addition as perhaps Cesium.Quaternion.computeAngleDiff(q1,q2)?

My understanding is that the quaternion defining the difference between two unit orientation quaternions q1+q2 is:

qDiff = inverse(q1) * q2

…and that you could then get the angle between q1+q2 as the angular component of qDiff.

Testing in sandcastle:

var q1 = Cesium.Quaternion.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(0, 0, 0));
var q2 = Cesium.Quaternion.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(5, 0, 0));

var q1inv = Cesium.Quaternion.inverse(q1, new Cesium.Quaternion());

var qDiff = Cesium.Quaternion.multiply(q1inv, q2, new Cesium.Quaternion());

var diffAngle = Cesium.Quaternion.computeAngle(qDiff);
console.log("diffAngleRad: " + diffAngle);
console.log("diffAngleDeg: " + Cesium.Math.toDegrees(diffAngle));

``

I get inconsistent results when I plug different values into the heading+pitch+roll values for q2.

I’m obviously misunderstanding how that should work, so it is more a quat math question than a Cesium question, but would anyone mind setting me straight on that, and thoughts on whether Quaternion.computeAngleDiff(q1,q2) would be a useful addition?

Cheers,

AC.

Hi AC,

Following this process the get the angle, it looks like you would use unit vectors (you can use the Cesium normalize function) and the conjugate.

Thanks,

Gabby