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