已知某一点坐标、线段长度和旋转角度,求另一点坐标

/**
 已知某一点坐标,旋转角度,长度,求另一点坐标
 */
export const calculateCoordinatePoint = (originPoint, degree, len) => {
    let rotate = (degree - 90 + 360) % 360; //这里是因为一开始以y轴下方为0度的
    let point = {
        x: len,
        y: 0
    };
 //计算某一点旋转后的坐标点,这里假设传入的点为原点
    let relativeOriginPoint = calculateRotate(point, rotate);
//计算相对坐标系的坐标
    let points = calculateCoordinateRelativePoint(originPoint, relativeOriginPoint);
    return points;
};
/**
 * 计算某一点旋转后的坐标点
 * @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;
};
/**
 * 计算相对坐标系的坐标
 */
export const calculateCoordinateRelativePoint = (origin, relativeOriginPoint) => {
    let x = relativeOriginPoint.x + origin.x;
    let y = relativeOriginPoint.y + origin.y;
    let points = {
        x: Math.round(x * 100) / 100,
        y: Math.round(y * 100) / 100
    };
    return points;
};

 

 

你可能感兴趣的:(JavaScript)