Home > SYS_Math > intersection
SYS_Math.intersection() method
Calculate the intersection of two polygons
Signature
typescript
function intersection(
polygon1: TSYS_MathPolygonInput,
polygon2: TSYS_MathPolygonInput,
): TSYS_MathPolygonGroup;1
2
3
4
2
3
4
Parameters
Parameter | Type | Description |
|---|---|---|
polygon1 | Polygon 1 | |
polygon2 | Polygon 2 |
Returns
Polygon group of the intersection result. An empty array means no intersection
Example
javascript
// 1. 两块部分重叠的矩形区域
const copperA = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const copperB = [{ x: 50, y: 20 }, { x: 150, y: 20 }, { x: 150, y: 60 }, { x: 50, y: 60 }];
// 2. 求交集,结果为一个新的多边形组
const overlap = eda.sys_Math.intersection(copperA, copperB);
console.log('重叠区域个数:', overlap.length);
console.log('重叠区域外环顶点:', overlap[0].outer.length, '个');
console.log('重叠区域孔洞数:', overlap[0].holes.length);
// 3. 交集面积:100 x 100 与 100 x 80 的重叠部分为 50 x 40 = 2000
console.log('重叠区域面积:', eda.sys_Math.calculateArea(overlap));
// 4. 完全分离的两个多边形没有交集,返回空数组
const far = [{ x: 200, y: 0 }, { x: 280, y: 0 }, { x: 280, y: 40 }, { x: 200, y: 40 }];
console.log('分离区域的交集个数:', eda.sys_Math.intersection(copperA, far).length);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