Expand description
§use-rigidbody
Rigid-body mass properties and scalar mechanics helpers for RustUse.
§Install
[dependencies]
use-rigidbody = "0.0.1"§Foundation
use-rigidbody provides small f64-first helpers for scalar rigid-body mechanics primitives:
mass properties, center of mass, moments of inertia, kinetic energy, angular momentum, simple
impulse response, and small rigid-body state helpers.
Inputs are expected to be SI-style numeric values:
- kilograms for mass
- meters for position, radius, length, and distance
- meters per second for velocity
- radians for angle
- radians per second for angular velocity
- kilogram square meters for moment of inertia
- kilogram meters per second for linear momentum
- kilogram square meters per second for angular momentum
- joules for kinetic energy
- newton-seconds for impulse
Vector mechanics should compose with use-vector.
Simulation loops belong in top-level use-simulation.
Collision-specific helpers belong in use-collision.
Rotation-specific helpers belong in use-rotation.
Torque-specific helpers belong in use-torque.
§Example
use use_rigidbody::{MassProperties, RigidBody1D, total_kinetic_energy};
let props = MassProperties::solid_sphere(5.0, 2.0).unwrap();
let body = RigidBody1D::new(props, 10.0, 3.0, 1.0, 5.0).unwrap();
assert_eq!(body.linear_momentum(), Some(15.0));
assert_eq!(body.rotational_kinetic_energy(), Some(100.0));
assert_eq!(total_kinetic_energy(5.0, 3.0, 8.0, 5.0), Some(122.5));§When to use directly
Choose use-rigidbody when you need small, reusable scalar helpers for rigid-body mass
properties, inertia, momentum, kinetic energy, and simple kinematic state updates.
§Scope
- APIs stay
f64-first and focus on scalar rigid-body mechanics primitives. - This crate is not a physics engine, collision detector, contact solver, constraint solver, game physics package, or simulation framework.
- Vector rigid-body dynamics, joints, broad phase, narrow phase, and simulation loops are out of scope.
§Status
use-rigidbody is a pre-1.0 crate with a deliberately small API.
Scalar rigid-body mechanics helpers.
Modules§
- prelude
- Convenient re-exports for the public rigid-body helpers.
Structs§
- Mass
Properties - Mass and rotational inertia for a scalar rigid body.
- Rigid
Body1D - A one-dimensional rigid body with scalar translational and rotational state.
Functions§
- angular_
impulse_ from_ angular_ velocity_ change - Computes angular impulse from an angular velocity change using
J = I(ω_final - ω_initial). - angular_
momentum - Computes angular momentum using
L = Iω. - angular_
velocity_ after_ angular_ impulse - Computes final angular velocity after an angular impulse using
ω_final = ω_initial + J / I. - center_
moment_ from_ parallel_ axis - Computes the center moment from a shifted moment using
I_cm = I - md². - center_
of_ mass_ 1d - Computes the one-dimensional center of mass using
x_cm = Σ(m_i * x_i) / Σm_i. - combined_
mass - Computes the sum of non-negative masses.
- hollow_
sphere_ moment_ of_ inertia - Computes hollow-sphere moment of inertia using
I = (2 / 3)mr². - impulse_
from_ velocity_ change - Computes impulse from a velocity change using
J = m(v_final - v_initial). - linear_
kinetic_ energy - Computes translational kinetic energy using
KE = 0.5mv². - linear_
momentum - Computes linear momentum using
p = mv. - parallel_
axis_ moment_ of_ inertia - Applies the parallel-axis theorem using
I = I_cm + md². - point_
mass_ moment_ of_ inertia - Computes point-mass moment of inertia using
I = mr². - reduced_
mass - Computes reduced mass using
μ = (m1 * m2) / (m1 + m2). - rod_
moment_ of_ inertia_ about_ center - Computes rod moment of inertia about its center using
I = (1 / 12)mL². - rod_
moment_ of_ inertia_ about_ end - Computes rod moment of inertia about one end using
I = (1 / 3)mL². - rotational_
kinetic_ energy - Computes rotational kinetic energy using
KE_rot = 0.5Iω². - solid_
disk_ moment_ of_ inertia - Computes solid-disk moment of inertia using
I = 0.5mr². - solid_
sphere_ moment_ of_ inertia - Computes solid-sphere moment of inertia using
I = (2 / 5)mr². - thin_
ring_ moment_ of_ inertia - Computes thin-ring moment of inertia using
I = mr². - total_
kinetic_ energy - Computes total kinetic energy using
KE_total = 0.5mv² + 0.5Iω². - velocity_
after_ impulse - Computes final velocity after an impulse using
v_final = v_initial + J / m.