projection.h

Go to the documentation of this file.
00001 #ifndef VVELIB_GEOMETRY_PROJECTION_H
00002 #define VVELIB_GEOMETRY_PROJECTION_H
00003 
00010 #include <config.h>
00011 #include <geometry/geometry.h>
00012 
00013 namespace geometry
00014 {
00028   template <size_t N>
00029   util::Vector<N,double> projectPointOnLine(const util::Vector<N,double>& pt, const util::Vector<N,double>& u1, const util::Vector<N,double>& u2, bool strict=false)
00030   {
00031     util::Vector<N,double> u = u2-u1;
00032     util::Vector<N,double> pv = pt-u1;
00033     double l = util::norm(u);
00034     u /= l;
00035     double proj_val = pv*u;
00036     if(strict)
00037     {
00038       if(proj_val < 0)
00039         proj_val = 0;
00040       else if(proj_val > l)
00041         proj_val = l;
00042     }
00043     return u1 + u*proj_val;
00044   }
00045 
00058   Point3d projectPointOnTriangle(const Point3d& pt, const Point3d& p1, const Point3d& p2, const Point3d& p3, double &s, bool *in_triangle = 0);
00059 
00067   inline Point3d projectPointOnPlane(const Point3d& pos, const Point3d& p, const Point3d& n)
00068   {
00069     Point3d res = pos - ((pos-p)*n)*n;
00070     return res;
00071   }
00072 };
00073 
00074 #endif // VVELIB_GEOMETRY_PROJECTION_H
00075 
 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