Home > SYS_Math > calculateArea
SYS_Math.calculateArea() method
计算多边形面积
签名
typescript
public calculateArea(polygon: TSYS_MathPolygonInput): number;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形或多边形组 |
返回值
number
面积(单个多边形为绝对面积,多边形组为净面积)
备注
使用 Shoelace 公式计算: - 传入单个多边形时,返回该多边形的绝对面积 - 传入多边形组(TSYS_MathPolygonGroup,如布尔运算的返回值)时, 计算所有外环面积之和减去所有孔洞面积之和,得到净面积
示例
javascript
// 1. 单个矩形 100 x 80(单位随输入坐标系,PCB 场景下通常是 mil)
const rect = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
console.log('矩形面积:', eda.sys_Math.calculateArea(rect));
// 2. 单个三角形(底 100 高 60,面积应为 3000)
const triangle = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 50, y: 60 }];
console.log('三角形面积:', eda.sys_Math.calculateArea(triangle));
// 3. 布尔运算返回的多边形组直接作为输入,得到净面积(含孔洞时自动扣除)
const overlap = [{ x: 50, y: 20 }, { x: 150, y: 20 }, { x: 150, y: 60 }, { x: 50, y: 60 }];
const merged = eda.sys_Math.union(rect, overlap);
console.log('两矩形合并后的净面积:', eda.sys_Math.calculateArea(merged));1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12