Cesium的一些坐标变换公式记录
程序员文章站
2022-05-27 14:37:30
...
var daTAs = {
code: '',
longitude: 121.42875949287559,
latitude: 31.198376344961723,
height: 6,
heading: 90,
scale: 1,
range: 50,
bimshow: true,
iseidting: false,
depthtest: false,
mat: '',
};
/* CESIUM原装函数 */
/* CESIUM原装函数 */
/* CESIUM原装函数 */
/*
new Cesium.Matrix3(
column0Row0, column1Row0, column2Row0,
column0Row1, column1Row1, column2Row1,
column0Row2, column1Row2, column2Row2)
*/
//经纬度坐标转换笛卡尔坐标
//Cartesian3.fromDegrees = a {x: -2847383.0422115843, y: 4659501.404998853, z: 3284729.700788161}
var fromDegrees = Cesium.Cartesian3.fromDegrees(daTAs.longitude, daTAs.latitude, daTAs.height);
var fromDegrees1 = Cesium.Cartesian3.fromDegrees(daTAs.longitude- 0.0005, daTAs.latitude- 0.0005, daTAs.height);
//笛卡尔坐标转换成4X4的矩阵,Transfroms。第四行是笛卡尔坐标,前三行是旋转参数。
var eastNorthUpToFixedFrame = Cesium.Transforms.eastNorthUpToFixedFrame(fromDegrees);
//角度转换为弧度
//函数3:Math.toRadians = 0.5235987755982988
var toRadians = Cesium.Math.toRadians(daTAs.heading);
//弧度转换成3X3的矩阵,
var fromRotationZ = Cesium.Matrix3.fromRotationZ(toRadians);
//3X3矩阵转换成4X4矩阵,前三行一样,第四行为(0 0 0 1)
var fromRotationTranslation =Cesium.Matrix4.fromRotationTranslation(fromRotationZ);
//计算两个矩阵的乘积Cesium.Matrix4.multiply(a, b, a),a = a*b;
var multiply = Cesium.Matrix4.multiply(eastNorthUpToFixedFrame, fromRotationTranslation, eastNorthUpToFixedFrame);
//笛卡尔坐标转为经纬度坐标(longitude, latitude, height),用经纬度用弧度
//fromCartesian.longitude = 2.1193316597629988
var fromCartesian = Cesium.Cartographic.fromCartesian(fromDegrees);
//函数8:弧度转为角度
//Math.toDegrees = 121.42875949287559
var toDegrees = Cesium.Math.toDegrees(fromCartesian.longitude);
//获得4X4矩阵左上角的3X3旋转矩阵
/*Matrix4.getRotation = {
0: -0.6039169322494417, 1: -0.6725816358851927, 2: 0.4276894691390252,
3: 0.6605635299913337, 4: -0.12206955725374125, 5: 0.7407798904109532,
6: -0.44602708638356436, 7: 0.7298855843636546, 8: 0.5180027721453959}*/
var getRotation = Cesium.Matrix4.getRotation(multiply, new Cesium.Matrix3());
//Matrix3.multiplyByVector计算3X3矩阵和列向量的乘积
//rotpos = new Cesium.Cartesian3 = a {x: 50, y: 0, z: 0}
var rotpos = new Cesium.Cartesian3(daTAs.range, 0.0, 0.0);
//multiplyByVector = a {x: -30.19584661247208, y: -33.62908179425963, z: 21.384473456951262}
var multiplyByVector = Cesium.Matrix3.multiplyByVector(getRotation, rotpos, new Cesium.Cartesian3());
//Cesium.Cartesian3.add(left, right, result),两个矩阵相加
//fromDegrees = a {x: -2847383.0422115843, y: 4659501.404998853, z: 3284729.700788161}
//addrotpos = a {x: -2847413.238058197, y: 4659467.775917059, z: 3284751.085261618}
var addrotpos = Cesium.Cartesian3.add(fromDegrees, multiplyByVector, new Cesium.Cartesian3());
//Cesium.Matrix3.getColumn(matrix, index, result),获取矩阵指定行的数据
//xaxis = getRotation[0] = a {x: -0.6039169322494417, y: -0.6725816358851927, z: 0.4276894691390252}
var xaxis = Cesium.Matrix3.getColumn(getRotation, 0, new Cesium.Cartesian3());
var yaxis = Cesium.Matrix3.getColumn(getRotation, 1, new Cesium.Cartesian3());
var zaxis = Cesium.Matrix3.getColumn(getRotation, 2, new Cesium.Cartesian3());
//Cesium.Cartesian3.subtract(left, right, result),两个矩阵相减
//subtract = a {x: -25.058249244466424, y: -23.75879775546491, z: 11.900636777747422}
var subtract = Cesium.Cartesian3.subtract(addrotpos, fromDegrees1 , new Cesium.Cartesian3());
//Cesium.Cartesian3.cross(left, right, result) ,计算两个坐标的叉(外)积
//subtract X zaxis = a {x: -20.99322632899841, y: 7.672236225656107, z: -28.886722231773863}
//zaxis X dir01 = a {x: -25.05824176993303, y: -23.75880998690632, z: 11.900628097043635}
var dir01 = Cesium.Cartesian3.cross(subtract, zaxis, new Cesium.Cartesian3());
var dir02 = Cesium.Cartesian3.cross(zaxis, dir01, new Cesium.Cartesian3());
//Cesium.Cartesian3.normalize(cartesian, result),标准化
//dir02normalize = a {x: -0.6039169322500869, y: -0.6725816358850737, z: 0.42768946913830164}
var dir02normalize = Cesium.Cartesian3.normalize(dir02, new Cesium.Cartesian3());
//Cesium.Cartesian3.angleBetween(left, right),两个坐标的夹角,弧度表示
//angleBetween(xaxis, dir02normalize) = 0.13281132473930984
var angleBetween = Cesium.Cartesian3.angleBetween(xaxis, dir02normalize);
console.log('_____CESIUM原始函数_____');
console.log('函数1:Cesium.Cartesian3.fromDegrees');
console.log('fromDegrees =', fromDegrees);
console.log('fromDegrees1 =', fromDegrees1);
console.log('函数2:Transforms.eastNorthUpToFixedFrame = ', eastNorthUpToFixedFrame);
console.log('函数3:Math.toRadians = ', toRadians);
console.log('函数4:Matrix3.fromRotationZ = ', fromRotationZ);
console.log('函数5:Matrix4.fromRotationTranslation = ', fromRotationTranslation);
console.log('函数6:Matrix4.multiply = ',multiply);
console.log('函数7:Cartographic.fromCartesian = ', fromCartesian);
console.log('函数8:Math.toDegrees = ', toDegrees);
console.log('函数9:Matrix4.getRotation = ', getRotation);
console.log('函数10:Matrix3.multiplyByVector = ', multiplyByVector);
console.log('new Cesium.Cartesian3 = ', rotpos);
console.log('函数11:Cartesian3.add = ', addrotpos);
console.log('函数12:Cesium.Matrix3.getColumn');
console.log('xaxis = ', xaxis);
console.log('yaxis = ', yaxis);
console.log('zaxis = ', zaxis);
console.log('函数13:Cesium.Cartesian3.subtract');
console.log('Cartesian3.add — Cartesian3.fromDegrees = ');
console.log('subtract = ', subtract);
console.log('函数14:Cesium.Cartesian3.cross');
console.log('subtract X zaxis = ', dir01);
console.log('zaxis X dir01 = ', dir02);
console.log('函数15:Cesium.Cartesian3.normalize');
console.log('dir02normalize = ', dir02normalize);
console.log('函数16:Cesium.Cartesian3.angleBetween');
console.log('angleBetween(xaxis, dir02normalize) = ', angleBetween);
console.log('角度angleBetween = ', Cesium.Math.toDegrees(angleBetween));
上一篇: cesium 添加监听事件、获取中心点坐标、高度、当前可视化区域范围
下一篇: 打印当前经纬度和高度
推荐阅读