{-
Polar coordinate to Cartesian coordinate:
(r, theta) ==> (r*sin(theta), r*cos(theta))
regularPolygon of n sides ==> theta = 360 degrees / n
/| angle = theta / 2
r / | ==> sin (theta/2) = (s/2) / r
/__| ==> r = s / (2 * sin(theta/2))
s/2
-}
regularPolygon :: Int -> Side -> Shape
-- regularPolygon n s = Polygon $ map vertexAtAngle [0, theta .. 360]
regularPolygon n s = Polygon $ map vertexAtAngle (take n [0, theta ..])
where
intToFloat n = fromInteger (toInteger n)
degreeToRadian angle = angle * pi / 180
theta = 360 / (intToFloat n)
r = s / (2 * sin (degreeToRadian (theta / 2)))
vertexAtAngle angle = (r * cos (degreeToRadian angle), r * sin (degreeToRadian angle))
This entry was posted
on Monday, May 14th, 2007 at 6:14 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.