Calculating angle in degrees of mouse movement

Use the atan2 function to get an angle in the full circle,

radians = Math.atan2(y2-y1,x2-x1);

Additionally, you may want to log the values of x1,x2,y1,y2 at the time of computation, it would be better to just have one place where the mouse position is traced. At the moment, you update the position (x2,y2,t2) every 10ms, but (x1,y1,t1) every time the mouse is moved. This can result in very unpredictable sample combinations.


Your calculations seem to be right, but the problem is that Math.asin(val) returns values in radians. Use the following function to convert to degrees:

Math.degrees = function(radians) {
    return radians*(180/Math.PI);
}

And then call Math.degrees(Math.asin(val)) and it should work!