Use some Linear library functions
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
{- Testing for and finding intersection points. -}
|
||||
module Geometry.Intersect where
|
||||
|
||||
import Linear
|
||||
import Control.Lens
|
||||
import Control.Applicative
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
@@ -11,7 +13,6 @@ 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.
|
||||
@@ -219,8 +220,8 @@ myIntersectLineLine a@(V2 ax _) b c@(V2 cx _) d
|
||||
Just 0 -> Nothing
|
||||
_ -> liftA2 V2 newx ((linGrad a b ^*^ newx) ^+^ axisInt a b)
|
||||
where
|
||||
(^-^) = liftA2 (-)
|
||||
(^+^) = liftA2 (+)
|
||||
-- (^-^) = liftA2 (-)
|
||||
-- (^+^) = liftA2 (+)
|
||||
(^/^) = liftA2 (/)
|
||||
(^*^) = liftA2 (*)
|
||||
newx = (axisInt c d ^-^ axisInt a b) ^/^ (linGrad a b ^-^ linGrad c d)
|
||||
@@ -348,8 +349,19 @@ intersectCircSeg c r a b
|
||||
z = sqrt y
|
||||
v = z *.* normalizeV (b -.- a)
|
||||
|
||||
intersectCylSeg :: Point3 -> Float -> Float -> Point3 -> Point3 -> Maybe Point3
|
||||
intersectCylSeg p r h x y = Nothing
|
||||
intersectCircLineAlong :: Point2 -> Float -> Point2 -> Point2 -> Maybe (Float, Float)
|
||||
intersectCircLineAlong p r x y = do
|
||||
let d = y - x
|
||||
f = p - x
|
||||
dis = (dot d f / dot d d) ** 2 + (dot f f - r ** 2)/dot d d
|
||||
guard $ dis > 0
|
||||
let a = dot d f / dot d d
|
||||
return (a - dis, a + dis)
|
||||
|
||||
intersectCylSeg :: Point3 -> Float -> Float -> Point3 -> Point3 -> Maybe (Point3, Point3)
|
||||
intersectCylSeg p r h x y = do
|
||||
(a,b) <- intersectCircLineAlong (p ^. _xy) r (x ^. _xy) (y ^. _xy)
|
||||
Nothing
|
||||
|
||||
intersectCircSegTest :: Point2 -> Float -> Point2 -> Point2 -> Bool
|
||||
intersectCircSegTest c r x y = intersectSegSegTest (c + z) (c - z) x y
|
||||
|
||||
Reference in New Issue
Block a user