Clarify circle segment intersection

This commit is contained in:
2025-10-11 11:13:35 +01:00
parent 49fb982877
commit 4949d98789
4 changed files with 28 additions and 21 deletions
+20 -13
View File
@@ -7,7 +7,6 @@ module Geometry.Intersect where
import Control.Applicative
import Control.Lens
import Control.Monad
import Data.List
import Data.Maybe
import Geometry.Data
import Geometry.LHS
@@ -348,18 +347,26 @@ inSegArea a b c = param >= 0 && param <= dotV (b -.- a) (b -.- a)
where
param = dotV (b -.- a) (c -.- a)
-- I suspect that this may not be correct...
-- it should probably use closestPointOnSeg
intersectCircSeg :: Point2 -> Float -> Point2 -> Point2 -> [Point2]
intersectCircSeg c r a b
| y < 0 = []
| otherwise = nub $ filter (inSegArea a b) [d -.- v, d +.+ v]
intersectCircSeg :: Point2 -> Float -> Point2 -> Point2 -> (Maybe Point2,Maybe Point2)
intersectCircSeg c r s e = intersectCircLineAlong c r s e
& g
& each %~ f
where
d = closestPointOnLine a b c
x = dist d c
y = r ^ (2 :: Int) - x ^ (2 :: Int)
z = sqrt y
v = z *.* normalizeV (b -.- a)
f (Just x) | x >= 0 && x < 1 = Just $ s + x *^ (e - s)
f _ = Nothing
g Nothing = (Nothing,Nothing)
g (Just (x,y)) = (Just x,Just y)
--intersectCircSeg :: Point2 -> Float -> Point2 -> Point2 -> [Point2]
--intersectCircSeg c r a b
-- | y < 0 = []
-- | otherwise = nub $ filter (inSegArea a b) [d -.- v, d +.+ v]
-- where
-- d = closestPointOnLine a b c
-- x = dist d c
-- y = r ^ (2 :: Int) - x ^ (2 :: Int)
-- z = sqrt y
-- v = z *.* normalizeV (b -.- a)
intersectCircLineAlong :: Point2 -> Float -> Point2 -> Point2 -> Maybe (Float, Float)
intersectCircLineAlong p r x y = do
@@ -415,4 +422,4 @@ intersectCircSegTest c r x y =
z = r *.* vNormal (normalizeV x - y)
intersectCircSegFirst :: Point2 -> Float -> Point2 -> Point2 -> Maybe Point2
intersectCircSegFirst c r a = listToMaybe . intersectCircSeg c r a
intersectCircSegFirst c r a = fst . intersectCircSeg c r a