Heading/Pitch/Roll to Quaternions... ... and back

Here’s yet another from me!

This relates to an aircraft - I use local heading, pitch and roll and convert it into a quaternion using the transform ‘headingPitchRollQuaternion’. The attitude of the aircraft is spot-on.

center = Cesium.Cartesian3.fromDegrees(-0.2080299, 51.1473961, 210.00);
hdg.addSample(Cesium.JulianDate.fromIso8601(‘2012-08-04T13:16:07Z’), Cesium.Transforms.headingPitchRollQuaternion(center, Cesium.HeadingPitchRoll.fromDegrees(166.2, -0.9, 0.2)));

``

A a later point I then use the transform ‘Cesium.HeadingPitchRoll.fromQuaternion’ to extract the headingPitchRoll from the quaternion and finally the toString() method to put heading, pitch and roll into a string.

The values in the string appear to be earth-oriented (e.g., affected by the lat/lon) rather than the local heading, pitch and roll. When the nose of the aircraft is [locally] vertical, the pitch is 0.89 radians or 51.1° : the same as the latitude.

I’m obviously missing a transform but can’t find one that is the direct inverse of ‘Cesium.Transforms.headingPitchRollQuaternion’?

Quaternions make my head hurt!

Thanks,

Hugh

Here's yet another from me!

This relates to an aircraft - I use local heading, pitch and roll and
convert it into a quaternion using the transform
'headingPitchRollQuaternion'. The attitude of the aircraft is spot-on.

center = Cesium.Cartesian3.fromDegrees(-0.2080299, 51.1473961, 210.00);
hdg.addSample(Cesium.JulianDate.fromIso8601('2012-08-04T13:16:07Z'),
Cesium.Transforms.headingPitchRollQuaternion(center, Cesium.
HeadingPitchRoll.fromDegrees(166.2, -0.9, 0.2)));

A a later point I then use the transform 'Cesium.HeadingPitchRoll.
fromQuaternion
<https://cesiumjs.org/Cesium/Build/Documentation/HeadingPitchRoll.html?classFilter=headingPitchRoll#.fromQuaternion&gt;&#39;
to extract the headingPitchRoll
<https://cesiumjs.org/Cesium/Build/Documentation/HeadingPitchRoll.html&gt;
from the quaternion and finally the toString()
<https://cesiumjs.org/Cesium/Build/Documentation/HeadingPitchRoll.html#toString&gt;
method to put heading, pitch and roll into a string.

The values in the string appear to be earth-oriented (e.g., affected by
the lat/lon) rather than the local heading, pitch and roll. When the nose
of the aircraft is [locally] vertical, the pitch is 0.89 radians or 51.1° :
the same as the latitude.

I'm obviously missing a transform but can't find one that is the direct
inverse of 'Cesium.Transforms.headingPitchRollQuaternion'?

Quaternions make my head hurt!

Thanks,

Hugh

--
You received this message because you are subscribed to a topic in the
Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/cesium-dev/sxqmI-NPqpg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
cesium-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hello,
From what I understood, you should “only” remove the rotation from local frame (by default East North Up local frame) to retrieve the desired result.

one solution

const scratchInvEastNorthUpFrame = new Matrix4();
const scratchInvRotation = new Matrix3();
const scratchInvRotationQ = new Quaternion();
const scratchLocalQuaternion = new Quaternion();
const scratchLocalHpr = new HeadingPitchRoll();

function getLocalHpr(origin, quaternion) {
    const eastNorthUpFrame = Transforms.eastNorthUpToFixedFrame(origin);
    const invEastNorthUpFrame = Matrix4.inverse(eastNorthUpFrame, scratchInvEastNorthUpFrame);

    const invRotation = Matrix4.getRotation(invEastNorthUpFrame, scratchInvRotation);
    const invRotationQ = Quaternion.fromRotationMatrix(invRotation, scratchInvRotationQ);

    const localQuaternion = Quaternion.multiply(invRotationQ, quaternion, scratchLocalQuaternion);
    
    return HeadingPitchRoll.fromQuaternion(localQuaternion, scratchLocalHpr);
}