ncollide3d/query/point/
point_plane.rs
1use crate::math::{Isometry, Point};
2use crate::query::{PointProjection, PointQuery};
3use crate::shape::{FeatureId, Plane};
4use na::{self, RealField};
5
6impl<N: RealField + Copy> PointQuery<N> for Plane<N> {
7 #[inline]
8 fn project_point(&self, m: &Isometry<N>, pt: &Point<N>, solid: bool) -> PointProjection<N> {
9 let ls_pt = m.inverse_transform_point(pt);
10 let d = self.normal.dot(&ls_pt.coords);
11
12 let inside = d <= na::zero();
13
14 if inside && solid {
15 PointProjection::new(true, *pt)
16 } else {
17 PointProjection::new(inside, *pt + (-*self.normal * d))
18 }
19 }
20
21 #[inline]
22 fn project_point_with_feature(
23 &self,
24 m: &Isometry<N>,
25 pt: &Point<N>,
26 ) -> (PointProjection<N>, FeatureId) {
27 (self.project_point(m, pt, false), FeatureId::Face(0))
28 }
29
30 #[inline]
31 fn distance_to_point(&self, m: &Isometry<N>, pt: &Point<N>, solid: bool) -> N {
32 let ls_pt = m.inverse_transform_point(pt);
33 let dist = self.normal.dot(&ls_pt.coords);
34
35 if dist < na::zero() && solid {
36 na::zero()
37 } else {
38 dist
40 }
41 }
42
43 #[inline]
44 fn contains_point(&self, m: &Isometry<N>, pt: &Point<N>) -> bool {
45 let ls_pt = m.inverse_transform_point(pt);
46
47 self.normal.dot(&ls_pt.coords) <= na::zero()
48 }
49}