Function evosim::contorl::update::get_mass_center
source · fn get_mass_center(mass_points: Vec<[f32; 3]>) -> Option<[f32; 2]>
Expand description
Calculates the mass center of a collection of points.
This function takes a vector of points, where each point is represented as an array of three f32
values.
The first two values are the x and y coordinates, and the third value is the mass at that point.
The function calculates the weighted sum of the coordinates based on the mass and divides by the total mass
to find the mass center.
Parameters
mass_points
: A vector of points, where each point is an array[x, y, mass]
.
Returns
Returns an Option
containing an array [x, y]
representing the mass center of the points.
If the input vector is empty or the total mass is zero, the function returns None
.