Cleanup
This commit is contained in:
+39
-27
@@ -17,12 +17,20 @@ import Linear
|
||||
-- | If two lines intersect, return 'Just' that point.
|
||||
intersectLineLine :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectLineLine #-}
|
||||
intersectLineLine (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
| den == 0 = Nothing
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
where
|
||||
den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
||||
t' = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
--intersectLineLine a@(V2 x1 y1) b@(V2 x2 y2) c@(V2 x3 y3) d@(V2 x4 y4)
|
||||
intersectLineLine a b c d = do
|
||||
let den = detV (a-b) (c-d)
|
||||
guard $ den /= 0
|
||||
let t = detV (a-c) (c-d)
|
||||
return $ a + (t/den) *^ (b-a)
|
||||
-- | den == 0 = Nothing
|
||||
-- | otherwise = Just $ a + (t/den) *^ (b - a)
|
||||
---- | otherwise = Just $ V2 (x1 + (x2 - x1) * t / den) (y1 + (y2 - y1) * t / den)
|
||||
-- where
|
||||
-- den = detV (a-b) (c-d)
|
||||
---- den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
||||
-- t = detV (a-c) (c-d) --x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
---- t = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
|
||||
---- note that the second argument is a vector, not the second point of the line
|
||||
--intersectLinePlane :: Point3 -> Point3 -> Point3 -> Point3 -> Maybe Point3
|
||||
@@ -38,13 +46,17 @@ intersectLinePlaneAlong x y p n = do
|
||||
|
||||
-- this needs to be checked
|
||||
intersectSegPlane :: Point3 -> Point3 -> Point3 -> Point3 -> Maybe Point3
|
||||
intersectSegPlane sp ep p n = case dot v n of
|
||||
0 -> Nothing
|
||||
x -> case dot (p - sp) n / x of
|
||||
d | d >= 0 && d <= 1 -> Just $ sp + d *.*.* v
|
||||
_ -> Nothing
|
||||
where
|
||||
v = ep - sp
|
||||
intersectSegPlane x y p n = do
|
||||
d <- intersectLinePlaneAlong x y p n
|
||||
guard $ d >= 0 && d < 1
|
||||
return $ x + d *^ (y - x)
|
||||
--case dot v n of
|
||||
-- 0 -> Nothing
|
||||
-- x -> case dot (p - sp) n / x of
|
||||
-- d | d >= 0 && d <= 1 -> Just $ sp + d *.*.* v
|
||||
-- _ -> Nothing
|
||||
-- where
|
||||
-- v = ep - sp
|
||||
|
||||
intersectSegSurface ::
|
||||
Point3 ->
|
||||
@@ -112,20 +124,20 @@ intersectSegRay (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
t' = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
u' = (y1 - y2) * (x1 - x3) - (x1 - x2) * (y1 - y3)
|
||||
|
||||
-- | Similar to 'intersectSegLineFrom'', but this version is probably not correct...
|
||||
intersectSegLineext :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectSegLineext #-}
|
||||
intersectSegLineext (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
| den == 0 = Nothing
|
||||
| den > 0 && (t' < 0 || u' < den || t' > den) =
|
||||
Nothing
|
||||
| den < 0 && (t' > 0 || u' > - den || t' < den) =
|
||||
Nothing
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
where
|
||||
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)
|
||||
---- | Similar to 'intersectSegLineFrom'', but this version is probably not correct...
|
||||
--intersectSegLineext :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
--{-# INLINE intersectSegLineext #-}
|
||||
--intersectSegLineext (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
-- | den == 0 = Nothing
|
||||
-- | den > 0 && (t' < 0 || u' < den || t' > den) =
|
||||
-- Nothing
|
||||
-- | den < 0 && (t' > 0 || u' > - den || t' < den) =
|
||||
-- Nothing
|
||||
-- | otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
-- where
|
||||
-- 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)
|
||||
|
||||
{- | Intersect a segment with a line.
|
||||
the line intersects with the first endpoint of the segment
|
||||
|
||||
Reference in New Issue
Block a user