Skip to main content

Crate use_collision

Crate use_collision 

Source
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§

prelude

Structs§

Collision1D
A one-dimensional collision configuration with two bodies and a restitution coefficient.
CollisionBody1D
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 true when 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.