SYS_Math.union() method
Calculate the union of two polygons
Signature
typescript
function union(
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 union result, preserving the association between outer rings and holes
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 merged = eda.sys_Math.union(copperA, copperB);
console.log('合并后多边形个数:', merged.length);
console.log('合并后外环顶点数:', merged[0].outer.length);
console.log('合并后孔洞数:', merged[0].holes.length);
// 3. 合并后的净面积:8000 + 4000 - 重叠的 2000 = 10000(重叠只算一次)
console.log('合并后面积:', eda.sys_Math.calculateArea(merged));
// 4. 完全分离的两个多边形合并时仍是两个独立多边形
const far = [{ x: 200, y: 0 }, { x: 280, y: 0 }, { x: 280, y: 40 }, { x: 200, y: 40 }];
console.log('分离区域合并后个数:', eda.sys_Math.union(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