Home > SYS_Math > intersects
SYS_Math.intersects() method
Determine whether two polygons intersect
Signature
typescript
function intersects(polygon1: TSYS_MathPolygonInput, polygon2: TSYS_MathPolygonInput): boolean;1
Parameters
Parameter | Type | Description |
|---|---|---|
polygon1 | Polygon 1 | |
polygon2 | Polygon 2 |
Returns
boolean
Whether they intersect
Remarks
Determine whether the regions of two polygons have any overlap (including containment, partial intersection, and boundary contact)
Example
javascript
// 1. 部分重叠的两个矩形 → true
const trace = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const keepout = [{ x: 50, y: 20 }, { x: 150, y: 20 }, { x: 150, y: 60 }, { x: 50, y: 60 }];
console.log('走线闯入禁布区:', eda.sys_Math.intersects(trace, keepout));
// 2. 完全分离 → false
const far = [{ x: 200, y: 0 }, { x: 280, y: 0 }, { x: 280, y: 40 }, { x: 200, y: 40 }];
console.log('走线远离另一区域:', eda.sys_Math.intersects(trace, far));
// 3. 完全包含也是相交的一种 → true
const small = [{ x: 20, y: 20 }, { x: 60, y: 20 }, { x: 60, y: 50 }, { x: 20, y: 50 }];
console.log('小区域整体在走线范围内:', eda.sys_Math.intersects(trace, small));
// 4. 仅边界贴合同样算相交 → true
const touching = [{ x: 100, y: 0 }, { x: 180, y: 0 }, { x: 180, y: 40 }, { x: 100, y: 40 }];
console.log('两区域边界贴合:', eda.sys_Math.intersects(trace, touching));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16