From ab3aa61521fcdbe90493f98845ba4725f3087d96 Mon Sep 17 00:00:00 2001 From: muxuming1 Date: Thu, 14 Aug 2025 16:51:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84generatePoints?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E7=94=A8Cesium=E7=9A=843D?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E7=B3=BB=E7=BB=9F=E8=AE=A1=E7=AE=97=E5=9C=86?= =?UTF-8?q?=E5=91=A8=E7=82=B9=20=E6=94=B9=E8=BF=9B=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E4=BB=A5=E8=80=83=E8=99=91=E5=9C=B0=E7=90=83=E6=9B=B2=E7=8E=87?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8ENU=E5=B1=80=E9=83=A8=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/polygon/circle.ts | 80 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/src/polygon/circle.ts b/src/polygon/circle.ts index 6cd438e..aa0b1fb 100644 --- a/src/polygon/circle.ts +++ b/src/polygon/circle.ts @@ -61,24 +61,86 @@ export default class Circle extends Base { const radius = Utils.MathDistance(center, pnt2); - const res = this.generatePoints(center, radius); + const res = this.generatePoints(positions); const temp = [].concat(...res); const cartesianPoints = this.cesium.Cartesian3.fromDegreesArray(temp); return cartesianPoints; } - - generatePoints(center, radius) { - let x, y, angle; + generatePoints(positions) { 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++) { - angle = (Math.PI * 2 * i) / 100; - x = center[0] + radius * Math.cos(angle); - y = center[1] + radius * Math.sin(angle); - points.push([x, y]); + const angle = (Math.PI * 2 * i) / 100; + const cosAngle = Math.cos(angle); + const sinAngle = Math.sin(angle); + + // 计算偏移量(基于米) + 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; } - getPoints() { return this.points; }