From b87832a022100332b90f8f01d4a34d252254d196 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Mon, 7 Apr 2014 06:30:30 +0000 Subject: [PATCH] added PlanePointSquaredDistance function --- vcg/space/distance3.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/vcg/space/distance3.h b/vcg/space/distance3.h index 99ea2e85..89bc638b 100644 --- a/vcg/space/distance3.h +++ b/vcg/space/distance3.h @@ -124,6 +124,41 @@ void SphereSphereDistance(const Sphere3 &sphere0, return dist; } +/* +* Computes the minimum squared distance between a between a point and a plane +* @param[in] pl The input line +* @param[in] p The input point +* @param[out] closest The closest point +* @param[out] dist The squared distance +*/ +template +void PlanePointSquaredDistance(const vcg::Plane3 &Pl, + const Point3 &p, + Point3 &closest, + ScalarType &dist) +{ + closest=Pl.Projection(p); + dist= (closest - p).SquaredNorm(); +} + + +/* +* Computes the minimum squared distance between a between a point and a plane +* @param[in] pl The input line +* @param[in] p The input point +* @param[out] closest The closest point +* @param[out] dist The squared distance +*/ +template +ScalarType PlanePointSquaredDistance(const vcg::Plane3 &Pl, + const Point3 &p) +{ + ScalarType dist; + vcg::Point3 closest; + PlanePointSquaredDistance(Pl,p,closest,dist); + return (dist); +} + /* * Computes the minimum squared distance between a between a point and a line