繁体   English   中英

Raphael.js如何找到最终点击和鼠标当前位置的坐标之间的度?

[英]Raphael.js how to find degrees between coordinates of last click and mouse current position?

当我在paper单击时,将位置存储在lastXlastY值中:

lastX = e.screenX;
lastY = e.screenY;

在mousemove上,我更新currentXcurrentY值:

currentX = e.screenX;
currentY = e.screenY;

我可以确定这两个坐标之间的度数吗? 我认为x线是0度。 但是,这里停止了我的科学。

在其他一些Google搜索之后:

var radian = Math.atan((currentY-lastY)/(currentX-lastX));
var degree = radian * (180/Math.PI);

假设原点是点(lastX, lastY) ,零度是正x轴,则到该点的度数(currentX, currentY)将是:

function degreesToPoint(origin, endP){
    if(typeof origin != typeof [] or typeof endP != typeof [])
        return false;
    else {
        var slope = {
            x: origin[0] - endP[0],
            y: origin[1] - endP[1]
        };
        var degrees = Math.atan(slope.y / slope.x) * 180 / Math.PI;
        if(slope.x < 0 && slope.y >= 0){
            degrees += 180;
        } else if (slope.x < 0 && slope.y < 0) {
            degrees -= 180;
        }
        return degrees;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM