Hi, to simulate a drone flight I’m trying to draw a vector that indicates the heading of the drone.
The heading of the drone is in radians from true north, so I figured I’d use fixedFrameToHeadingPitchRoll to do this.
The documentation says “Heading is the rotation from the local north direction where a positive angle is increasing eastward.” so I figured I’d plug in 0 for my first try, expecting all the vectors to point north. Instead they pointed directly east indicating the rotation is from east, not from north.
In the example code in the documentation this snippet is used:
const center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
const heading = -Cesium.Math.PI_OVER_TWO;
const pitch = Cesium.Math.PI_OVER_FOUR;
const roll = 0.0;
const hpr = new HeadingPitchRoll(heading, pitch, roll);
const quaternion = Cesium.Transforms.headingPitchRollQuaternion(center, hpr);
Which also seems to suggest subtracting pi over two from the heading, but there’s no explanation for why that example is used and what the expected result would be.
Or am I just using transforms wrong? This is how I’m drawing the vector:
const heading = waypoint.heading - Cesium.Math.PI_OVER_TWO
const headingIndicatorLength = 5 //meters
const headingIndicatorStartPos = position
const headingTransform = Cesium.Transforms.headingPitchRollToFixedFrame(position, new Cesium.HeadingPitchRoll(heading, 0, 0))
const headingVector = Matrix3.multiplyByVector(Matrix4.getMatrix3(headingTransform, new Matrix3()), Cartesian3.UNIT_X, new Cartesian3())
const headingIndicatorEndpoint = Cartesian3.add(
headingIndicatorStartPos,
Cartesian3.multiplyByScalar(headingVector, headingIndicatorLength, new Cartesian3()),
new Cartesian3()
)
this.lineToHeading = new LinePrimitive(
[headingIndicatorStartPos, headingIndicatorEndpoint],
Matrix4.IDENTITY,
Cesium.Color.YELLOWGREEN,
{}
)
this.context.viewer.scene.primitives.add(this.lineToHeading)