Expand description
§use-relativity
Small special relativity scalar helpers for RustUse.
§Install
[dependencies]
use-relativity = "0.0.1"§Foundation
use-relativity provides small special relativity scalar helpers for Lorentz factor, time dilation,
length contraction, mass-energy relations, relativistic momentum, rapidity, velocity addition,
and simple longitudinal Doppler calculations.
Inputs are expected to be SI-style numeric values:
- meters per second for speed and velocity
- seconds for time
- meters for length
- kilograms for mass
- joules for energy
- kilogram meters per second for momentum
- hertz for frequency
Positive beta in the Doppler helpers means the source is approaching the observer.
This crate keeps SPEED_OF_LIGHT locally for convenience. Broader physical constants belong in the
top-level use-constants set.
Unit abstractions belong in the top-level use-units set.
§Example
use use_relativity::{RelativisticBody, SPEED_OF_LIGHT, beta, dilated_time, velocity_addition};
assert_eq!(beta(SPEED_OF_LIGHT * 0.5), Some(0.5));
assert!((dilated_time(10.0, SPEED_OF_LIGHT * 0.6).unwrap() - 12.5).abs() < 1.0e-12);
assert!((velocity_addition(SPEED_OF_LIGHT * 0.5, SPEED_OF_LIGHT * 0.5).unwrap()
- (SPEED_OF_LIGHT * 0.8))
.abs()
< 1.0e-3);
let body = RelativisticBody::new(1.0, SPEED_OF_LIGHT * 0.6).unwrap();
assert!(body.total_energy().unwrap() > body.rest_energy().unwrap());§When to use directly
Choose use-relativity when you need small scalar special relativity helpers without a full unit,
geometry, or simulation system.
§Scope
- APIs stay
f64-first and focus on scalar special relativity helpers. - General relativity, tensor calculus, curved spacetime, and numerical simulation are out of scope.
- Full constants systems and unit abstractions belong in
use-constantsanduse-units.
§Status
use-relativity is a pre-1.0 crate with a deliberately small API.
Small special relativity scalar helpers.
Modules§
- prelude
- Re-exports for ergonomic glob imports.
Structs§
- Relativistic
Body - A body with scalar rest mass and signed velocity.
Constants§
- SPEED_
OF_ LIGHT - Speed of light in vacuum, in meters per second.
Functions§
- beta
- Computes the dimensionless speed ratio
β = v / c. - beta_
from_ rapidity - Computes
β = tanh(φ)from rapidity. - contracted_
length - Computes contracted length
L = L0 / γfrom proper lengthL0. - dilated_
time - Computes dilated coordinate time
t = γτfrom proper timeτ. - doppler_
factor_ longitudinal_ from_ beta - Computes the longitudinal relativistic Doppler factor
D = sqrt((1 + β) / (1 - β)). - energy_
momentum_ relation - Computes total energy from rest mass and momentum using
E = sqrt((pc)² + (mc²)²). - is_
subluminal_ speed - Returns
truewhenspeedis finite, non-negative, and strictly less than the speed of light. - lorentz_
factor - Computes the Lorentz factor
γfrom a speed magnitude in meters per second. - lorentz_
factor_ from_ beta - Computes the Lorentz factor
γ = 1 / sqrt(1 - β²)from a non-negativebetamagnitude. - mass_
from_ rest_ energy - Computes rest mass
m = E0 / c²from rest energy in joules. - observed_
frequency_ longitudinal - Computes observed longitudinal Doppler-shifted frequency
f_observed = f_emitted * D. - proper_
length - Computes proper length
L0 = Lγfrom a contracted lengthL. - proper_
time - Computes proper time
τ = t / γfrom dilated coordinate timet. - rapidity_
from_ beta - Computes rapidity
φ = atanh(β)from a signedbeta. - relativistic_
kinetic_ energy - Computes relativistic kinetic energy
KE = (γ - 1)mc²in joules. - relativistic_
momentum - Computes relativistic momentum
p = γmv. - rest_
energy - Computes rest energy
E0 = mc²in joules. - rest_
mass_ from_ momentum_ speed - Computes rest mass from relativistic momentum and velocity using
m = p / (γv). - speed_
from_ beta - Computes the speed magnitude
v = βcin meters per second. - speed_
from_ rapidity - Computes signed velocity
v = c * tanh(φ)from rapidity. - total_
energy - Computes total relativistic energy
E = γmc²in joules. - velocity_
addition - Computes relativistic velocity addition
u = (v + w) / (1 + vw / c²).