Skip to content

Instantly share code, notes, and snippets.

@jarek-foksa
Created February 24, 2013 17:41
Show Gist options
  • Select an option

  • Save jarek-foksa/5024758 to your computer and use it in GitHub Desktop.

Select an option

Save jarek-foksa/5024758 to your computer and use it in GitHub Desktop.
# The angle can be in range 0 - 360 and is measured clockwise starting from hour 12
# vector1 is the reference vector
getAngleBetweenTwoVectors: (vector1, vector2) ->
angleRad = atan2(vector2.y, vector2.x) - atan2(vector1.y, vector1.x)
angle = angleRad * (180/pi)
angle = 360 - abs(angle) if angle < 0
return angle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment