Improve intersection test--fails sometimes
This commit is contained in:
@@ -5,6 +5,7 @@ Testing for and finding intersection points.
|
||||
module Geometry.Intersect
|
||||
where
|
||||
import Geometry.Data
|
||||
import Geometry.LHS
|
||||
import Control.Applicative
|
||||
|
||||
import Data.Maybe (isNothing)
|
||||
@@ -74,6 +75,30 @@ intersectSegLine' (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
den = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4)
|
||||
t' = (x1-x3)*(y3-y4) - (y1-y3)*(x3-x4)
|
||||
--u' = (y1-y2)*(x1-x3) - (x1-x2)*(y1-y3)
|
||||
-- | It is not always necessary to find a point of intersection, sometimes a
|
||||
-- test may suffice.
|
||||
intersectSegSegTest
|
||||
:: Point2
|
||||
-> Point2
|
||||
-> Point2
|
||||
-> Point2
|
||||
-> Bool
|
||||
{-# INLINE intersectSegSegTest #-}
|
||||
intersectSegSegTest a' b' c' d'
|
||||
= f a' b' c' d' && f c' d' a' b'
|
||||
where
|
||||
f a b c d = ( isLHS a b c && not (isLHS a b d) )
|
||||
|| ( not (isLHS a b c) && isLHS a b d )
|
||||
intersectSegSegPreTest
|
||||
:: Point2
|
||||
-> Point2
|
||||
-> Point2
|
||||
-> Point2
|
||||
-> Maybe Point2
|
||||
{-# INLINE intersectSegSegPreTest #-}
|
||||
intersectSegSegPreTest a b c d
|
||||
| intersectSegSegTest a b c d = myIntersectSegSeg a b c d
|
||||
| otherwise = Nothing
|
||||
-- | Due to floating point issues, 'intersectSegSeg'' is not always
|
||||
-- accurate---'myIntersectSegSeg'
|
||||
-- fixes at least some of
|
||||
|
||||
Reference in New Issue
Block a user