// 假设当前模型的经纬度坐标为{114, 30, 1000} 方位角{heading: 30, pitch: 20, roll: 10} 都是角度来计算
// 1. 根据坐标, 方位角计算世界矩阵
var position = Cesium.Cartesian3.fromDegrees(114, 30, 1000);
var heading = Cesium.Math.toRadians(30);
var pitch = Cesium.Math.toRadians(20);
var roll = Cesium.Math.toRadians(10);
var headingPitchRoll = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var m = Cesium.Transforms.headingPitchRollToFixedFrame(position, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, new Cesium.Matrix4());
console.log(m);
// 2. 根据矩阵求方位角
// 我们就用上面得到的矩阵 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.getRotation(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);
console.log('heading : ' + heading, 'pitch : ' + pitch, 'roll : ' + roll);
Cesium坐标转换:cesium矩阵和方位角heading ,pitch, roll的相互转换
最新推荐文章于 2025-04-02 14:55:12 发布