ncollide3d/bounding_volume/
bounding_sphere_utils.rs

1use crate::math::Point;
2use crate::utils;
3use na::{self, RealField};
4
5/// Computes the bounding sphere of a set of point, given its center.
6// FIXME: return a bounding sphere?
7#[inline]
8pub fn point_cloud_bounding_sphere_with_center<N: RealField + Copy>(
9    pts: &[Point<N>],
10    center: Point<N>,
11) -> (Point<N>, N) {
12    let mut sqradius = na::zero();
13
14    for pt in pts.iter() {
15        let distance_squared = na::distance_squared(pt, &center);
16
17        if distance_squared > sqradius {
18            sqradius = distance_squared
19        }
20    }
21
22    (center, sqradius.sqrt())
23}
24
25/// Computes a bounding sphere of the specified set of point.
26// FIXME: return a bounding sphere?
27#[inline]
28pub fn point_cloud_bounding_sphere<N: RealField + Copy>(pts: &[Point<N>]) -> (Point<N>, N) {
29    point_cloud_bounding_sphere_with_center(pts, utils::center(pts))
30}