ncollide3d/query/distance/
distance_plane_support_map.rs

1use crate::math::{Isometry, Point};
2use crate::shape::Plane;
3use crate::shape::SupportMap;
4use na::{self, RealField};
5
6/// Distance between a plane and a support-mapped shape.
7pub fn distance_plane_support_map<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
8    mplane: &Isometry<N>,
9    plane: &Plane<N>,
10    mother: &Isometry<N>,
11    other: &G,
12) -> N {
13    let plane_normal = mplane * plane.normal;
14    let plane_center = Point::from(mplane.translation.vector);
15    let deepest = other.support_point_toward(mother, &-plane_normal);
16
17    let distance = plane_normal.dot(&(plane_center - deepest));
18
19    if distance < na::zero() {
20        -distance
21    } else {
22        na::zero()
23    }
24}
25
26/// Distance between a support-mapped shape and a plane.
27pub fn distance_support_map_plane<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
28    mother: &Isometry<N>,
29    other: &G,
30    mplane: &Isometry<N>,
31    plane: &Plane<N>,
32) -> N {
33    distance_plane_support_map(mplane, plane, mother, other)
34}