SYS_Math.scale() method
Scale the polygon
Signature
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
Parameters
Parameter | Type | Description |
|---|---|---|
polygon | Polygon | |
scaleX | number | X direction scale ratio |
scaleY | number | (Optional) Y direction scale ratio, defaulting to the same as scaleX |
centerX | number | (Optional) X coordinate of the scaling center, defaulting to the centroid |
centerY | number | (Optional) Y coordinate of the scaling center, defaulting to the centroid |
Returns
Array<ISYS_MathPoint>
Array of discrete points after scaling
Example
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