{"id":7,"date":"2007-07-24T22:27:08","date_gmt":"2007-07-25T05:27:08","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=7"},"modified":"2008-01-07T21:38:52","modified_gmt":"2008-01-08T05:38:52","slug":"exercise-22","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=7","title":{"rendered":"Exercise 2.2"},"content":{"rendered":"<p>There are several ways to solve this problem. I used the approach of rotating around the origin incrementing the angle by 2\u00cf\u20ac\/n each time. The radius of the figure is given by application of the sine rule to the isosceles triangle formed by two adjacent vertices and the origin.<\/p>\n<pre lang=\"haskell\">type Side = Float\r\n{-\r\nConstruct a regular polygon, given number of sides n and side length s.\r\n-}\r\nregularPolygon :: Int -> Side -> Shape\r\nregularPolygon n s\r\n    = let angleinc = pi * 2 \/ fromIntegral n\r\n          radius = s * sin ((pi - angleinc) \/ 2) \/ sin angleinc\r\n          regularVerts 0 _ = []\r\n          regularVerts n angle = (radius * cos angle, radius * sin angle)\r\n                                 : regularVerts (n-1) (angle + angleinc)\r\n      in Polygon (regularVerts n 0)<\/pre>\n<p>Note that the vertex list is in anticlockwise order. This is also the case with <a href=\"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=6\">Exercise 2.1<\/a>. Note also the use of <tt>fromIntegral<\/tt> to convert between types.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are several ways to solve this problem. I used the approach of rotating around the origin incrementing the angle by 2\u00cf\u20ac\/n each time. The radius of the figure is given by application of the sine rule to the isosceles triangle formed by two adjacent vertices and the origin. type Side = Float {- Construct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/7"}],"collection":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}