# calc the angle between two orientations?

**URL:** <https://community.cesium.com/t/calc-the-angle-between-two-orientations/6977>\
**Category:** CesiumJS\
**Created:** [June 3, 2018, 3:21am UTC](https://community.cesium.com/t/calc-the-angle-between-two-orientations/6977 "2018-06-03T03:21:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Chapman](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/andrew_chapman/32/4219_2.png) [@Andrew\_Chapman](https://community.cesium.com/u/Andrew_Chapman)\
**Post date:** [June 3, 2018, 3:21am UTC](https://community.cesium.com/t/calc-the-angle-between-two-orientations/6977/1 "2018-06-03T03:21:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [June 6, 2018, 2:03pm UTC](https://community.cesium.com/t/calc-the-angle-between-two-orientations/6977/2 "2018-06-06T14:03:34Z")

</div>

Hi AC,

Following[this process](https://math.stackexchange.com/questions/167827/compute-angle-between-quaternions-in-matlab) the get the angle, it looks like you would use unit vectors (you can use the Cesium **normalize** function) and the **conjugate**.

Thanks,

Gabby
