Skip to content

Instantly share code, notes, and snippets.

@gf3
Created December 11, 2011 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gf3/1462758 to your computer and use it in GitHub Desktop.
Save gf3/1462758 to your computer and use it in GitHub Desktop.
# ### Point.angleForCircle( origin, point ) -> Number
#
# * **origin** ( `Point` ): Origin of circle.
# * **point** ( `Point` ): Point to find angle of.
#
# Get the angle (in degrees) of a point for a given origin of a circle.
Point.angleForCircle = (origin, point) ->
x = origin.x - point.x
y = origin.y - point.y
r = Math.sqrt Math.pow(x, 2) + Math.pow(y, 2)
if y < 0 and x > 0
Raphael.deg Math.acos x / r
if x < 0 and y > 0
Raphael.deg Math.asin y / r
else
Raphael.deg Math.atan y / x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment