| Crates.io | amari-relativistic |
| lib.rs | amari-relativistic |
| version | 0.17.0 |
| created_at | 2025-10-06 02:34:20.687967+00 |
| updated_at | 2026-01-11 22:35:14.206973+00 |
| description | Relativistic physics using geometric algebra for charged particle simulations |
| homepage | https://github.com/justinelliottcobb/Amari |
| repository | https://github.com/justinelliottcobb/Amari |
| max_upload_size | |
| id | 1869676 |
| size | 239,711 |
Relativistic physics using geometric algebra for spacetime calculations.
amari-relativistic implements relativistic physics using the spacetime algebra Cl(1,3), providing tools for special and general relativity calculations. The crate handles Lorentz transformations, geodesic integration, particle dynamics, and gravitational fields with optional high-precision arithmetic for spacecraft-grade calculations.
Add to your Cargo.toml:
[dependencies]
amari-relativistic = "0.12"
[dependencies]
# Default: std + phantom-types + high-precision
amari-relativistic = "0.12"
# With serialization
amari-relativistic = { version = "0.12", features = ["serde-support"] }
# Native high-precision (rug/GMP backend)
amari-relativistic = { version = "0.12", features = ["native-precision"] }
# WASM-compatible high-precision (dashu backend)
amari-relativistic = { version = "0.12", features = ["wasm-precision"] }
use amari_relativistic::prelude::*;
// Create a velocity (0.8c in the x-direction)
let velocity = Vector3::new(0.8, 0.0, 0.0);
// Create the corresponding Lorentz boost
let boost = LorentzBoost::from_velocity(&velocity);
// Transform a 4-vector
let event = FourVector::new(1.0, 0.0, 0.0, 0.0); // (t, x, y, z)
let boosted = boost.apply(&event);
use amari_relativistic::prelude::*;
// Create gravitational field (Earth)
let earth = schwarzschild::SchwarzschildMetric::earth();
let mut integrator = geodesic::GeodesicIntegrator::with_metric(Box::new(earth));
// Spacecraft at 400 km altitude
let altitude = 400e3;
let earth_radius = 6.371e6;
let position = Vector3::new(earth_radius + altitude, 0.0, 0.0);
let orbital_velocity = Vector3::new(0.0, 7.67e3, 0.0);
// Create particle
let mut spacecraft = particle::RelativisticParticle::new(
position,
orbital_velocity,
0.0, // charge
1000.0, // mass (kg)
0.0, // charge
)?;
// Propagate orbit
let trajectory = particle::propagate_relativistic(
&mut spacecraft,
&mut integrator,
5580.0, // orbital period (s)
60.0, // time step (s)
)?;
The Minkowski metric signature (+,-,-,-):
Boosts and rotations are represented as rotors:
Λ = exp(-φ/2 · e₀₁) // Boost in x-direction
R = exp(-θ/2 · e₁₂) // Rotation in xy-plane
Apply transformation via sandwich product:
v' = Λ v Λ†
For a mass M at the origin:
ds² = (1 - rs/r)dt² - (1 - rs/r)⁻¹dr² - r²dΩ²
where rs = 2GM/c² is the Schwarzschild radius.
Particle motion in curved spacetime:
d²xᵘ/dτ² + Γᵘᵥρ (dxᵥ/dτ)(dxρ/dτ) = 0
Spacetime 4-vectors:
let position = FourVector::new(t, x, y, z);
let momentum = FourVector::from_3momentum(mass, velocity);
Lorentz transformations as rotors:
let boost = LorentzBoost::from_velocity(&v);
let rotation = LorentzRotation::from_axis_angle(&axis, angle);
let combined = boost.compose(&rotation);
Gravitational field:
let earth = SchwarzschildMetric::earth();
let sun = SchwarzschildMetric::new(solar_mass);
let black_hole = SchwarzschildMetric::new(1e6 * solar_mass);
Particles in spacetime:
let particle = RelativisticParticle::new(
position, velocity, charge, mass, spin
)?;
| Module | Description |
|---|---|
lorentz |
Lorentz boosts and rotations |
geodesic |
Geodesic integration in curved spacetime |
schwarzschild |
Schwarzschild metric implementation |
particle |
Relativistic particle dynamics |
precision |
High-precision arithmetic types |
verified |
Phantom type verification |
| Backend | Use Case | Dependencies |
|---|---|---|
high-precision |
Default, WASM-compatible | dashu (pure Rust) |
native-precision |
Maximum performance | rug (GMP/MPFR) |
wasm-precision |
WebAssembly targets | dashu |
The crate provides standard physical constants:
use amari_relativistic::constants::*;
let c = SPEED_OF_LIGHT; // 299792458 m/s
let G = GRAVITATIONAL_CONSTANT; // 6.67430e-11 m³/(kg·s²)
let M_earth = EARTH_MASS; // 5.972e24 kg
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
This crate is part of the Amari mathematical computing library.