Home > SYS_Math > containsPoint
SYS_Math.containsPoint() method
Determine whether the point is inside the polygon
Signature
typescript
function containsPoint(polygon: TSYS_MathPolygonInput, point: ISYS_MathPoint): boolean;1
Parameters
Parameter | Type | Description |
|---|---|---|
polygon | Polygon | |
point | The point to determine |
Returns
boolean
Whether In polygon internal
Remarks
Use the ray casting method to determine whether the point is inside the polygon
Due to the characteristics of the ray casting method, points on the boundary behave inconsistently: some boundary points may return true, and some may return false, depending on the geometric relationship between the ray direction and the boundary
To strictly determine whether the point is on the boundary, combine SYS_Math.distanceToPoint() to check whether the distance is 0
Example
javascript
// 1. 定义一块禁布区,测试三个典型位置的点
const keepout = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const inside = { x: 50, y: 40 }; // 区域中心,明显在内部
const outside = { x: 150, y: 40 }; // 区域右侧,明显在外部
const corner = { x: 0, y: 0 }; // 顶点,落在边界上
console.log('中心点在禁布区内:', eda.sys_Math.containsPoint(keepout, inside));
console.log('外部点在禁布区内:', eda.sys_Math.containsPoint(keepout, outside));
console.log('顶点在禁布区内:', eda.sys_Math.containsPoint(keepout, corner));
// 2. 严格判断边界点:距离为 0 说明点恰好在边界上
console.log('顶点到边界的距离:', eda.sys_Math.distanceToPoint(keepout, corner));1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12