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

/**
 已知某一点坐标,旋转角度,长度,求另一点坐标
 */
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;
};

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值