JS计算两条直线的夹角

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);

 

posted @ 2020-03-13 09:24  .why  阅读(4023)  评论(0编辑  收藏  举报
Live2D