Clifford is a Rust library for Geometric Algebra (also known as Clifford Algebra), providing tools for 3D rotations, rigid body transformations, and computational geometry. If you're looking for an alternative to quaternions, rotation matrices, or homogeneous coordinates, Geometric Algebra offers a unified, intuitive approach.
Why Geometric Algebra?
Geometric Algebra (GA) unifies vectors, complex numbers, quaternions, and more into a single elegant framework. Instead of juggling matrices, quaternions, and Euler angles, GA gives you:
- Rotors: Like quaternions but they generalize to any dimension
- Motors: Rotation + translation in one composable object (no more 4x4 matrices!)
- Bivectors: Oriented planes that represent rotations naturally
- The geometric product: One operation that subsumes dot and cross products
If you work with robotics, computer graphics, physics simulations, or game development, GA simplifies your math while eliminating edge cases like gimbal lock.
Features
- 15 Specialized Algebras: Complex, Dual, Quaternion, Dual Quaternion, 2D/3D Euclidean, 2D/3D Projective (PGA), 2D/3D Conformal (CGA), 2D/3D Minkowski, 2D Elliptic, Hyperbolic
- Projective Geometric Algebra (PGA) for rigid body transforms (points, lines, planes, motors)
- Conformal Geometric Algebra (CGA) for circles, spheres, and conformal transformations
- Code Generation System (
clifford-codegen) for deriving optimized algebraic operations - Optimized 2D/3D types with zero-cost abstractions
- Interior Products and Projections for computing orthogonal components
- Seamless nalgebra integration for existing codebases
- Rerun visualization (
clifford-viz) for debugging and education - Generic over float types (f32, f64)
- Compile-time dimension checking
- Property-tested correctness with proptest
- WASM support for browser-based applications
Installation
[]
= "0.3"
Quick Start
3D Rotations with Rotors
Rotors are the GA equivalent of quaternions, but they arise naturally from the geometry:
use Transform;
use ;
use FRAC_PI_2;
// Create a rotation of 90 degrees in the xy-plane (around the z-axis)
let plane = unit_xy;
let rotor = from_angle_plane;
// Rotate a vector
let v = new;
let rotated = rotor.transform;
// x-axis is now pointing along y-axis
assert!;
assert!;
Rigid Transforms with PGA Motors
Motors combine rotation and translation into a single object that composes beautifully:
use ;
// Create a motor: translate by (1, 2, 3)
let motor = from_translation;
// Transform a point at the origin
let p = origin;
let transformed = motor.transform_point;
// The origin moved to (1, 2, 3)
assert!;
assert!;
assert!;
Compose motors for complex transforms - rotation then translation, or vice versa:
Motors can also transform lines and planes, making them ideal for robotics and graphics.
2D Geometry
The same patterns work in 2D:
use Transform;
use ;
use FRAC_PI_2;
let v = new;
let rotor = from_angle;
let rotated = rotor.transform;
assert!;
assert!;
Working with nalgebra
Already using nalgebra? Clifford integrates seamlessly:
use ;
use ;
// From nalgebra
let na_vec = new;
let cliff_vec = from;
// To nalgebra
let back_to_na: = cliff_vec.into;
// Quaternions too
let rotor = from_angle_plane;
let quat: = rotor.into;
Visualization with Rerun
Debug your geometric algebra computations visually:
This shows an animated bivector (parallelogram) with its Hodge dual vector, demonstrating how the wedge product works.
Module Structure
Specialized Algebras
| Module | Signature | Description |
|---|---|---|
specialized::complex |
Cl(0,1) | Complex numbers (i^2 = -1) |
specialized::dual |
Cl(0,0,1) | Dual numbers (epsilon^2 = 0) for automatic differentiation |
specialized::quaternion |
Cl(0,2) | Quaternions for 3D rotations |
specialized::dualquat |
- | Dual quaternions for rigid transforms |
specialized::euclidean::dim2 |
Cl(2,0) | 2D Euclidean: Vector, Bivector, Rotor |
specialized::euclidean::dim3 |
Cl(3,0) | 3D Euclidean: Vector, Bivector, Trivector, Rotor |
specialized::projective::dim2 |
Cl(2,0,1) | 2D PGA: Point, Line, Motor |
specialized::projective::dim3 |
Cl(3,0,1) | 3D PGA: Point, Line, Plane, Motor, Flector |
specialized::conformal::dim2 |
Cl(3,1) | 2D CGA: Points, circles, conformal transforms |
specialized::conformal::dim3 |
Cl(4,1) | 3D CGA: Points, spheres, circles, conformal transforms |
specialized::minkowski::dim2 |
Cl(1,1) | 2D Minkowski spacetime |
specialized::minkowski::dim3 |
Cl(1,2) | 3D Minkowski spacetime |
specialized::elliptic::dim2 |
Cl(2,0) + positive curvature | 2D elliptic/spherical geometry |
specialized::hyperbolic |
- | Hyperbolic numbers (j^2 = +1) |
Core Infrastructure
| Module | Description |
|---|---|
algebra |
Generic multivector for any metric signature |
signature |
Metric signatures (Euclidean, Minkowski, etc.) |
ops |
Algebraic operations (Wedge, Antiwedge, Sandwich, Transform, etc.) |
Cargo Features
| Feature | Description | Default |
|---|---|---|
serde |
Serialization/deserialization | Yes |
proptest-support |
Property-based testing strategies | Yes |
nalgebra-0_33 |
nalgebra 0.33.x conversions | Yes |
nalgebra-0_32 |
nalgebra 0.32.x conversions | No |
nalgebra-0_34 |
nalgebra 0.34.x conversions | No |
rerun-0_28 |
Rerun visualization integration | No |
Note: The nalgebra features are mutually exclusive. Enable only one.
Performance
Clifford is designed for performance:
- Specialized types use fixed-size arrays (no heap allocation)
- Operations are inlined and optimized by LLVM
- Benchmarks show competitive performance with hand-written quaternion code
Run benchmarks yourself:
Learning Resources
New to Geometric Algebra? These resources helped us:
- Geometric Algebra Primer - Jaap Suter's excellent introduction
- Let's Remove Quaternions from Every 3D Engine - Marc ten Bosch on why GA is better
- Siggraph 2019 GA Course - Video introduction
- bivector.net - Community resources and tools
Minimum Supported Rust Version
Clifford requires Rust 1.87.0 or later (edition 2024).
License
MIT License