ncollide3d/query/closest_points/
closest_points_plane_support_map.rs

1use na::{self, RealField};
2
3use crate::math::{Isometry, Point};
4use crate::query::ClosestPoints;
5use crate::shape::Plane;
6use crate::shape::SupportMap;
7
8/// Closest points between a plane and a support-mapped shape (Cuboid, ConvexHull, etc.)
9pub fn closest_points_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) -> ClosestPoints<N> {
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(mother, &-plane_normal);
24
25    let distance = plane_normal.dot(&(plane_center - deepest));
26
27    if distance >= -margin {
28        if distance >= na::zero() {
29            ClosestPoints::Intersecting
30        } else {
31            let c1 = deepest + *plane_normal * distance;
32            ClosestPoints::WithinMargin(c1, deepest)
33        }
34    } else {
35        ClosestPoints::Disjoint
36    }
37}
38
39/// Closest points between a support-mapped shape (Cuboid, ConvexHull, etc.) and a plane.
40pub fn closest_points_support_map_plane<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
41    mother: &Isometry<N>,
42    other: &G,
43    mplane: &Isometry<N>,
44    plane: &Plane<N>,
45    margin: N,
46) -> ClosestPoints<N> {
47    let mut res = closest_points_plane_support_map(mplane, plane, mother, other, margin);
48    res.flip();
49    res
50}