## 坐标插值

// 如下代码插值计算出的航线有问题
property.setInterpolationOptions({
interpolationDegree : 5,
interpolationAlgorithm : Cesium.LagrangePolynomialApproximation
});


/**
* 重新采样
* @param { [{ time:string, lng:number, lat:number, height:number }] } positions 坐标集合
*/
function sameple(positions) {
for (let i = 0; i < 3; i++) {
samepleOnce(positions);
}
}

/**
* 重新采样
* @param { [{ time:string, lng:number, lat:number, height:number }] } positions 坐标集合
*/
function samepleOnce(positions) {
for (let i = 0; i < positions.length - 1; i += 2) {
let pos1 = positions[i];
let pos2 = positions[i + 1];
let time1 = dayjs(pos1.time, 'YYYY-MM-DD HH:mm:ss');
let time2 = dayjs(pos2.time, 'YYYY-MM-DD HH:mm:ss');
let time = time1.add(time2.diff(time1) / 2.0, 'millisecond');
let lng = (pos1.lng + pos2.lng) / 2.0;
let lat = (pos1.lat + pos2.lat) / 2.0;
let height = (pos1.height + pos2.height) / 2.0;
let pos = {
time: time.format('YYYY-MM-DD HH:mm:ss.SSS'),
lng: lng,
lat: lat,
height: height,
}
positions.splice(i + 1, 0, pos);
}
}


/**
* @param { Cesium.Cartesian3 } pointA
* @param { Cesium.Cartesian3 } pointB
* @returns
*/
//建立以点A为原点，X轴为east,Y轴为north,Z轴朝上的坐标系
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(pointA);
//向量AB
const positionvector = Cesium.Cartesian3.subtract(pointB, pointA, new Cesium.Cartesian3());
//因transform是将A为原点的eastNorthUp坐标系中的点转换到世界坐标系的矩阵
//AB为世界坐标中的向量
//因此将AB向量转换为A原点坐标系中的向量，需乘以transform的逆矩阵。
const vector = Cesium.Matrix4.multiplyByPointAsVector(
Cesium.Matrix4.inverse(transform, new Cesium.Matrix4()),
positionvector,
new Cesium.Cartesian3()
);
//归一化
const direction = Cesium.Cartesian3.normalize(vector, new Cesium.Cartesian3());
let heading = Math.atan2(direction.y, direction.x) - Cesium.Math.PI_OVER_TWO;
}

/**
* 根据两个坐标点,获取Pitch(仰角)
* @param { Cesium.Cartesian3 } pointA
* @param { Cesium.Cartesian3 } pointB
* @returns
*/
function getPitch(pointA, pointB) {
let transfrom = Cesium.Transforms.eastNorthUpToFixedFrame(pointA);
const vector = Cesium.Cartesian3.subtract(pointB, pointA, new Cesium.Cartesian3());
let direction = Cesium.Matrix4.multiplyByPointAsVector(Cesium.Matrix4.inverse(transfrom, transfrom), vector, vector);
Cesium.Cartesian3.normalize(direction, direction);
//因为direction已归一化，斜边长度等于1，所以余弦函数等于direction.z
let pitch = Cesium.Math.PI_OVER_TWO - Cesium.Math.acosClamped(direction.z);
return Cesium.Math.toDegrees(pitch);
}


/**
* @param { [{ time:string, lng:number, lat:number, height:number }] } positions 坐标集合
*/
positions.map(pos => {
});

for (let i = 0; i < positions.length - 1; i++) {
let pos1 = positions[i];
let pos2 = positions[i + 1];
}
}
}

/**
* 计算无人机的pitch
* @param { [{ time:string, lng:number, lat:number, height:number }] } positions 坐标集合
*/
function calcPitch(positions) {
// 清空原有pitch
positions.map(pos => {
pos.pitch = undefined;
});

for (let i = 0; i < positions.length - 1; i++) {
let pos1 = positions[i];
let pos2 = positions[i + 1];
let pitch = getPitch(Cesium.Cartesian3.fromDegrees(pos1.lng, pos1.lat, pos1.height), Cesium.Cartesian3.fromDegrees(pos2.lng, pos2.lat, pos2.height));
if (!pos1.pitch) {
pos1.pitch = pitch;
}
pos2.pitch = pitch;
}
}

/**
* 计算无人机的roll(不支持转弯大于90度)
* @param { [{ time:string, lng:number, lat:number, height:number }] } positions 坐标集合
*/
function calcRoll(positions) {
// 清空原有roll
positions.map(pos => {
pos.roll = undefined;
});

for (let i = 1; i < positions.length - 1; i++) {
let pos1 = positions[i];
let pos2 = positions[i + 1];
}
}


## 遇到的问题

1. 插值计算的问题，就是设置的坐标集合，是拆线，最好把它插值成平滑曲线，但是Cesium自带的插值，有时间参数，而我想仅仅通过经纬度集合来插值。
2. 我写的计算roll的方法有问题，不支持转弯大于90度的情况，花了一些时间，没搞定。转弯小于90度，凑合用，测试了几组数据没问题，但仍不确定有没有BUG。严格来讲，根据这些参数，这个roll是算不出来的，但是，该算法要求根据飞机的转弯半径及方向，给出一个相对合理的roll值。
抛砖引玉，有没有高手给个提示，插值问题怎么解决？roll的正确的通用的计算方法？
posted @ 2024-04-02 12:16  0611163  阅读(638)  评论(0编辑  收藏  举报