Name: Anonymous 2007-10-24 21:01
Help me /prog/, i'm stuck on exercise 2.2 of the haskell school of expressions.
Define a function regularPolygon :: Int -> Side -> Shape such that regularPolygon n s is a regular polygon with n sides, each of length s.
I've found a couple answers, but don't get them.
regularPolygon :: Int -> Side -> Shape
regularPolygon n s
= let angleinc = pi * 2 / fromIntegral n
radius = s * sin ((pi - angleinc) / 2) / sin angleinc
regularVerts 0 _ = []
regularVerts n angle = (radius * cos angle, radius * sin angle)
: regularVerts (n-1) (angle + angleinc)
in Polygon (regularVerts n 0)
Define a function regularPolygon :: Int -> Side -> Shape such that regularPolygon n s is a regular polygon with n sides, each of length s.
I've found a couple answers, but don't get them.
regularPolygon :: Int -> Side -> Shape
regularPolygon n s
= let angleinc = pi * 2 / fromIntegral n
radius = s * sin ((pi - angleinc) / 2) / sin angleinc
regularVerts 0 _ = []
regularVerts n angle = (radius * cos angle, radius * sin angle)
: regularVerts (n-1) (angle + angleinc)
in Polygon (regularVerts n 0)