ncollide3d/query/proximity/
proximity_plane_support_map.rs
1use na::{self, RealField};
2
3use crate::math::{Isometry, Point};
4use crate::query::Proximity;
5use crate::shape::Plane;
6use crate::shape::SupportMap;
7
8pub fn proximity_plane_support_map<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
10 mplane: &Isometry<N>,
11 plane: &Plane<N>,
12 mother: &Isometry<N>,
13 other: &G,
14 margin: N,
15) -> Proximity {
16 assert!(
17 margin >= na::zero(),
18 "The proximity margin must be positive or null."
19 );
20
21 let plane_normal = mplane * plane.normal;
22 let plane_center = Point::from(mplane.translation.vector);
23 let deepest = other.support_point_toward(mother, &-plane_normal);
24
25 let distance = plane_normal.dot(&(plane_center - deepest));
26
27 if distance >= -margin {
28 if distance >= na::zero() {
29 Proximity::Intersecting
30 } else {
31 Proximity::WithinMargin
32 }
33 } else {
34 Proximity::Disjoint
35 }
36}
37
38pub fn proximity_support_map_plane<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
40 mother: &Isometry<N>,
41 other: &G,
42 mplane: &Isometry<N>,
43 plane: &Plane<N>,
44 margin: N,
45) -> Proximity {
46 proximity_plane_support_map(mplane, plane, mother, other, margin)
47}