Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_TRIANGLE_EXTRUSION_LENGTH_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_COMPUTE_TRIANGLE_EXTRUSION_LENGTH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace geometry
00015 {
00016
00038 template< typename vector3_type >
00039 typename vector3_type::value_type
00040 compute_triangle_extrusion_length(
00041 vector3_type const & p1
00042 , vector3_type const & p2
00043 , vector3_type const & p3
00044 , vector3_type const & n1
00045 , vector3_type const & n2
00046 , vector3_type const & n3
00047 , bool inward = false
00048 )
00049 {
00050 using std::min;
00051
00052 typedef typename vector3_type::value_type real_type;
00053 real_type extrusion = static_cast<real_type>(10e30);
00054
00055 unsigned int count = 0;
00056 real_type roots[ 2 ];
00057
00058 vector3_type a,b,c;
00059
00060 if(inward)
00061 {
00062 c = ( p2 - p1) % (p3 - p1 );
00063 b = ( p2 - p1) % (n1 - n3 ) + ( n1 - n2 ) % ( p3 - p1 );
00064 a = ( n1 - n2) % (n1 - n3 );
00065 }
00066 else
00067 {
00068 c = ( p2 - p1) % (p3 - p1 );
00069 b = ( p2 - p1) % (n3 - n1 ) + ( n2 - n1 ) % ( p3 - p1 );
00070 a = ( n2 - n1) % (n3 - n1 );
00071 }
00072
00073 real_type a1 = n1 * a;
00074 real_type b1 = n1 * b;
00075 real_type c1 = n1 * c;
00076 math::compute_polynomial_roots( c1, b1, a1, count, roots );
00077 for ( unsigned int i = 0;i < count;++i )
00078 if ( roots[ i ] > 0 )
00079 extrusion = min( roots[ i ], extrusion );
00080
00081 real_type a2 = n2 * a;
00082 real_type b2 = n2 * b;
00083 real_type c2 = n2 * c;
00084 math::compute_polynomial_roots( c2, b2, a2, count, roots );
00085 for ( unsigned int i = 0;i < count;++i )
00086 if ( roots[ i ] > 0 )
00087 extrusion = min( roots[ i ], extrusion );
00088
00089 real_type a3 = n3 * a;
00090 real_type b3 = n3 * b;
00091 real_type c3 = n3 * c;
00092 math::compute_polynomial_roots( c3, b3, a3, count, roots );
00093 for ( unsigned int i = 0;i < count;++i )
00094 if ( roots[ i ] > 0 )
00095 extrusion = min( roots[ i ], extrusion );
00096
00097 return extrusion;
00098 }
00099
00100 }
00101 }
00102
00103
00104 #endif