I have the following JavaScript code to work out the angle between two points (clockwise). The code I have seems a bit "hacky" to me, as I have a while loop ensuring the number is not negative (to make the range 0-360), as well as I have to subtract 270 degrees to get it to work correctly. Is there a better way to do this?
this.angle = function(point)
{
var delta = point.subtract(this);
var aR = Math.atan2(delta.y, delta.x);
var aD = aR * (180 / Math.PI);
aD -= 270;
while (aD < 0)
{
aD += 360;
}
return aD;
};