0

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

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

在 mousemove 上,我更新currentXcurrentY值:

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

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

4

2 回答 2

0

在其他一些谷歌搜索之后:

var radian = Math.atan((currentY-lastY)/(currentX-lastX));
var degree = radian * (180/Math.PI);
于 2013-05-10T23:36:39.707 回答
0

假设原点是 point (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;
    }
}
于 2013-05-11T03:37:09.550 回答