Geometry (83)

Geometric operations on 2D/3D/nD coordinate arrays.

alphaShape
2-D alpha shape → { triangles, edges }; keeps Delaunay triangles with circumradius ≤ 1/alpha and returns the boundary edges. Recovers concavities/holes (e.g. an annulus).
Syntax
alphaShape(points, alpha)
angle2D
Angle between vectors
Syntax
angle2D(v1, v2)
angle3D
Angle between vectors
Syntax
angle3D(v1, v2)
arcLength
Arc length of a parametric curve t ↦ [x, y] (adaptive quadrature of the central-difference speed) / curvature magnitude |x′y″ − y′x″| / (x′² + y′²)^{3/2} at t (central differences, step h = 1e-4)
Syntax
arcLength(curve, a, b)
Typesfunction
area
Area of a shape
Syntax
area(shape)
barycentricCoordinates
Containment test / barycentric coordinates [λa, λb, λc] of p
Syntax
barycentricCoordinates(p, a, b, c)
Typesnumber[]
boundingBox
Axis-aligned min/max per dimension: { min, max }
Syntax
boundingBox(points)
catmullRom
Point at t ∈ [0, 1] on the Catmull–Rom segment p1→p2; alpha 0.5 (centripetal, default), 0 uniform, 1 chordal
Syntax
catmullRom(p0, p1, p2, p3, t[, alpha])
Typesnumber[]
centroid
Centroid of a polygon
Syntax
centroid(polygon)
chebyshevDistance
L∞ distance
Syntax
chebyshevDistance(a, b)
closestPair
Closest pair in O(n log n): { i, j, distance }
Syntax
closestPair(points)
Typesnumber[][]
conj
Complex conjugate — negates the imaginary part
Syntax
conj(z)
Typesnumber, bigint, BigNumber, Complex, Array
convexHull
Convex hull, 2-D/3-D, structured result
Syntax
convexHull(points)
convexHull2D
2-D convex hull vertices (Andrew's monotone chain, counter-clockwise); the structured hull API is convexHull
Syntax
convexHull2D(points)
Typesnumber[][]
convexHull3D
3D convex hull via QuickHull (convexHull3DJS); returns CCW-oriented triangular faces as vertex-index triples
Syntax
convexHull3D(points)
coordinateTransform
Coordinate-system conversion
Syntax
coordinateTransform(point, from, to)
cross3D
3D cross / dot product
Syntax
cross3D(a, b)
curvature
Arc length of a parametric curve t ↦ [x, y] (adaptive quadrature of the central-difference speed) / curvature magnitude |x′y″ − y′x″| / (x′² + y′²)^{3/2} at t (central differences, step h = 1e-4)
Syntax
curvature(curve, t[, h])
Typesfunction
delaunay
2-D Delaunay triangulation → { simplices } (triangles as index triples); no point lies inside any triangle's circumcircle.
Syntax
delaunay(points)
delaunayTriangulation
Delaunay triangulation (JS)
Syntax
delaunayTriangulation(points)
distance
mathjs-style distance (factory layer)
Syntax
distance(...)
distance2D
Euclidean distance
Syntax
distance2D(a, b)
distance3D
Euclidean distance
Syntax
distance3D(a, b)
distanceMatrix
All-pairs Euclidean distance matrix (always computePool.distanceMatrix)
Syntax
distanceMatrix(points)
Accelparallel
distanceND
Euclidean distance
Syntax
distanceND(a, b)
distancePointToLine2D
Point-to-line distance
Syntax
distancePointToLine2D(point, lineA, lineB)
dot3D
3D cross / dot product
Syntax
dot3D(a, b)
douglasPeucker
Ramer–Douglas–Peucker polyline simplification
Syntax
douglasPeucker(points, epsilon)
Typesnumber[][]
earClipping
Triangulate a simple polygon; returns vertex-index triples into the input, oriented like it; throws on non-simple input
Syntax
earClipping(poly)
Typesnumber[][]
frechetDistance
Symmetric Hausdorff distance / discrete Fréchet distance between point sequences
Syntax
frechetDistance(p, q)
Typesnumber[][]
halfspaceIntersection
Vertices of the bounded polytope {x : A·x + b ≤ 0} from rows [a₁…a_d, b] (SciPy convention) in 2-D (counter-clockwise) or 3-D, plus vertex–facet incidences; needs a strictly interior point, throws if unbounded
Syntax
halfspaceIntersection(halfspaces, interiorPoint)
Typesnumber[][]
hausdorffDistance
Symmetric Hausdorff distance / discrete Fréchet distance between point sequences
Syntax
hausdorffDistance(a, b)
Typesnumber[][]
haversine
Great-circle distance between two lat/lon points (degrees); radius defaults to mean Earth radius in km
Syntax
haversine(lat1, lon1, lat2, lon2[, radius])
inCircle
For counter-clockwise (a, b, c): +1 if d is strictly inside the circumcircle, −1 outside, 0 on it
Syntax
inCircle(a, b, c, d)
Typesnumber[]
intersect
mathjs-style intersection (factory layer)
Syntax
intersect(...)
intersectLines2D
Line intersection
Syntax
intersectLines2D(p1, d1, p2, d2)
intersectSegments2D
Segment intersection
Syntax
intersectSegments2D(a1, a2, b1, b2)
kdTree
k-d tree + nearest query
Syntax
kdTree(points)
kdTreeKNN
Indices of the k nearest points to query (brute force)
Syntax
kdTreeKNN(points, query, k)
kdTreeNearest
k-d tree + nearest query
Syntax
kdTreeNearest(tree, query)
kdTreeRadius
Indices of all points within radius r of query (brute force)
Syntax
kdTreeRadius(points, query, r)
manhattanDistance
L1 distance
Syntax
manhattanDistance(a, b)
massProperties
Volume (area in 2-D), mass, centroid and inertia (tensor in 3-D, polar moment in 2-D) at uniform density (default 1); shapes sphere, box, capsule, convexPolyhedron, circle, rectangle, capsule2d, polygon
Syntax
massProperties(shape[, density])
Typesobject
minimumEnclosingCircle
Welzl smallest enclosing circle { center, radius }
Syntax
minimumEnclosingCircle(points)
Typesnumber[][]
minkowskiDistance
Lp distance
Syntax
minkowskiDistance(a, b, p)
minkowskiSum
Minkowski sum of two convex polygons (hull of the pairwise sums)
Syntax
minkowskiSum(a, b)
Typesnumber[][]
nearestNeighbor
Nearest-neighbour search (k-d tree, JS)
Syntax
nearestNeighbor(points, query)
orient2D
Orientation of the triangle: +1 counter-clockwise, −1 clockwise, 0 collinear
Syntax
orient2D(a, b, c)
Typesnumber[]
orient3D
Sign of det(b−a, c−a, d−a), the orientation of tetrahedron (a, b, c, d)
Syntax
orient3D(a, b, c, d)
Typesnumber[]
pointInPolygon
Ray-casting containment test
Syntax
pointInPolygon(point, polygon)
pointInTriangle
Containment test / barycentric coordinates [λa, λb, λc] of p
Syntax
pointInTriangle(p, a, b, c)
Typesnumber[]
polygonArea
Polygon area (shoelace)
Syntax
polygonArea(vertices)
polygonClip
Sutherland–Hodgman clipping of a polygon against a convex clip polygon
Syntax
polygonClip(subject, clipConvex)
Typesnumber[][]
polygonIsConvex
Convexity test for a polygon
Syntax
polygonIsConvex(poly)
Typesnumber[][]
polygonPerimeter
Polygon perimeter
Syntax
polygonPerimeter(vertices)
procrustes
Orthogonal Procrustes alignment mapping B onto A; returns { R, scale, disparity }
Syntax
procrustes(A, B)
projectVector
Vector projection
Syntax
projectVector(v, onto)
quaternionConjugate
Conjugate [w, −x, −y, −z]
Syntax
quaternionConjugate(q)
quaternionExp
Exponential eʷ·(cos|v|, sin|v|·v̂); inverse of quaternionLog
Syntax
quaternionExp(q)
quaternionFromAxisAngle
Unit quaternion for angle radians about axis; throws on a zero or non-finite axis
Syntax
quaternionFromAxisAngle(axis, angle)
quaternionFromEuler
Unit quaternion for ZYX intrinsic Euler angles (radians); inverse of quaternionToEuler
Syntax
quaternionFromEuler([roll, pitch, yaw])
quaternionFromRotationMatrix
Unit quaternion of a 3×3 rotation matrix (method of Shepperd); q and −q are one rotation
Syntax
quaternionFromRotationMatrix(m)
quaternionInverse
Multiplicative inverse conj(q) / |q|²
Syntax
quaternionInverse(q)
quaternionLog
Logarithm (ln|q|, θ·û); zero quaternion for the identity
Syntax
quaternionLog(q)
quaternionMultiply
Hamilton product of two quaternions
Syntax
quaternionMultiply(q1, q2)
quaternionNormalize
Unit-normalize a quaternion; throws on zero magnitude
Syntax
quaternionNormalize(q)
quaternionPow
Power exp(t·log(q)); scales a unit quaternion's rotation angle by t
Syntax
quaternionPow(q, t)
quaternionRotate
Rotate 3-vector v by the rotation of q (q·v·q⁻¹)
Syntax
quaternionRotate(q, v)
quaternionSlerp
Shortest-arc spherical interpolation; normalizes the inputs, returns a unit quaternion
Syntax
quaternionSlerp(q1, q2, t)
quaternionToAxisAngle
{ axis, angle } of the rotation: unit axis, angle in [0, π]; axis [1, 0, 0] at 0
Syntax
quaternionToAxisAngle(q)
quaternionToEuler
ZYX intrinsic Euler angles [roll, pitch, yaw] (radians); roll is 0 at gimbal lock
Syntax
quaternionToEuler(q)
quaternionToRotationMatrix
3×3 rotation matrix of q; the matrix acts on column vectors
Syntax
quaternionToRotationMatrix(q)
rayPlaneIntersect
Ray↔plane hit; returns { point, t } or null when the ray is parallel to the plane
Syntax
rayPlaneIntersect(origin, dir, planePoint, planeNormal)
rayTriangleIntersect
Möller–Trumbore ray↔triangle hit; returns { point, t } or null
Syntax
rayTriangleIntersect(origin, dir, v0, v1, v2)
reflectVector
Reflection across a plane
Syntax
reflectVector(v, normal)
rotateVector2D
Vector rotation
Syntax
rotateVector2D(v, angle)
rotateVector3D
Vector rotation
Syntax
rotateVector3D(v, axis, angle)
segmentSegmentClosest
Closest points between two 3-D segments; returns { point1, point2, distance } (distance is 0 when they intersect)
Syntax
segmentSegmentClosest(p1, p2, q1, q2)
slerp
Spherical linear interpolation between two vectors for t ∈ [0,1]; throws on zero-length or antipodal input
Syntax
slerp(v0, v1, t)
sphericalVoronoi
Voronoi diagram of points on a sphere (via the 3-D hull) → { vertices, regions, areas }; areas are geodesic cell areas summing to 4πr².
Syntax
sphericalVoronoi(points[, radius, center])
triangleArea
Triangle area
Syntax
triangleArea(a, b, c)
voronoi
2-D Voronoi diagram (dual of Delaunay) → { vertices, simplices, regions }; vertices are the Delaunay circumcenters, regions[i] the Voronoi vertices bounding generator i's cell.
Syntax
voronoi(points)
voronoiDiagram
Voronoi diagram inside bounds
Syntax
voronoiDiagram(points, bounds)