HMath.Geometry.Primitives¶
Module index · Numerical conventions
Description
Checked distances, containment, intersections and primitive signed distance functions. Boundaries are included, rays return their nonnegative parameter (direction need not be normalized), and coincident/overlapping intersections are explicit. Metrics accept dimensions 1..16; discrete Jaccard uses sets.
On this page¶
| API | Purpose |
|---|---|
| Metric | Minkowski p must be finite and at least one. |
| Euclidean | Declaration and type contract below. |
| Manhattan | Declaration and type contract below. |
| Chebyshev | Declaration and type contract below. |
| Minkowski | Declaration and type contract below. |
| distance | Euclidean, L1, Linfinity, or scaled Lp distance. |
| cosineDistance | One minus cosine similarity; zero vectors are undefined. |
| hammingDistance | Number of unequal positions (not normalized). |
| jaccardDistance | Set Jaccard distance; two empty sets have distance zero. |
| hausdorffDistance | Symmetric Hausdorff distance on two nonempty finite clouds, at most 1024 each. |
| mahalanobisDistance | Mahalanobis distance using a checked symmetric positive-definite covariance. |
| pointLineDistance | Distance to an infinite line; a zero direction is an error. |
| pointSegmentDistance | Distance to a closed segment, including a zero-length segment. |
| pointPlaneDistance | Unsigned perpendicular plane distance. |
| orientation | Exact orientation of the represented finite Double coordinates. |
| incircle | Exact in-circle sign, orientation-independent: positive means inside. |
| polygonLocation | Simple polygon position, with boundary separate from interior. |
| triangleLocation | Triangle position using exact orientation signs. |
| sphereContains | Closed sphere containment. |
| boxContains | Closed axis-aligned box containment. |
| ellipseContains | Closed ellipse containment after rotation to its principal axes. |
| triangleBarycentric | Weights (a,b,c) summing to one; valid outside the triangle as well. |
| circumcenter | Circumcenter, obtained from exact rational perpendicular-bisector equations. |
| incenter | Incenter weighted by opposite side lengths. |
| Intersection2 | Two-dimensional intersection, with a coincident line or overlapping segment explicit. |
| NoIntersection | Declaration and type contract below. |
| IntersectionPoint | Declaration and type contract below. |
| OverlapSegment | Declaration and type contract below. |
| CoincidentLine | Declaration and type contract below. |
| segmentIntersection | Closed segment intersection with exact degeneracy predicates. |
| lineIntersection | Infinite-line intersection from origins and nonzero direction vectors. |
| linePlaneIntersection | Lineplane result: Nothing paralleldisjoint, Just Nothing coincident, Just (Just p) a unique intersection. |
| planeIntersection | Plane intersection: same nested convention as linePlaneIntersection, with the unique intersection represented by a line. |
| rayTriangle | Moller-Trumbore ray intersection; coplanar rays return Nothing because their hit set is not a unique transverse surface crossing. |
| rayBox | Slab intersection interval [entry,exit], clipped to the ray t>=0. |
| raySphere | Ray-sphere near/far nonnegative parameters; tangent gives equal roots. |
| CircleIntersection | Circle intersections: coincidence is distinct from disjointness and tangency. |
| DisjointCircles | Declaration and type contract below. |
| CoincidentCircles | Declaration and type contract below. |
| CirclePoints | Declaration and type contract below. |
| circleIntersection | Given two circles, return DisjointCircles, CoincidentCircles, or CirclePoints for their intersection. |
| triangleIntersection | Closed triangle overlap polygon, including isolated tangencies as vertices. |
| sphereSDF | Sphere signed distance (negative inside). |
| boxSDF | Axis-aligned box exact signed Euclidean distance in 1..16 dimensions. |
| obbSDF | Oriented box distance after validating its orthonormal axes. |
| capsuleSDF | Capsule distance from its closed axis minus radius. |
| cylinderSDF | Exact capped finite-cylinder signed distance. |
| coneSDF | Exact finite-cone distance by reducing to its radial/axial cross-section. |
Documentation
Metric
Minkowski p must be finite and at least one.
Instances
distance
distance :: Metric -> PointND -> PointND -> Either MathError Double Source #
Euclidean, L1, Linfinity, or scaled Lp distance.
cosineDistance
cosineDistance :: PointND -> PointND -> Either MathError Double Source #
One minus cosine similarity; zero vectors are undefined.
hammingDistance
hammingDistance :: Eq a => [a] -> [a] -> Either MathError Int Source #
Number of unequal positions (not normalized).
jaccardDistance
jaccardDistance :: Eq a => [a] -> [a] -> Either MathError Double Source #
Set Jaccard distance; two empty sets have distance zero.
hausdorffDistance
hausdorffDistance :: [PointND] -> [PointND] -> Either MathError Double Source #
Symmetric Hausdorff distance on two nonempty finite clouds, at most 1024 each.
mahalanobisDistance
mahalanobisDistance :: [[Double]] -> PointND -> PointND -> Either MathError Double Source #
Mahalanobis distance using a checked symmetric positive-definite covariance. A Cholesky triangular solve avoids an explicit inverse.
pointLineDistance
pointLineDistance :: PointND -> Line -> Either MathError Double Source #
Distance to an infinite line; a zero direction is an error.
pointSegmentDistance
pointSegmentDistance :: PointND -> Segment -> Either MathError Double Source #
Distance to a closed segment, including a zero-length segment.
pointPlaneDistance
pointPlaneDistance :: Point3 -> Plane -> Either MathError Double Source #
Unsigned perpendicular plane distance.
orientation
orientation :: Point2 -> Point2 -> Point2 -> Either MathError Orientation Source #
Exact orientation of the represented finite Double coordinates.
incircle
incircle :: Point2 -> Point2 -> Point2 -> Point2 -> Either MathError Ordering Source #
Exact in-circle sign, orientation-independent: positive means inside. A collinear defining triangle is rejected.
polygonLocation
polygonLocation :: Polygon -> Point2 -> Either MathError Location Source #
Simple polygon position, with boundary separate from interior.
triangleLocation
triangleLocation :: Triangle -> Point2 -> Either MathError Location Source #
Triangle position using exact orientation signs.
sphereContains
sphereContains :: Sphere -> Point3 -> Either MathError Bool Source #
Closed sphere containment.
boxContains
boxContains :: AABB -> PointND -> Either MathError Bool Source #
Closed axis-aligned box containment.
ellipseContains
ellipseContains :: Ellipse -> Point2 -> Either MathError Bool Source #
Closed ellipse containment after rotation to its principal axes.
triangleBarycentric
triangleBarycentric :: Triangle -> Point2 -> Either MathError [Double] Source #
Weights (a,b,c) summing to one; valid outside the triangle as well.
circumcenter
circumcenter :: Triangle -> Either MathError Point2 Source #
Circumcenter, obtained from exact rational perpendicular-bisector equations.
incenter
incenter :: Triangle -> Either MathError Point2 Source #
Incenter weighted by opposite side lengths.
Intersection2
data Intersection2 Source #
Two-dimensional intersection, with a coincident line or overlapping segment explicit.
Instances
| Show Intersection2 Source # | |
Defined in HMath.Geometry.Primitives Methods showsPrec :: Int -> Intersection2 -> ShowS # show :: Intersection2 -> String # showList :: [Intersection2] -> ShowS # | |
| Eq Intersection2 Source # | |
Defined in HMath.Geometry.Primitives Methods (==) :: Intersection2 -> Intersection2 -> Bool # (/=) :: Intersection2 -> Intersection2 -> Bool # | |
segmentIntersection
segmentIntersection :: Point2 -> Point2 -> Point2 -> Point2 -> Either MathError Intersection2 Source #
Closed segment intersection with exact degeneracy predicates.
lineIntersection
lineIntersection :: Point2 -> Point2 -> Point2 -> Point2 -> Either MathError Intersection2 Source #
Infinite-line intersection from origins and nonzero direction vectors.
linePlaneIntersection
linePlaneIntersection :: Line -> Plane -> Either MathError (Maybe (Maybe Point3)) Source #
Lineplane result: Nothing paralleldisjoint, Just Nothing coincident, Just (Just p) a unique intersection. The line must have dimension three.
planeIntersection
planeIntersection :: Plane -> Plane -> Either MathError (Maybe (Maybe Line)) Source #
Plane intersection: same nested convention as linePlaneIntersection, with the unique intersection represented by a line.
rayTriangle
rayTriangle :: Ray -> (Point3, Point3, Point3) -> Either MathError (Maybe Double) Source #
Moller-Trumbore ray intersection; coplanar rays return Nothing because their hit set is not a unique transverse surface crossing. Degenerate triangles fail.
rayBox
rayBox :: Ray -> AABB -> Either MathError (Maybe (Double, Double)) Source #
Slab intersection interval [entry,exit], clipped to the ray t>=0.
raySphere
raySphere :: Ray -> Sphere -> Either MathError (Maybe (Double, Double)) Source #
Ray-sphere near/far nonnegative parameters; tangent gives equal roots.
CircleIntersection
data CircleIntersection Source #
Circle intersections: coincidence is distinct from disjointness and tangency.
Constructors
| DisjointCircles | |
| CoincidentCircles | |
| CirclePoints [Point2] |
Instances
| Show CircleIntersection Source # | |
Defined in HMath.Geometry.Primitives Methods showsPrec :: Int -> CircleIntersection -> ShowS # show :: CircleIntersection -> String # showList :: [CircleIntersection] -> ShowS # | |
| Eq CircleIntersection Source # | |
Defined in HMath.Geometry.Primitives Methods (==) :: CircleIntersection -> CircleIntersection -> Bool # (/=) :: CircleIntersection -> CircleIntersection -> Bool # | |
circleIntersection
circleIntersection :: Circle -> Circle -> Either MathError CircleIntersection Source #
Given two circles, return DisjointCircles, CoincidentCircles, or CirclePoints for their intersection. Require valid finite centers and nonnegative bounded radii. Tangency yields one point; identical zero-radius circles yield their single center.
triangleIntersection
triangleIntersection :: Triangle -> Triangle -> Either MathError [Point2] Source #
Closed triangle overlap polygon, including isolated tangencies as vertices.
sphereSDF
sphereSDF :: Sphere -> Point3 -> Either MathError Double Source #
Sphere signed distance (negative inside).
boxSDF
boxSDF :: AABB -> PointND -> Either MathError Double Source #
Axis-aligned box exact signed Euclidean distance in 1..16 dimensions.
obbSDF
obbSDF :: OBB -> Point3 -> Either MathError Double Source #
Oriented box distance after validating its orthonormal axes.
capsuleSDF
capsuleSDF :: Capsule -> Point3 -> Either MathError Double Source #
Capsule distance from its closed axis minus radius.