2013-05-10 35 views

回答

0

假設原點是點(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; 
    } 
} 
0

一些其它的谷歌搜索後:

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

如果當前點位於該點的右側,這將不起作用 – PitaJ 2013-05-11 03:38:15

相關問題