pub fn compute_centroid<'a, T: BorrowedBuffer<'a>>(
point_cloud: &'a T,
) -> Vector3<f64>
Expand description
Computes the centroid for a given point cloud. The centroid is the point that has the same distance to all other points in the point cloud. Iterates over all points in the ‘point_cloud’.
§Panics
If the point_cloud is empty
§Examples
#[repr(C, packed)]
#[derive(PointType, Debug, Clone, Copy, bytemuck::AnyBitPattern, bytemuck::NoUninit)]
struct SimplePoint {
#[pasture(BUILTIN_POSITION_3D)]
pub position: Vector3<f64>,
#[pasture(BUILTIN_INTENSITY)]
pub intensity: u16,
}
let points: Vec<SimplePoint> = vec![
SimplePoint {
position: Vector3::new(1.0, 0.0, 0.0),
intensity: 42,
},
SimplePoint {
position: Vector3::new(0.0, 1.0, 0.0),
intensity: 84,
},
SimplePoint {
position: Vector3::new(1.0, 1.0, 0.0),
intensity: 84,
},
SimplePoint {
position: Vector3::new(-1.0, 0.0, 0.0),
intensity: 84,
},
];
let interleaved = points.into_iter().collect::<VectorBuffer>();
let centroid = compute_centroid(&interleaved);