使用cesiumjs,我想计算两点之间的仰角,好像我们站在第一点的热气球上一样。这些点是简单的制图点(纬度,长度,高度)。
经过一番研究,这是一种建议的方法:
将地球固定帧中的目标点转换为此局部 水平平面,你可以使用Transforms.eastNorthUpToFixedFrame。 返回一个Matrix4,然后再乘以你的目标点 矢量,产生一个新的向量。规范化该向量,然后对 仰角只是归一化矢量的asin(z)。
这是我放在一起的代码,但它返回NaN进行乘法运算。任何建议都将不胜感激。
var Cesium = require('cesium');
var startPoint = new Cesium.Cartesian3.fromDegrees(-107, 30, 3000);
var endPoint = new Cesium.Cartesian3.fromDegrees(-112, 25, 1000000);
//To transform your target point in the Earth-fixed frame to this local horizontal plane, you can use Transforms.eastNorthUpToFixedFrame.
var effTarget = Cesium.Transforms.eastNorthUpToFixedFrame(endPoint)
console.log("Earth-fixed frame (target): " + effTarget);
//That returns a Matrix4, which you then multiply your target point vector by, yielding a new vector.
var multiplicationResult = new Cesium.Cartesian3();
Cesium.Cartesian3.multiplyComponents(effTarget, endPoint, multiplicationResult)
console.log("Multiplication result: " + multiplicationResult)
//Normalize that vector
var normalizationResult = new Cesium.Cartesian3();
Cesium.Cartesian3.normalize(multiplicationResult, normalizationResult);
console.log("Normalize result: " + normalizationResult)
//and then the elevation angle is simply asin(z) of the normalized vector.
var elevationAngle = Math.asin(normalizationResult.z)
console.log("Elevation angle: " + elevationAngle)
答案 0 :(得分:1)
var startPoint = new Cesium.Cartesian3.fromDegrees(-107, 30, 3000);
var endPoint = new Cesium.Cartesian3.fromDegrees(-112, 25, 1000000);
// Obtain vector by taking difference of the end points.
var difference = Cesium.Cartesian3.subtract(endPoint, startPoint, new Cesium.Cartesian3());
difference = Cesium.Cartesian3.normalize(difference, new Cesium.Cartesian3());
console.log("Difference: " + difference);
// Obtain surface normal by normalizing the starting point position.
var surfaceNormal = Cesium.Cartesian3.normalize(startPoint, new Cesium.Cartesian3());
console.log("Surface normal: " + surfaceNormal);
// Take the dot product of your given vector and the surface normal.
var dotProduct = Cesium.Cartesian3.dot(difference, surfaceNormal);
console.log("Dot product: " + dotProduct);
// Arcos the result.
var angle = 90 - Cesium.Math.toDegrees(Math.acos(dotProduct));
console.log("Angle: " + angle);
控制台:
Difference: (-0.696260739885982, -0.7156821634654381, -0.05495473583645852)
Surface normal: (-0.2536245226271608, -0.8295684339468393, 0.4974844871160639)
Dot product: 0.7429570007551259
Angle: 47.9839196010689
答案 1 :(得分:0)
我相信你正在使用错误的对象进行乘法运算。尝试使用.multiplyByPoint方法获取新的Cartesian3结果:
//That returns a Matrix4, which you then multiply your target point vector by, yielding a new vector.
var multiplicationResult = new Cesium.Cartesian3();
Cesium.Matrix4.multiplyByPoint(effTarget, endPoint, multiplicationResult)
console.log("Multiplication result: " + multiplicationResult)
您应该可以继续multiplicationResult
。
答案 2 :(得分:0)
这是正确的方向,但还不是很正确:
var startPoint = new Cesium.Cartesian3.fromDegrees(-107, 30, 3000);
var endPoint = new Cesium.Cartesian3.fromDegrees(-112, 25, 1000000);
//To transform your target point in the Earth-fixed frame to this local horizontal plane, you can use Transforms.eastNorthUpToFixedFrame.
var effTarget = Cesium.Transforms.eastNorthUpToFixedFrame(endPoint);
console.log("Earth-fixed frame (target): " + effTarget);
//That returns a Matrix4, which you then multiply your target point vector by, yielding a new vector.
var multiplicationResult = Cesium.Matrix4.multiplyByPointAsVector(effTarget, startPoint, new Cesium.Cartesian3());
console.log("Multiplication result: " + multiplicationResult);
//Normalize that vector
var normalizationResult = new Cesium.Cartesian3();
Cesium.Cartesian3.normalize(multiplicationResult, normalizationResult);
console.log("Normalize result: " + normalizationResult);
//and then the elevation angle is simply asin(z) of the normalized vector.
var elevationAngle = Math.asin(normalizationResult.z);
console.log("Elevation angle: " + Cesium.Math.toDegrees(elevationAngle));