Home > SYS_Math > calculatePerimeter
SYS_Math.calculatePerimeter() method
计算多边形周长
签名
typescript
function calculatePerimeter(polygon: TSYS_MathPolygonInput): number;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形 |
返回值
number
周长
示例
javascript
// 1. 矩形 100 x 80,周长应为 360
const rect = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
console.log('矩形周长:', eda.sys_Math.calculatePerimeter(rect));
// 2. L 形轮廓(缺口裁掉一个角,周长按实际边界累加)
const lShape = [
{ x: 0, y: 0 },
{ x: 100, y: 0 },
{ x: 100, y: 40 },
{ x: 40, y: 40 },
{ x: 40, y: 80 },
{ x: 0, y: 80 },
];
console.log('L 形轮廓周长:', eda.sys_Math.calculatePerimeter(lShape));
// 3. 布尔运算返回的多边形组同样可以作为输入
const hole = [{ x: 30, y: 20 }, { x: 70, y: 20 }, { x: 70, y: 60 }, { x: 30, y: 60 }];
const cut = eda.sys_Math.subtract(rect, hole);
console.log('挖孔后多边形组的周长:', eda.sys_Math.calculatePerimeter(cut));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19