Shoelace formula for polygonal area: Difference between revisions
→{{header|Haskell}}: Tidied in terms of bimap
(Shoelace formula for polygonal area in BASIC256) |
(→{{header|Haskell}}: Tidied in terms of bimap) |
||
Line 717:
=={{header|Haskell}}==
<lang Haskell>
main = print (shoelace [(3, 4), (5, 11), (12, 8), (9, 5), (5, 6)])▼
----------- SHOELACE FORMULA FOR POLYGONAL AREA ----------
-- The area of a polygon formed by the list of (x, y) coordinates.▼
-- the list of (x, y) coordinates.
shoelace :: [(Double, Double)] -> Double
shoelace =
let calcSums ((
in (/ 2)
. abs
abs . uncurry (-) . foldr calcSums (0, 0) . (<*>) zip (tail . cycle)</lang>▼
. uncurry (-)
. foldr calcSums (0, 0)
--------------------------- TEST -------------------------
main :: IO ()
main =
print $
{{out}}
<pre>30.0</pre>
|