Work towards convex partition of polygons

This commit is contained in:
2026-03-22 13:41:45 +00:00
parent 1a3d54e3b5
commit 505ced95bb
2 changed files with 24 additions and 7 deletions
+8
View File
@@ -151,6 +151,14 @@ convexHull :: [Point2] -> [Point2]
convexHull (x : y : z : xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b, a)) (x : y : z : xs)
convexHull _ = error "Tried to create the convex hull of two or fewer points"
-- assumes the points go "anticlockwise" around a non-self intersecting shape
convexPartition :: [Point2] -> [[Point2]]
convexPartition (x:y:z:[]) = [[x,y,z]]
convexPartition (x:y:z:xs)
| isLHS x y z = [x,y,z] : convexPartition (x:z:xs)
| otherwise = convexPartition (y:z:xs <> [x])
convexPartition _ = error "unexpected shape for convexPartition"
{- | Creates the convex hull of a set of points.
assumes no repetition of points: try nubbing!
-}