Home > SYS_Math > calculateArea
SYS_Math.calculateArea() method
Calculate the area of a polygon
Signature
typescript
function calculateArea(polygon: TSYS_MathPolygonInput): number;1
Parameters
Parameter | Type | Description |
|---|---|---|
polygon | Polygon or polygon group |
Returns
number
Area (absolute area for a single polygon, net area for a polygon group)
Remarks
Calculated using the Shoelace formula: - When a single polygon is passed in, the absolute area of the polygon is returned - When a polygon group (TSYS_MathPolygonGroup, such as the return value of Boolean operations) is passed in, the net area is obtained by subtracting the sum of all hole areas from the sum of all outer ring areas
Example
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