/**
* 计算某一点旋转后的坐标点
* @param point
* @param degree
*/
export const calculateRotate = (point, degree) => {
let x = point.x * Math.cos(degree * Math.PI / 180) + point.y * Math.sin(degree * Math.PI / 180);
let y = -point.x * Math.sin(degree * Math.PI / 180) + point.y * Math.cos(degree * Math.PI / 180);
let relativeOriginPoint = {
x: Math.round(x * 100) / 100,
y: Math.round(y * 100) / 100
};
return relativeOriginPoint;
};
这里是按顺时针旋转计算的,假设中心的坐标为原点的。
若另一点不是原点,则可先将该点坐标转换为相对坐标计算,计算结果再加上中心点o点坐标。
参与计算的点坐标实际计算公式如下:
let x = (point.x-o.x)* Math.cos(degree * Math.PI / 180) + (point.y-o.y) * Math.sin(degree * Math.PI / 180);
let y = -(point.x-o.x)* Math.sin(degree * Math.PI / 180) + (point.y-o.y) * Math.cos(degree * Math.PI / 180);