parry3d/query/distance/
distance_ball_convex_polyhedron.rs

1use crate::math::{Isometry, Point, Real};
2use crate::shape::{Ball, Shape};
3
4/// Distance between a ball and a convex polyhedron.
5///
6/// This function panics if the input shape does not implement
7/// both the ConvexPolyhedron and PointQuery traits.
8#[inline]
9pub fn distance_ball_convex_polyhedron(
10    pos12: &Isometry<Real>,
11    ball1: &Ball,
12    shape2: &(impl Shape + ?Sized),
13) -> Real {
14    distance_convex_polyhedron_ball(&pos12.inverse(), shape2, ball1)
15}
16
17/// Distance between a convex polyhedron and a ball.
18///
19/// This function panics if the input shape does not implement
20/// both the ConvexPolyhedron and PointQuery traits.
21#[inline]
22pub fn distance_convex_polyhedron_ball(
23    pos12: &Isometry<Real>,
24    shape1: &(impl Shape + ?Sized),
25    ball2: &Ball,
26) -> Real {
27    let center2_1 = Point::from(pos12.translation.vector);
28    let proj = shape1.project_local_point(&center2_1, true);
29    (na::distance(&proj.point, &center2_1) - ball2.radius).max(0.0)
30}