How to write a javascript function that figures out the angle of two points? -
assuming straight line pointing north 0 degrees , goes 359. if given 2 points each x , y value, how find out "angle" makes between first point , second point? assuming (arctan2) function exists okay.
i have following:
var x = x2 - x1; var y = y2 - y1; var radian = arctan2(y, x); var degrees = radian * 180 / 3.14;
i seem getting "0 degrees" on right arrow , 270 pointing north instead of 0 degrees looking towards north.
if coordinate system have 0 degrees pointing up/north x comes first atan2 function:
var x = x2 - x1; var y = y2 - y1; var angledegrees = math.atan2(x, y) * 180 / math.pi; if (angledegrees < 0) angledegrees += 360; // force positive value
Comments
Post a Comment