/* * missing in CGAL? */ squared_distance_t squaredDistancePointTriangle3D( const Point_3& p, const Triangle_3& abc ) { #if CGAL_VERSION_NR >= 1041001000 // >= 4.10 return CGAL::squared_distance(p, abc); #else Point_3 a = abc.vertex( 0 ); Point_3 b = abc.vertex( 1 ); Point_3 c = abc.vertex( 2 ); /* * project P on ABC plane as projP. */ Point_3 projP = Plane_3( a, b, c ).projection( p ); squared_distance_t dMin ; if ( abc.has_on( projP ) ) { // Is projP is in the triangle, return distance from P to its projection // on the plane dMin = CGAL::squared_distance( p, projP ) ; } else { // Else, the distance is the minimum from P to triangle sides dMin = CGAL::squared_distance( p, Segment_3( a,b ) ) ; dMin = std::min( dMin, CGAL::squared_distance( p, Segment_3( b,c ) ) ); dMin = std::min( dMin, CGAL::squared_distance( p, Segment_3( c,a ) ) ); } return dMin ; #endif }
squared_distance_t squaredDistanceSegmentTriangle3D( const Segment_3& sAB, const Triangle_3& tABC ) { typedef Kernel::FT squared_distance_t ; /* * If [sAsB] intersects the triangle (tA,tB,tC), distance is 0.0 */ if ( boost::none != CGAL::intersection( sAB, tABC ) ) { return 0.0 ; } /* * else, distance is the min of the following values : * - distance from sA to the Triangle * - distance from sB to the Triangle * - distance from sAB to the side of the Triangles */ squared_distance_t dMin = squaredDistancePointTriangle3D( sAB.vertex( 0 ), tABC ); dMin = std::min( dMin, squaredDistancePointTriangle3D( sAB.vertex( 1 ), tABC ) ); for ( int i = 0; i < 3; i++ ) { dMin = std::min( dMin, CGAL::squared_distance( sAB, Segment_3( tABC.vertex( i ), tABC.vertex( i+1 ) ) ) ) ; } return dMin ; }
void Viewer::drawFacet(const Triangle_3& t, const QColor& /*clr*/) { // disable lighting ::glDisable( GL_LIGHTING ); // disable depth buffer writing ::glDepthMask( GL_FALSE ); qglColor( m_colorFacet ); ::glBegin(GL_TRIANGLES); Point_3 p0 = t.vertex(0); Point_3 p1 = t.vertex(1); Point_3 p2 = t.vertex(2); ::glVertex3f( p0.x(), p0.y(), p0.z() ); ::glVertex3f( p1.x(), p1.y(), p1.z() ); ::glVertex3f( p2.x(), p2.y(), p2.z() ); ::glEnd(); // resume depth buffer writing ::glDepthMask( GL_TRUE ); // resume lighting ::glEnable( GL_LIGHTING ); }
/* * missing in CGAL? */ squared_distance_t squaredDistanceTriangleTriangle3D( const Triangle_3& triangleA, const Triangle_3& triangleB ) { if ( boost::none != CGAL::intersection( triangleA, triangleB ) ) { return squared_distance_t( 0 ); } /* * min of distance from A segments to B triangle and B segments to A triangle */ squared_distance_t dMin = squaredDistanceSegmentTriangle3D( Segment_3( triangleA.vertex( 0 ), triangleA.vertex( 1 ) ), triangleB ); dMin = std::min( dMin, squaredDistanceSegmentTriangle3D( Segment_3( triangleA.vertex( 1 ), triangleA.vertex( 2 ) ), triangleB ) ); dMin = std::min( dMin, squaredDistanceSegmentTriangle3D( Segment_3( triangleA.vertex( 2 ), triangleA.vertex( 0 ) ), triangleB ) ); dMin = std::min( dMin, squaredDistanceSegmentTriangle3D( Segment_3( triangleB.vertex( 0 ), triangleB.vertex( 1 ) ), triangleA ) ); dMin = std::min( dMin, squaredDistanceSegmentTriangle3D( Segment_3( triangleB.vertex( 1 ), triangleB.vertex( 2 ) ), triangleA ) ); dMin = std::min( dMin, squaredDistanceSegmentTriangle3D( Segment_3( triangleB.vertex( 2 ), triangleB.vertex( 0 ) ), triangleA ) ); return dMin ; }