Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef _GMTL_LINESEGOPS_H_
00007 #define _GMTL_LINESEGOPS_H_
00008
00009 #include <gmtl/LineSeg.h>
00010 #include <gmtl/RayOps.h>
00011
00012 namespace gmtl {
00013
00022 template< class DATA_TYPE >
00023 Point<DATA_TYPE, 3> findNearestPt( const LineSeg<DATA_TYPE>& lineseg,
00024 const Point<DATA_TYPE, 3>& pt )
00025 {
00026
00027 return ( lineseg.mOrigin + lineseg.mDir *
00028 dot(pt - lineseg.mOrigin, lineseg.mDir) / lengthSquared(lineseg.mDir) );
00029 }
00030
00039 template< class DATA_TYPE >
00040 inline DATA_TYPE distance( const LineSeg<DATA_TYPE>& lineseg,
00041 const Point<DATA_TYPE, 3>& pt )
00042 {
00043 return gmtl::length(gmtl::Vec<DATA_TYPE, 3>(pt - findNearestPt(lineseg, pt)));
00044 }
00045
00054 template< class DATA_TYPE >
00055 inline DATA_TYPE distanceSquared( const LineSeg<DATA_TYPE>& lineseg,
00056 const Point<DATA_TYPE, 3>& pt )
00057 {
00058 return gmtl::lengthSquared(gmtl::Vec<DATA_TYPE, 3>(pt - findNearestPt(lineseg, pt)));
00059 }
00060
00061
00062 }
00063 #endif