{-
section 2.2
area (Polygon (v1:vs)) = polyArea vs
where polyArea :: [Vertex] -> Float
polyArea (v2:v3:vs’) = triArea v1 v2 v3 + polyArea(v3:vs’)
polyArea _ = 0
area (Polygon _) = 0
-}
area (Polygon (v1:vs)) = sum $ map (\(v2, v3) -> triArea v1 v2 v3) (zip vs (tail vs))
area (Polygon _) = 0
{- or replace "sum" by "foldr (+) 0" -}
This entry was posted
on Monday, May 21st, 2007 at 4:59 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.