mirror of
https://github.com/ethan-zf/cesium-plot-js.git
synced 2025-12-28 23:20:00 +00:00
feat: 重构generatePoints方法,使用Cesium的3D坐标系统计算圆周点
改进算法以考虑地球曲率,使用ENU局部坐标系
This commit is contained in:
parent
a8b7f2b46d
commit
ab3aa61521
@ -61,24 +61,86 @@ export default class Circle extends Base {
|
|||||||
|
|
||||||
const radius = Utils.MathDistance(center, pnt2);
|
const radius = Utils.MathDistance(center, pnt2);
|
||||||
|
|
||||||
const res = this.generatePoints(center, radius);
|
const res = this.generatePoints(positions);
|
||||||
const temp = [].concat(...res);
|
const temp = [].concat(...res);
|
||||||
const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(temp);
|
const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(temp);
|
||||||
return cartesianPoints;
|
return cartesianPoints;
|
||||||
}
|
}
|
||||||
|
generatePoints(positions) {
|
||||||
generatePoints(center, radius) {
|
|
||||||
let x, y, angle;
|
|
||||||
const points = [];
|
const points = [];
|
||||||
|
const degreesPerRadian = 180.0 / Math.PI;
|
||||||
|
|
||||||
|
// 验证输入格式
|
||||||
|
if (!positions || positions.length !== 2) {
|
||||||
|
console.error('输入参数格式错误,需要包含两个世界坐标点');
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
// 提取中心点和第二点(均为Cartesian3世界坐标)
|
||||||
|
const centerCartesian = positions[0];
|
||||||
|
const secondPointCartesian = positions[1];
|
||||||
|
|
||||||
|
// 计算两点之间的距离作为半径(米)
|
||||||
|
const radius = this.cesium.Cartesian3.distance(centerCartesian, secondPointCartesian);
|
||||||
|
// 计算局部坐标系(东-北-上)
|
||||||
|
const localFrame = this.cesium.Transforms.eastNorthUpToFixedFrame(centerCartesian);
|
||||||
|
// 提取东向和北向单位向量
|
||||||
|
const eastVector = this.cesium.Cartesian3.fromElements(
|
||||||
|
localFrame[0],
|
||||||
|
localFrame[1],
|
||||||
|
localFrame[2],
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const northVector = this.cesium.Cartesian3.fromElements(
|
||||||
|
localFrame[4],
|
||||||
|
localFrame[5],
|
||||||
|
localFrame[6],
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 归一化方向向量
|
||||||
|
this.cesium.Cartesian3.normalize(eastVector, eastVector);
|
||||||
|
this.cesium.Cartesian3.normalize(northVector, northVector);
|
||||||
|
|
||||||
|
// 生成圆周点
|
||||||
for (let i = 0; i <= 100; i++) {
|
for (let i = 0; i <= 100; i++) {
|
||||||
angle = (Math.PI * 2 * i) / 100;
|
const angle = (Math.PI * 2 * i) / 100;
|
||||||
x = center[0] + radius * Math.cos(angle);
|
const cosAngle = Math.cos(angle);
|
||||||
y = center[1] + radius * Math.sin(angle);
|
const sinAngle = Math.sin(angle);
|
||||||
points.push([x, y]);
|
|
||||||
|
// 计算偏移量(基于米)
|
||||||
|
const eastOffset = this.cesium.Cartesian3.multiplyByScalar(
|
||||||
|
eastVector,
|
||||||
|
radius * cosAngle,
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
const northOffset = this.cesium.Cartesian3.multiplyByScalar(
|
||||||
|
northVector,
|
||||||
|
radius * sinAngle,
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 计算目标点
|
||||||
|
const targetPoint = this.cesium.Cartesian3.add(
|
||||||
|
centerCartesian,
|
||||||
|
this.cesium.Cartesian3.add(eastOffset, northOffset, new this.cesium.Cartesian3()),
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 投影到椭球表面
|
||||||
|
const surfacePoint = this.cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(
|
||||||
|
targetPoint,
|
||||||
|
new this.cesium.Cartesian3(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 转换回经纬度
|
||||||
|
const cartographic = this.cesium.Cartographic.fromCartesian(surfacePoint);
|
||||||
|
const longitude = cartographic.longitude * degreesPerRadian;
|
||||||
|
const latitude = cartographic.latitude * degreesPerRadian;
|
||||||
|
|
||||||
|
points.push([longitude, latitude]);
|
||||||
}
|
}
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoints() {
|
getPoints() {
|
||||||
return this.points;
|
return this.points;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user