SYS_Math.subtract() method
Calculate the difference of two polygons (polygon1 - polygon2)
Signature
typescript
function subtract(
polygon1: TSYS_MathPolygonInput,
polygon2: TSYS_MathPolygonInput,
): TSYS_MathPolygonGroup;1
2
3
4
2
3
4
Parameters
Parameter | Type | Description |
|---|---|---|
polygon1 | Minuend polygon | |
polygon2 | Subtrahend polygon |
Returns
Polygon group of the difference result, preserving the association between outer rings and holes
Example
javascript
// 1. 大矩形铺铜区域与一个完全落在其内部的矩形开孔区
const copper = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
const hole = [{ x: 30, y: 20 }, { x: 70, y: 20 }, { x: 70, y: 60 }, { x: 30, y: 60 }];
// 2. 挖孔:差集结果的多边形组里,开孔区被记为孔洞
const cut = eda.sys_Math.subtract(copper, hole);
console.log('差集结果多边形个数:', cut.length);
console.log('孔洞数:', cut[0].holes.length);
// 3. 挖孔后的净面积:100 x 80 - 40 x 40 = 6400
console.log('挖孔后的净面积:', eda.sys_Math.calculateArea(cut));
// 4. 减去完全分离的多边形不产生任何变化(结果仍是原形状的等价组)
const far = [{ x: 200, y: 0 }, { x: 280, y: 0 }, { x: 280, y: 40 }, { x: 200, y: 40 }];
const untouched = eda.sys_Math.subtract(copper, far);
console.log('减去分离区域后的面积:', eda.sys_Math.calculateArea(untouched));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