Correctly intersect lines and circles

This commit is contained in:
2021-12-15 11:16:56 +00:00
parent 9333d9497e
commit c5a211afce
4 changed files with 15 additions and 18 deletions
+7 -1
View File
@@ -251,10 +251,16 @@ orthogonalPointOnSeg a b p
| otherwise = Just $ a +.+ param *.* (normalizeV $ b -.- a)
where
param = closestPointOnLineParam a b p
inSegArea :: Point2 -> Point2 -> Point2 -> Bool
inSegArea a b c = param >= 0 && param <= dotV (b -.- a) (b -.- a)
where
param = dotV (b -.- a) (c -.- a)
intersectCircSeg :: Point2 -> Float -> Point2 -> Point2 -> [Point2]
intersectCircSeg c r a b
| y < 0 = []
| otherwise = nub $ filter ( (< dist a b) . dist a ) [ d -.- v, d +.+ c ]
| otherwise = nub $ filter (inSegArea a b) [ d -.- v, d +.+ c ]
where
d = closestPointOnLine a b c
x = dist d c