Skip to main content

center_of_mass_1d

Function center_of_mass_1d 

pub fn center_of_mass_1d(masses: &[f64], positions: &[f64]) -> Option<f64>
Expand description

Computes the one-dimensional center of mass using x_cm = Σ(m_i * x_i) / Σm_i.

Returns None when the slices have different lengths, are empty, contain invalid inputs, or when the computed result is not finite.

§Examples

use use_rigidbody::center_of_mass_1d;

assert_eq!(center_of_mass_1d(&[1.0, 3.0], &[0.0, 10.0]), Some(7.5));