SYS_Math.rotate() method
旋转多边形
签名
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
参数名
参数 | 类型 | 描述 |
|---|---|---|
polygon | 多边形 | |
angle | number | 旋转角度(角度制,正值为逆时针) |
centerX | number | (可选) 旋转中心 X 坐标,默认为质心 |
centerY | number | (可选) 旋转中心 Y 坐标,默认为质心 |
返回值
Array<ISYS_MathPoint>
旋转后的离散点数组
示例
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