SYS_Math.scale() method
缩放多边形
签名
typescript
function scale(
polygon: TSYS_MathPolygonInput,
scaleX: number,
scaleY?: number,
centerX?: number,
centerY?: number,
): Array<ISYS_MathPoint>;1
2
3
4
5
6
7
2
3
4
5
6
7
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形 | |
scaleX | number | X 方向缩放比例 |
scaleY | number | (可选) Y 方向缩放比例,默认与 scaleX 相同 |
centerX | number | (可选) 缩放中心 X 坐标,默认为质心 |
centerY | number | (可选) 缩放中心 Y 坐标,默认为质心 |
返回值
Array<ISYS_MathPoint>
缩放后的离散点数组
示例
javascript
// 1. 定义一个矩形焊区
const pad = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
// 2. 等比放大 1.5 倍:绕质心原地放大,面积变为 2.25 倍
const enlarged = eda.sys_Math.scale(pad, 1.5);
console.log('放大 1.5 倍后的顶点:', JSON.stringify(enlarged));
console.log('放大后的面积:', eda.sys_Math.calculateArea(enlarged));
// 3. X、Y 采用不同比例:只在 X 方向拉宽 2 倍(绕质心,Y 不变)
const stretched = eda.sys_Math.scale(pad, 2, 1);
console.log('仅 X 方向放大 2 倍后的顶点:', JSON.stringify(stretched));
// 4. 指定缩放中心 (0, 0):各点坐标直接乘以比例
const fromOrigin = eda.sys_Math.scale(pad, 2, 2, 0, 0);
console.log('绕原点放大后的第一个点:', JSON.stringify(fromOrigin[0]));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15