Skip to main content

angle between two points in javascript


//--------- to get angle between two points ---------
//---param---
//@x1,x2,y1,y2 : cordinates of 2 points
//@return: theta(value in degrees)
function getTanTheta(x1,y1,x2,y2)
{
var y = eval(y2)-eval(y1);
var x = eval(x2)-eval(x1);

if(y < 0) { y = -y;}
if(x < 0) { x = -x;}

//alert(y+'  '+x);
var tanTheta = y/x;
if(tanTheta < 0) { tanTheta = -x;}

tanTheta = roundNumber(tanTheta,3);
//alert(tanTheta);
return tanTheta;

}

Popular posts from this blog