module Physics.Hpysics.BoundingSphere where import Physics.Hpysics.Types import Physics.Hpysics.Utils import Data.List canIntersect :: Shape -> Shape -> Bool canIntersect p1 p2 = let BoundingVol c1 r1 = boundingVol p1 BoundingVol c2 r2 = boundingVol p2 in distance c1 c2 < r1 + r2 constructBoundingSphere :: Shape -> Shape constructBoundingSphere p = p { boundingVol = BoundingVol zeroVector $ maximum [norm vertex | vertex <- vertices_v p] } -- | Given /unit/ vector ab, returns barycentric coordinates (wrt a,b) of -- boundary points of shape's BV. projectBV :: Vec -> Vec -> Shape -> (FloatType,FloatType) projectBV a b s = let BoundingVol c r = boundingVol s project = projectToLineLambda a b projectedRadius = r `scale` (b`sub`a) v1 = c `sub` projectedRadius v2 = c `add` projectedRadius in (project v1, project v2)