{"id":33,"date":"2007-07-29T23:49:36","date_gmt":"2007-07-30T06:49:36","guid":{"rendered":"http:\/\/www.elbeno.com\/haskell_soe_blog\/?p=33"},"modified":"2008-01-07T22:10:55","modified_gmt":"2008-01-08T06:10:55","slug":"exercise-84","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/haskell_soe_blog\/?p=33","title":{"rendered":"Exercise 8.4"},"content":{"rendered":"<p>The simplest way to allow vertices in clockwise or anticlockwise order is to define <tt>isRightOf<\/tt> analogously to <tt>isLeftOf<\/tt>, and combine them with a boolean expression.<\/p>\n<pre lang=\"haskell\">isLeftOf :: Coordinate -> Ray -> Bool\r\n(px,py) `isLeftOf` ((ax,ay), (bx,by))\r\n    = let (s,t) = (px-ax, py-ay)\r\n          (u,v) = (px-bx, py-by)\r\n      in s * v >= t * u\r\n\r\nisRightOf :: Coordinate -> Ray -> Bool\r\n(px,py) `isRightOf` ((ax,ay), (bx,by))\r\n    = let (s,t) = (px-ax, py-ay)\r\n          (u,v) = (px-bx, py-by)\r\n      in s * v <= t * u\r\n\r\n(Polygon pts) `containsS` p\r\n    = let leftOfList = map isLeftOfp (zip pts (tail pts ++ [head pts]))\r\n          isLeftOfp p' = isLeftOf p p'\r\n          rightOfList = map isRightOfp (zip pts (tail pts ++ [head pts]))\r\n          isRightOfp p' = isRightOf p p'\r\n      in and leftOfList || and rightOfList<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The simplest way to allow vertices in clockwise or anticlockwise order is to define isRightOf analogously to isLeftOf, and combine them with a boolean expression. isLeftOf :: Coordinate -> Ray -> Bool (px,py) `isLeftOf` ((ax,ay), (bx,by)) = let (s,t) = (px-ax, py-ay) (u,v) = (px-bx, py-by) in s * v >= t * u isRightOf [&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\/33"}],"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=33"}],"version-history":[{"count":0,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/haskell_soe_blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}