Work on gibs and chasms
This commit is contained in:
@@ -10,6 +10,9 @@ import Data.Maybe
|
||||
import Geometry.Data
|
||||
import Geometry.LHS
|
||||
import Geometry.Vector
|
||||
import Geometry.Vector3D
|
||||
import Linear.Metric
|
||||
import Control.Monad
|
||||
|
||||
-- | If two lines intersect, return 'Just' that point.
|
||||
intersectLineLine' :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
@@ -21,6 +24,33 @@ intersectLineLine' (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)
|
||||
|
||||
-- note that the second argument is a vector, not the second point of the line
|
||||
intersectLinePlane :: Point3 -> Point3 -> Point3 -> Point3 -> Maybe Point3
|
||||
intersectLinePlane l v p n = case dot v n of
|
||||
0 -> Nothing
|
||||
x -> Just $ l + ((dot (p - l) n) / x) *.*.* v
|
||||
|
||||
-- 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
|
||||
|
||||
intersectSegSurface :: Point3 -> Point3 -> Point3 -> Point3
|
||||
-> [(Point3,Point3)] -> Maybe Point3
|
||||
intersectSegSurface sp ep p n ss = do
|
||||
xp <- intersectSegPlane sp ep p n
|
||||
let f (a,b) = isNHS a b xp
|
||||
guard $ all f ss
|
||||
return xp
|
||||
|
||||
isNHS :: Point3 -> Point3 -> Point3 -> Bool
|
||||
isNHS p n x = 0 < dot n (x - p)
|
||||
|
||||
intersectSegSegErrorTest :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectSegSegErrorTest #-}
|
||||
intersectSegSegErrorTest a b c d = case intersectSegSeg a b c d of
|
||||
|
||||
Reference in New Issue
Block a user