boolean findInitialTriangle ( List < Point2D_I32 > contour ) { // find the first estimate for a corner int cornerSeed = findCornerSeed ( contour ) ; // see if it can reject the contour immediately if ( convex ) { if ( ! isConvexUsingMaxDistantPoints ( contour , 0 , cornerSeed ) ) return false ; } // Select the second corner. splitter . selectSplitPoint ( contour , 0 , cornerSeed , resultsA ) ; splitter . selectSplitPoint ( contour , cornerSeed , 0 , resultsB ) ; if ( splitter . compareScore ( resultsA . score , resultsB . score ) >= 0 ) { addCorner ( resultsA . index ) ; addCorner ( cornerSeed ) ; } else { addCorner ( cornerSeed ) ; addCorner ( resultsB . index ) ; } // Select the third corner. Initial triangle will be complete now // the third corner will be the one which maximizes the distance from the first two int index0 = list . getHead ( ) . object . index ; int index1 = list . getHead ( ) . next . object . index ; int index2 = maximumDistance ( contour , index0 , index1 ) ; addCorner ( index2 ) ; // enforce CCW requirement ensureTriangleOrder ( contour ) ; return initializeScore ( contour , true ) ; }
Select an initial triangle . A good initial triangle is needed . By good it should minimize the error of the contour from each side