Total circles area: Difference between revisions

Undone part of the changes in the Haskell analytical solution (because it didn't compile)
(Improved C entry (partially from Ledrug code))
(Undone part of the changes in the Haskell analytical solution (because it didn't compile))
Line 365:
<lang haskell>{-# LANGUAGE GeneralizedNewtypeDeriving #-}
 
import Data.List (sort, zip3)
 
data Vec = Vec Double Double
Line 463:
inAnyCircle arc = any (inCircle (arcMid arc, c)) cs
where (Arc c _) = arc
 
 
{-
Line 479 ⟶ 480:
joinArcs [] (x:xs) = joinArcs [x] xs
joinArcs a (x:xs)
| vDist ((arcEndarcStart (lasthead a)) arcStart(arcEnd (headlast a))) < 1e-4
= a : joinArcs [] (x:xs)
| vDist (arcEnd (last a)) (arcStart x) < 1e-4
Line 491 ⟶ 492:
area_ a e (arc:as) =
area_ (a + arcArea arc) (e ++ [arcCenter arc, arcEnd arc]) as
 
 
-- slice N-polygon into N-2 triangles
Line 496 ⟶ 498:
polylineArea (v:vs) = sum $ map triArea $ zip3 (repeat v) vs (tail vs)
where triArea (a,b,c) = ((b `vSub` a) `vCross` (c `vSub` b)) / 2
 
 
circlesArea :: [Circle] -> Double
Line 530 ⟶ 533:
main = print $ circlesArea circles</lang>
{{out}}
21.5650366038563955650366038564
 
=={{header|Perl 6}}==