00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_CLOSEST_POINTS_LINE_LINE_H 00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_CLOSEST_POINTS_LINE_LINE_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/math_precision.h> 00013 00014 namespace OpenTissue 00015 { 00016 namespace geometry 00017 { 00018 00031 template<typename vector3_type,typename real_type> 00032 void compute_closest_points_line_line( 00033 vector3_type const & pA 00034 , vector3_type const & uA 00035 , vector3_type const & pB 00036 , vector3_type const & uB 00037 , real_type & s 00038 , real_type & t 00039 ) 00040 { 00041 using std::fabs; 00042 00043 vector3_type r = pB - pA; 00044 real_type k = uA*uB; 00045 real_type q1 = uA*r; 00046 real_type q2 = -uB*r; 00047 real_type w = 1 - k*k; 00048 s = 0; t = 0; 00049 real_type epsilon = math::working_precision<real_type>(); 00050 if(fabs(w) > epsilon) 00051 { 00052 s = (q1 + k*q2)/w; 00053 t = (q2 + k*q1)/w; 00054 } 00055 } 00056 00057 } //End of namespace geometry 00058 } //End of namespace OpenTissue 00059 00060 // OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_CLOSEST_POINTS_LINE_LINE_H 00061 #endif