Add function for cutting polygons
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
{- Testing for and finding intersection points. -}
|
||||
module Geometry.Intersect where
|
||||
|
||||
import Data.List (sortOn)
|
||||
import Control.Applicative
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
@@ -264,6 +265,14 @@ intersectSegPolyFirst a b xs = foldr (<|>) Nothing $ zipWith lineColl xs (tail x
|
||||
where
|
||||
lineColl = intersectSegSeg a b
|
||||
|
||||
-- orders intersecting points according to the line
|
||||
intersectLinePoly :: Point2 -> Point2 -> [Point2] -> [Point2]
|
||||
intersectLinePoly a b (p:ps) = sortOn (dotV (b - a))
|
||||
. catMaybes
|
||||
$ zipWith (\x y -> intersectSegLine x y a b) (p:ps) (ps ++[p])
|
||||
intersectLinePoly _ _ [] = error "intersectLinePoly empty polygon"
|
||||
|
||||
|
||||
{- | Given a line and a point return the point on the line closest to the
|
||||
point.
|
||||
-}
|
||||
|
||||
Reference in New Issue
Block a user