首页 > Web开发 > 详细

JS计算两条直线的夹角

时间:2020-03-13 12:28:02      阅读:539      评论:0      收藏:0      [点我收藏+]

技术分享图片

const getAngle = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
    const dot = x1 * x2 + y1 * y2
    const det = x1 * y2 - y1 * x2
    const angle = Math.atan2(det, dot) / Math.PI * 180
    return Math.round(angle + 360) % 360
}
const angle = getAngle({
    x: x1 - x3,
    y: y1 - y3,
}, {
    x: x2 - x3,
    y: y2 - y3,
});
console.log(angle);

 

JS计算两条直线的夹角

原文:https://www.cnblogs.com/zhigu/p/12484436.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!