Apollonius 🌌
Apollonius is a lightweight, high-performance N-dimensional geometry library for Rust. It provides the mathematical and structural foundations for physics engines, collision detection systems, and spatial simulations using const generics.
✨ Key Features
- N-Dimensional Support: Type-safe coordinates and vectors for 2D, 3D, and higher-dimensional spaces using Rust's
const generics. - Efficient Primitives:
- Hyperspheres: (Circles, Spheres, N-Spheres) with plane intersection and submerged volume ratio.
- Lines & Segments: Infinite lines and finite segments with parametric evaluation, projection, and full intersection APIs.
- Hyperplanes: Half-space queries, signed distance, and intersection with lines, segments, and hyperspheres.
- Triangles: N-dimensional triangles with centroid, area (Lagrange identity), and AABB.
- Broad-Phase Foundations: Native support for AABB (Axis-Aligned Bounding Boxes) with optimized overlap theorems.
- Unified Intersection Engine: A single
IntersectionResulttype covering:- None, Tangent(point), Secant(p1, p2), Collinear, Single(point) for point-like contacts.
- HalfSpacePenetration(depth) for hypersphere–hyperplane penetration.
- Point-to-Point Intersections: Line∩Line, Line∩Segment, Line∩Hypersphere, Line∩Hyperplane; Segment∩Segment, Segment∩Hypersphere, Segment∩Hyperplane, Segment∩Line; Hyperplane∩Line, Hyperplane∩Segment, Hyperplane∩Hypersphere; Hypersphere∩Line, Hypersphere∩Segment, Hypersphere∩Hyperplane.
- Numerical Stability: Robust floating-point classification via
classify_to_zeroandFloatSignto handle accumulation errors.
🛠 Technical Stack
- Language: Rust (Stable)
- Math Traits:
num-traitsfor generic support overf32andf64. - Core Philosophy: Minimal dependencies; core logic is independent of rendering or external physics frameworks.
📦 Installation
Add this to your Cargo.toml:
[]
= "0.0.6-alpha"
📖 Quick Example: Line–Hypersphere Intersection
use ;
let line = new;
let sphere = new;
match line.intersect_hypersphere
📖 Example: Hypersphere–Hyperplane (Tangent vs Penetration)
use ;
let sphere = new;
let plane = new;
match sphere.intersect_hyperplane
🛰 Roadmap
- N-dimensional Point & Vector algebra.
- Core primitives (Hypersphere, Line, Segment, Hyperplane, AABB, Triangle).
- AABB broad-phase overlap.
- Point-result intersections: Line/Segment with Line, Segment, Hypersphere, Hyperplane; Hyperplane with Line, Segment, Hypersphere; Hypersphere with Line, Segment, Hyperplane.
- Hypersphere–Hyperplane: tangent contact, half-space penetration,
submerged_ratio. - Documentation and doc tests.
- v0.0.7: Transformation matrices (affine: translation, scale, rotation; apply to Point/Vector).
- GJK (Gilbert–Johnson–Keerthi) for narrow-phase.
- Oriented Bounding Boxes (OBB).
- Spatial partitioning (BVH / quadtree).
📝 License
This project is licensed under the MIT License.
Developed with 🦀 by Mauricio Klainbard