码迷,mamicode.com
首页 > 编程语言 > 详细

javascript计算两条直线的夹角

时间:2019-01-26 18:51:32      阅读:542      评论:0      收藏:0      [点我收藏+]

标签:分享图片   git   代码   技术分享   jpg   turn   OLE   ext   console   

技术分享图片
计算上面两直线的夹角,代码如下

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 (angle + 360) % 360
}
const angle = getAngle({
    x: x1 - x3,
    y: y1 - y3,
}, {
    x: x2 - x3,
    y: y2 - y3,
});
console.log(angle);

javascript计算两条直线的夹角

标签:分享图片   git   代码   技术分享   jpg   turn   OLE   ext   console   

原文地址:https://www.cnblogs.com/ystrdy/p/10324466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!