See Exercises 2.4 and 5.1. Then:
area'' :: Shape -> Float
area'' (Polygon (v1:vs)) = if convex (Polygon (v1:vs))
then let areas = map ((v2, v3) -> triArea v1 v2 v3)
(zip vs (tail vs))
in foldl (+) 0 areas
else error "Non-convex polygon" |
area'' :: Shape -> Float
area'' (Polygon (v1:vs)) = if convex (Polygon (v1:vs))
then let areas = map ((v2, v3) -> triArea v1 v2 v3)
(zip vs (tail vs))
in foldl (+) 0 areas
else error "Non-convex polygon"
This entry was posted on Friday, August 3rd, 2007 at 10:37 pm and is filed under Uncategorized. 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.