projection.cpp

00001 #include <geometry/projection.h>
00002 #include <geometry/intersection.h>
00003 
00004 namespace geometry
00005 {
00006 
00007   Point3d projectPointOnTriangle(const Point3d& pos, const Point3d& p1, const Point3d& p2, const Point3d& p3, double &s, bool *in_triangle)
00008   {
00009     Point3d u;
00010     if(geometry::pointInTriangle(u, s, pos, p1, p2, p3))
00011     {
00012       if(in_triangle) *in_triangle = true;
00013       return u;
00014     }
00015     Point3d p12 = geometry::projectPointOnLine(pos, p1, p2, true);
00016     Point3d p23 = geometry::projectPointOnLine(pos, p2, p3, true);
00017     Point3d p13 = geometry::projectPointOnLine(pos, p1, p3, true);
00018     double s12 = util::normsq(p12-pos);
00019     double s23 = util::normsq(p23-pos);
00020     double s13 = util::normsq(p13-pos);
00021     if(in_triangle) *in_triangle = false;
00022     if(s12 <= s23 and s12 <= s13)
00023     {
00024       s = s12;
00025       return p12;
00026     }
00027     if(s13 <= s23)
00028     {
00029       s = s13;
00030       return p13;
00031     }
00032     s = s23;
00033     return p23;
00034   }
00035 
00036 }
00037 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Fri May 31 15:37:50 2013 for VVE by  doxygen 1.6.3