parry3d/query/contact/
contact_halfspace_support_map.rs

1use crate::math::{Isometry, Real};
2use crate::query::Contact;
3use crate::shape::{HalfSpace, SupportMap};
4
5/// Contact between a halfspace and a support-mapped shape (Cuboid, ConvexHull, etc.)
6pub fn contact_halfspace_support_map<G: ?Sized + SupportMap>(
7    pos12: &Isometry<Real>,
8    halfspace: &HalfSpace,
9    other: &G,
10    prediction: Real,
11) -> Option<Contact> {
12    let deepest = other.support_point_toward(pos12, &-halfspace.normal);
13    let distance = halfspace.normal.dot(&deepest.coords);
14
15    if distance <= prediction {
16        let point1 = deepest - halfspace.normal.into_inner() * distance;
17        let point2 = pos12.inverse_transform_point(&deepest);
18        let normal2 = pos12.inverse_transform_unit_vector(&-halfspace.normal);
19
20        Some(Contact::new(
21            point1,
22            point2,
23            halfspace.normal,
24            normal2,
25            distance,
26        ))
27    } else {
28        None
29    }
30}
31
32/// Contact between a support-mapped shape (Cuboid, ConvexHull, etc.) and a halfspace.
33pub fn contact_support_map_halfspace<G: ?Sized + SupportMap>(
34    pos12: &Isometry<Real>,
35    other: &G,
36    halfspace: &HalfSpace,
37    prediction: Real,
38) -> Option<Contact> {
39    contact_halfspace_support_map(pos12, halfspace, other, prediction).map(|c| c.flipped())
40}