# headingPitchRollQuaternion gives wrong heading

**URL:** <https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529>\
**Category:** CesiumJS\
**Created:** [May 20, 2015, 11:36pm UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529 "2015-05-20T23:36:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leighton.carr](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@leighton.carr](https://community.cesium.com/u/leighton.carr)\
**Post date:** [May 20, 2015, 11:36pm UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529/1 "2015-05-20T23:36:00Z")

</div>

Hi all,

New to cesium here so sorry if this is a dumb question. I'm trying to convert lat, lon, alt, heading, pitch, roll into a quaternion for orientation of a flight, and for some reason the heading is around 80 degrees out of whack.

Here's the relevant code:

var curloc = Cesium.Cartesian3.fromDegrees(curlon, curlat, (curalt \* 0.3048), Cesium.Ellipsoid.WGS84);

var quat = Cesium.Transforms.headingPitchRollQuaternion(curloc, curhead, curpitch, curroll, Cesium.Ellipsoid.WGS84);

path[1].orientation.unitQuaternion.push(time, quat.x, quat.y, quat.z, quat.w);

Do I need to alter the reference frame or something - I thought the current location would do that?

Cheers,  
Leighton.

---

<div class="post-metadata">

**Author:** ![abdou](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/abdou/32/2012_2.png) [@abdou](https://community.cesium.com/u/abdou)\
**Post date:** [May 21, 2015, 8:34am UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529/2 "2015-05-21T08:34:36Z")

</div>

Hello,  
you should test this code:

var curloc = Cesium.Cartesian3.fromDegrees(curlon, curlat, (curalt \* 0.3048), Cesium.Ellipsoid.WGS84);

var quat = Cesium.Transforms.headingPitchRollQuaternion(curloc, -curhead-Math.PI/2, curpitch, curroll, Cesium.Ellipsoid.WGS84);

path[1].orientation.unitQuaternion.push(time, quat.x, quat.y, quat.z, quat.w);

Indeed, for an entity, the frame used to apply a rotation is EastNorthUp frame which is local to the position. So the abscissa axis is West-\> East and the ordered axis is South-\>North. As a trigonometric an angle is defined from abscissa axis (here West-\>West), you must remove 90 degrees or PI/2 radians to convert from a flight angle.  
Finally the direction of trigonometric angle and flight angle are opposites.

---

<div class="post-metadata">

**Author:** ![Michael\_Lodge-Paoli1](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Michael\_Lodge-Paoli1](https://community.cesium.com/u/Michael_Lodge-Paoli1)\
**Post date:** [May 22, 2015, 2:52pm UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529/3 "2015-05-22T14:52:00Z")

</div>

Thanks Bobactor

---

<div class="post-metadata">

**Author:** ![leighton.carr](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@leighton.carr](https://community.cesium.com/u/leighton.carr)\
**Post date:** [May 25, 2015, 1:42am UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529/4 "2015-05-25T01:42:14Z")

</div>

Hi Bobactor,

Thanks for the reply! The other 9 degrees was of course me using magnetic heading instead of true heading.

Regards,  
Leighton.

---

<div class="post-metadata">

**Author:** ![Michael\_Lodge-Paoli1](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Michael\_Lodge-Paoli1](https://community.cesium.com/u/Michael_Lodge-Paoli1)\
**Post date:** [May 26, 2015, 3:12am UTC](https://community.cesium.com/t/headingpitchrollquaternion-gives-wrong-heading/2529/5 "2015-05-26T03:12:10Z")

</div>

Got to love that moment when you realize you’re using the wrong units, coordinate systems or conversion values… We’ve all been there!
