Skip to content

Instantly share code, notes, and snippets.

@hellertime
Created August 12, 2012 00:17
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 hellertime/3328080 to your computer and use it in GitHub Desktop.
Save hellertime/3328080 to your computer and use it in GitHub Desktop.
Basic angle types
newtype Degree = Degree Float
newtype Radian = Radian Float
toRadian :: Degree -> Radian
toRadian deg = Radian $ (fromDegree deg) * (pi / 180)
fromRadian :: Radian -> Float
fromRadian (Radian x) = x
toDegree :: Radian -> Degree
toDegree rad = Degree $ (fromRadian rad) * (180 / pi)
fromDegree :: Degree -> Float
fromDegree (Degree x) = x
arclen :: Float -> Radian -> Float
arclen radius rad = (fromRadian rad / tau) * (tau / radius
where
tau = 2 * pi
sectorArea :: Float -> Radian -> Float
secrorArea radius rad = (fromRadian rad / tau) * (pi * $ radius ^ 2)
where
tau = 2 * pi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment