效果展示
关键代码
//求方位角和朝向
export function getHeadingPitchRoll(m) {
var m1 = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Matrix4.getTranslation(m, new Cesium.Cartesian3()), Cesium.Ellipsoid.WGS84, new Cesium.Matrix4());
var m3 = Cesium.Matrix4.multiply(Cesium.Matrix4.inverse(m1, new Cesium.Matrix4()), m, new Cesium.Matrix4());
var mat3 = Cesium.Matrix4.getMatrix3(m3, new Cesium.Matrix3());
var q = Cesium.Quaternion.fromRotationMatrix(mat3);
var hpr = Cesium.HeadingPitchRoll.fromQuaternion(q);
var heading = Cesium.Math.toDegrees(hpr.heading);
var pitch = Cesium.Math.toDegrees(hpr.pitch);
var roll = Cesium.Math.toDegrees(hpr.roll);
return hpr
}
//模型矩阵
export function getModelMatrix(pointA, pointB) {
const vector2 = Cesium.Cartesian3.subtract(pointB, pointA, new Cesium.Cartesian3());
//归一化
const normal = Cesium.Cartesian3.normalize(vector2, new Cesium.Cartesian3());
const rotationMatrix3 = Cesium.Transforms.rotationMatrixFromPositionVelocity(pointA, normal, Cesium.Ellipsoid.WGS84);
const orientation = Cesium.Quaternion.fromRotationMatrix(rotationMatrix3);
const modelMatrix4 = Cesium.Matrix4.fromRotationTranslation(rotationMatrix3, pointA);
const hpr = Cesium.HeadingPitchRoll.fromQuaternion(orientation);
return modelMatrix4;
}
源码下载:Cesium雷达追踪卫星