diff --git a/vcg/space/triangle3.h b/vcg/space/triangle3.h index bd7a6097..0d418b96 100644 --- a/vcg/space/triangle3.h +++ b/vcg/space/triangle3.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.7 2006/03/01 15:35:09 pietroni +compiled InterspolationParameters function + Revision 1.6 2006/01/22 10:00:56 cignoni Very Important Change: Area->DoubleArea (and no more Area function) @@ -48,6 +51,8 @@ Initial commit #define __VCG_TRIANGLE3 #include +#include +#include namespace vcg { @@ -283,6 +288,48 @@ typename TriangleType::ScalarType Perimeter(const TriangleType &t) Distance(t.P(2),t.P(0)); } +template +void PointDistance(const TriangleType &t, + typename TriangleType::CoordType & q, + typename TriangleType::ScalarType & dist, + typename TriangleType::CoordType & p ) +{ + typedef typename TriangleType::CoordType CoordType; + typedef typename TriangleType::ScalarType ScalarType; + + CoordType clos[4]; + ScalarType distv[4]; + + ///find distance on the plane + vcg::Plane3 plane; + plane.Init(t.P(0),t.P(1),t.P(2)); + clos[0]=plane.Projection(q); + distv[0]=(clos[0]-p).Norm(); + + //distance from the edges + vcg::Segment3 e0=vcg::Segment3(t.P(0),t.P(1)); + vcg::Segment3 e1=vcg::Segment3(t.P(1),t.P(2)); + vcg::Segment3 e2=vcg::Segment3(t.P(2),t.P(0)); + clos[1]=ClosestPoint( e0, q); + clos[2]=ClosestPoint( e1, q); + clos[3]=ClosestPoint( e2, q); + + distv[1]=(clos[1]-p).Norm(); + distv[2]=(clos[2]-p).Norm(); + distv[3]=(clos[3]-p).Norm(); + int min=0; + + ///find minimum distance + for (int i=1;i<4;i++) + { + if (distv[i]