Expand description
§use-collision
One-dimensional collision, restitution, impulse, and kinetic-energy helpers for RustUse.
§Install
[dependencies]
use-collision = "0.0.1"§Foundation
use-collision provides small, dependency-free helpers for scalar one-dimensional collision calculations.
Inputs are expected to be SI-style numeric values:
- kilograms for mass
- meters per second for velocity
- kilogram meters per second for momentum
- joules for kinetic energy
- newton-seconds for impulse
The coefficient of restitution is modeled as a scalar in [0.0, 1.0].
§Example
use use_collision::{Collision1D, CollisionBody1D};
let body_a = CollisionBody1D::new(1.0, 1.0).unwrap();
let body_b = CollisionBody1D::new(1.0, -1.0).unwrap();
let collision = Collision1D::new(body_a, body_b, 1.0).unwrap();
assert_eq!(collision.final_velocities(), Some((-1.0, 1.0)));
assert_eq!(collision.kinetic_energy_loss(), Some(0.0));§When to use directly
Choose use-collision when you need small, reusable helpers for one-dimensional collision outcomes, restitution, collision impulse, and kinetic-energy changes.
§Scope
- The crate focuses on scalar collision relations, coefficient of restitution, kinetic-energy changes, and impulse.
- Momentum and broader impulse utilities belong in
use-momentum. - Vector operations belong in
use-vector. - Simulation loops belong in top-level
use-simulation. - Rigid-body engines, contact solvers, vector mechanics, and game-physics systems are out of scope.
§Status
use-collision is a pre-1.0 crate with a deliberately small API.
Scalar helpers for one-dimensional collisions.
Modules§
Structs§
- Collision1D
- A one-dimensional collision configuration with two bodies and a restitution coefficient.
- Collision
Body1D - A one-dimensional body with scalar mass and velocity.
Functions§
- coefficient_
of_ restitution - Computes the coefficient of restitution from approach and separation speeds.
- collision_
energy_ loss_ 1d - Computes the total kinetic energy lost in a one-dimensional collision.
- collision_
energy_ loss_ fraction_ 1d - Computes the fraction of kinetic energy lost in a one-dimensional collision.
- collision_
final_ velocities_ 1d - Computes the final velocities of a one-dimensional collision from masses, initial velocities, and a coefficient of restitution.
- collision_
impulse_ on_ a - Computes the collision impulse applied to body A.
- collision_
impulse_ on_ b - Computes the collision impulse applied to body B.
- collision_
impulses_ 1d - Computes the impulses on both bodies for a one-dimensional collision.
- elastic_
collision_ final_ velocities_ 1d - Computes the final velocities of a perfectly elastic one-dimensional collision.
- is_
perfectly_ elastic - Returns whether a valid restitution coefficient is effectively perfectly elastic.
- is_
perfectly_ inelastic - Returns whether a valid restitution coefficient is effectively perfectly inelastic.
- is_
valid_ restitution - Returns
truewhen a restitution coefficient is finite and within[0.0, 1.0]. - kinetic_
energy - Computes kinetic energy from mass and one-dimensional velocity.
- kinetic_
energy_ loss - Computes the kinetic energy lost between an initial and final state.
- kinetic_
energy_ loss_ fraction - Computes the fraction of kinetic energy lost between two states.
- perfectly_
inelastic_ collision_ final_ velocities_ 1d - Computes the final velocities of a perfectly inelastic one-dimensional collision.
- perfectly_
inelastic_ collision_ velocity_ 1d - Computes the shared final velocity of a perfectly inelastic one-dimensional collision.
- relative_
speed - Computes the relative speed between two one-dimensional bodies.
- relative_
velocity - Computes the signed relative velocity between two one-dimensional bodies.
- separation_
speed_ from_ restitution - Computes separation speed from an approach speed and restitution coefficient.
- total_
kinetic_ energy_ 1d - Computes the total kinetic energy of two one-dimensional bodies.