• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

LineSegOps.h

Go to the documentation of this file.
00001 // GMTL is (C) Copyright 2001-2010 by Allen Bierbaum
00002 // Distributed under the GNU Lesser General Public License 2.1 with an
00003 // addendum covering inlined code. (See accompanying files LICENSE and
00004 // LICENSE.addendum or http://www.gnu.org/copyleft/lesser.txt)
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    // result = origin + dir * dot((pt-origin), dir)
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 } // namespace gmtl
00063 #endif

Generated on Sun Sep 19 2010 14:35:14 for GenericMathTemplateLibrary by  doxygen 1.7.1