Skip to main content

Module geometry

Module geometry 

Source
Expand description

Computational geometry: primitives, intersection, distance, convex hull, triangulation, polygon operations, GJK/EPA collision detection.

Structs§

Aabb2
2D axis-aligned bounding box.
Aabb3
3D axis-aligned bounding box.
Capsule
Capsule: cylinder with hemispherical caps.
Circle
Circle in 2D.
Obb3
Oriented bounding box.
Plane
Plane: normal·x + d = 0. Normal should be unit length.
Point2
2D point / vector.
Point3
3D point / vector.
Ray2
2D ray.
Ray3
3D ray.
Segment2
2D line segment.
Sphere
Sphere in 3D.
Triangle2
2D triangle.
Triangle3
3D triangle.

Enums§

Halfspace
Result of a halfspace test for AABB vs plane.

Functions§

aabb_aabb
AABB vs AABB overlap test.
aabb_plane
AABB vs plane halfspace classification.
capsule_capsule
Capsule vs capsule overlap.
convex_hull_2d
2D convex hull via Jarvis march (gift wrapping).
convex_hull_3d
3D convex hull via incremental Quickhull. Returns triangle face indices.
convex_polygon_area
Area of a convex polygon.
delaunay_2d
Bowyer-Watson Delaunay triangulation in 2D. Returns triangle index triples.
ear_clipping
Ear clipping triangulation for simple (non-self-intersecting) polygons. Returns triangle indices.
epa
EPA (Expanding Polytope Algorithm) — finds penetration depth and normal.
gjk
GJK distance test — returns true if shapes overlap.
gjk_closest
GJK closest points between two shapes. Returns (point_on_a, point_on_b, distance) or None if overlapping.
minkowski_sum
Minkowski sum of two convex polygons (CCW winding assumed).
obb_obb
OBB vs OBB — Separating Axis Theorem.
point_in_aabb
Point inside AABB.
point_in_convex_polygon
Point in convex polygon (hull assumed CCW).
point_in_obb
Point inside OBB.
point_in_triangle
Point in 2D triangle test.
point_to_aabb
Distance from point to AABB (0 if inside).
point_to_plane
Signed distance from point to plane.
point_to_segment
Closest point on a 3D segment to point p (treating segment as 3D using z=0 for Point2).
point_to_triangle
Distance from point to triangle in 3D.
polygon_area
Signed polygon area via Shoelace formula.
polygon_centroid
Polygon centroid.
polygon_is_convex
Test if polygon is convex.
polygon_winding
Winding number of polygon. Positive = CCW.
ray_aabb
Ray vs AABB — returns t of first positive intersection or None.
ray_capsule
Ray vs capsule.
ray_obb
Ray vs oriented bounding box.
ray_plane
Ray vs plane.
ray_sphere
Ray vs sphere.
ray_triangle
Ray vs triangle using Möller–Trumbore algorithm. Returns (t, u, v) — barycentric coords (w = 1 - u - v).
segment_segment_2d
2D segment-segment intersection. Returns intersection point or None.
segment_to_segment
2D segment-to-segment distance (embedding in 3D).
sphere_aabb
Sphere vs AABB overlap.
sphere_sphere
Sphere vs sphere overlap.
sphere_to_aabb
Distance from sphere to AABB surface. Negative means overlap.
sutherland_hodgman
Sutherland-Hodgman polygon clipping.
voronoi_2d
Compute approximate Voronoi diagram from Delaunay triangulation dual. Returns one polygon (as point list) per input point.