SYS_Math.rotate() method
Rotate the polygon
Signature
typescript
function rotate(
polygon: TSYS_MathPolygonInput,
angle: number,
centerX?: number,
centerY?: number,
): Array<ISYS_MathPoint>;1
2
3
4
5
6
2
3
4
5
6
Parameters
Parameter | Type | Description |
|---|---|---|
polygon | Polygon | |
angle | number | Rotation angle (in degrees, positive values are counterclockwise) |
centerX | number | (Optional) X coordinate of the rotation center, defaulting to the centroid |
centerY | number | (Optional) Y coordinate of the rotation center, defaulting to the centroid |
Returns
Array<ISYS_MathPoint>
Array of discrete points after rotation
Example
javascript
// 1. 定义一个矩形安装座
const mount = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
// 2. 不传中心:绕质心 (50, 40) 逆时针旋转 90 度,占位原地转身
const selfRotated = eda.sys_Math.rotate(mount, 90);
console.log('绕质心旋转后的顶点:', JSON.stringify(selfRotated));
// 3. 传中心参数:绕坐标原点 (0, 0) 旋转 90 度,图形整体公转
// 逆时针 90 度把 (x, y) 映射为 (-y, x)
const originRotated = eda.sys_Math.rotate(mount, 90, 0, 0);
console.log('绕原点旋转后的顶点:', JSON.stringify(originRotated));
// 4. 负角度顺时针旋转,与正角度互为逆变换
const back = eda.sys_Math.rotate(originRotated, -90, 0, 0);
console.log('再顺时针转回后的第一个点:', JSON.stringify(back[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