Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created February 14, 2015 21:03
Show Gist options
  • Select an option

  • Save TimSC/33e9b43a8e976564fb3c to your computer and use it in GitHub Desktop.

Select an option

Save TimSC/33e9b43a8e976564fb3c to your computer and use it in GitHub Desktop.
Difference between two angles
function relativeBearing(b1Rad, b2Rad)
{
b1y = Math.cos(b1Rad);
b1x = Math.sin(b1Rad);
b2y = Math.cos(b2Rad);
b2x = Math.sin(b2Rad);
crossp = b1y * b2x - b2y * b1x;
dotp = b1x * b2x + b1y * b2y;
if(crossp > 0.)
return Math.acos(dotp);
return -Math.acos(dotp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment