Created
May 4, 2018 12:25
-
-
Save thw0rted/4857eea152fcc54265330c00775f0fb5 to your computer and use it in GitHub Desktop.
Cesium function to transform relative heading-pitch-roll to absolute rotation Quaternion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Cartesian3, | |
HeadingPitchRoll, | |
Matrix3, | |
Matrix4, | |
Quaternion, | |
Transforms, | |
} from "cesium"; | |
/** | |
* Convert a local heading/pitch/range rotation to an earth-axis-relative Quaternion | |
* @param position a Cartesian3 point in space | |
* @param heading degrees from North, rotation around Earth-normal vector | |
* @param pitch degrees from horizontal, rotation around earth-tangent X axis | |
* @param roll degrees from vertical, rotation around earth-tangent Y axis | |
*/ | |
export function relativeOrientation(position: Cartesian3, | |
heading: number, pitch: number, roll: number): Quaternion { | |
// Build a Quaternion that represents the rotation between absolute and | |
// local-surface frames of reference | |
const transform4 = Transforms.eastNorthUpToFixedFrame(position); | |
const transform3 = new Matrix3(); | |
Matrix4.getRotation(transform4, transform3); | |
const transformQ = Quaternion.fromRotationMatrix(transform3); | |
// Convert the h/p/r values to a (local-reference) Quaternion | |
const localHpr = HeadingPitchRoll.fromDegrees(heading, pitch, roll); | |
const localQ = Quaternion.fromHeadingPitchRoll(localHpr); | |
// Result is local times transform | |
const ret = new Quaternion(); | |
Quaternion.multiply(localQ, transformQ, ret); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment