Entity orientation from quaternion

1. A concise explanation of the problem you're experiencing.
I have the quaternion representing an entity's orientation from the ECEF frame to the body frame (e.g. body frame for an aircraft: +x is out of nose, +y is out of starboard wing, +z is down). I also have the entity's ECEF position.

How do I assign the quaternion and tell it that it is ECEF to body? It seems like all options require a heading/pitch/roll or a local NED/ENU frame.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

var position_ecef = new Cesium.Cartesian3(ecef_x, ecef_y, ecef_z);
var orientation_ecef_to_body = new Cesium.quaternion(qx, qy, qz, qw);
   position: position_ecef,
   orientation: orientation_ecef_to_body

How do I specify that the orientation is ECEF to body? Or do I have to convert my quaternion to something else first?


Just checking to see if anybody can help me out with this.

I got this working, so I figured I'd share in case anyone else needs it.

I have a quaternion defining the rotation to get from ECEF to body:
q_ecef_to_body = new Cesium.Quaternion(x,y,z,w);

Then I need to get the quaternion from ENU to ECEF. This is a multi-step calculation:
var origin = new Cesium.Cartesian3(0, 0, 0);
var r4_enu_to_ecef = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
var r3_enu_to_ecef = Cesium.Matrix4.getRotation(r4_enu_to_ecef, new Cesium.Matrix3);
var q_enu_to_ecef = Cesium.Quaternion.fromRotationMatrix(r3_enu_to_ecef);

Now I can calculate the quaternion defining the orientation from ENU to body, which is what I need to assign to the entity's orientation. Note that multiplication order matters.
q_enu_to_body = Cesium.Quaternion.multiply(q_ecef_to_body, q_enu_to_ecef, new Cesium.Quaternion);

One more thing: on the quaternion multiplication, if one quaternion is normalized, make sure the other one is too. Otherwise the result will be wrong.

For example, if q_ecef_to_body is normalized, then you must normalize q_enu_to_ecef before multiplying:
q_enu_to_ecef = Cesium.Quaternion.normalize(q_enu_to_ecef, new Cesium.Quaternion);

Hi Steven,

Sorry for the delay, but glad you figured it out thanks for the updates! Transforms.eastNorthUpToFixedFrame() is indeed the way to transform between reference frames.