headingPitchRollQuaternion gives wrong heading

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.

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.

Thanks Bobactor

Hi Bobactor,

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

Regards,
Leighton.

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