Home > SYS_Math > distanceToPoint
SYS_Math.distanceToPoint() method
计算点到多边形边界的最短距离
签名
typescript
function distanceToPoint(polygon: TSYS_MathPolygonInput, point: ISYS_MathPoint): number;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形 | |
point | 待计算的点 |
返回值
number
最短距离,如点在多边形内部则返回 0
示例
javascript
// 1. 定义矩形区域(右边界在 x = 100)
const zone = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
// 2. 外部点:到右边界的水平距离为 50
const outsidePoint = { x: 150, y: 40 };
console.log('外部点到边界的最短距离:', eda.sys_Math.distanceToPoint(zone, outsidePoint));
// 3. 内部点:在多边形内部时返回 0
const insidePoint = { x: 50, y: 40 };
console.log('内部点到边界的最短距离:', eda.sys_Math.distanceToPoint(zone, insidePoint));
// 4. 斜向最近边不是正对的那条边时,结果取真实垂线距离
const diagonalPoint = { x: 130, y: 110 };
console.log('斜向点到边界的最短距离:', eda.sys_Math.distanceToPoint(zone, diagonalPoint));1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14