added PolygonPointDistance and PolygonBox functions

This commit is contained in:
nico 2017-03-14 12:55:57 +01:00
parent 7674ae4061
commit 4e71e28535
1 changed files with 42 additions and 10 deletions

View File

@ -28,6 +28,7 @@
#include <vcg/space/fitting3.h>
#include <vcg/space/point_matching.h>
#include <vcg/math/matrix33.h>
#include <vcg/space/distance3.h>
namespace vcg {
@ -530,5 +531,36 @@ typename PolygonType::ScalarType PolyAspectRatio(const PolygonType &F,
return(diff);
}
template<class PolygonType>
typename PolygonType::ScalarType PolygonPointDistance(const PolygonType &F,
const vcg::Point3<typename PolygonType::ScalarType> &pos)
{
typedef typename PolygonType::ScalarType ScalarType;
typedef typename PolygonType::CoordType CoordType;
ScalarType minD=std::numeric_limits<ScalarType>::max();
CoordType bary=vcg::PolyBarycenter(F);
for (size_t j=0;j<F.VN();j++)
{
vcg::Triangle3<ScalarType> T(F.cP0(j),F.cP1(j),bary);
ScalarType dist;
CoordType closest;
vcg::TrianglePointDistance(T,pos,dist,closest);
if (dist>minD)continue;
minD=dist;
}
return minD;
}
template<class PolygonType>
vcg::Box3<typename PolygonType::ScalarType> PolygonBox(const PolygonType &F)
{
typedef typename PolygonType::ScalarType ScalarType;
vcg::Box3<ScalarType> bb;
for (size_t j=0;j<F.VN();j++)
bb.Add(F.V(j)->P());
return bb;
}
}
#endif // POLYGON_H