CESIUM空间中AB两点A绕B点的地面法向量旋转任意角度后新的A点坐标(A’)
var A = new Cesium.Cartesian3(675679.994355399, 4532763.148054989, 4426298.210847025); var B = new Cesium.Cartesian3(675520.4303984543, 4532803.837842555, 4425994.113846752); // 计算B的地面法向量 var chicB = Cesium.Cartographic.fromCartesian(B); chicB.height = 0; var dB = Cesium.Cartographic.toCartesian(chicB); var normaB = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(dB, B, new Cesium.Cartesian3()), new Cesium.Cartesian3()); // 构造基于B的法向量旋转90度的矩阵 var Q = Cesium.Quaternion.fromAxisAngle(normaB, Cesium.Math.toRadians(90)); var m3 = Cesium.Matrix3.fromQuaternion(Q); var m4 = Cesium.Matrix4.fromRotationTranslation(m3); // 计算A点相对B点的坐标A1 var A1 = Cesium.Cartesian3.subtract(A, B, new Cesium.Cartesian3()); //对A1应用旋转矩阵 var p = Cesium.Matrix4.multiplyByPoint(m4, A1, new Cesium.Cartesian3()); // 新的A的坐标 var p2 = Cesium.Cartesian3.add(p, B, new Cesium.Cartesian3()); viewer.entities.add({ polyline: { positions: [B, A], width: 5, material: Cesium.Color.RED }, }); viewer.entities.add({ polyline: { positions: [B, p2], width: 5, material: Cesium.Color.BLUE }, });