block by shancarter 1034db3e675f2d3814e6006cf31dbfdc

Calculating the relative angle difference between two vectors

Full Screen

Here are the math-y bits, courtesy of @ch402:

var a2 = Math.atan2(source.y, source.x);
var a1 = Math.atan2(compare.y, compare.x);
var sign = a1 > a2 ? 1 : -1;
var angle = a1 - a2;
var K = -sign * Math.PI * 2;
var angle = (Math.abs(K + angle) < Math.abs(angle))? K + angle : angle;

index.html