boolean isApproximatelyElliptical ( EllipseRotated_F64 ellipse , List < Point2D_F64 > points , int maxSamples ) { closestPoint . setEllipse ( ellipse ) ; double maxDistance2 = maxDistanceFromEllipse * maxDistanceFromEllipse ; if ( points . size ( ) <= maxSamples ) { for ( int i = 0 ; i < points . size ( ) ; i ++ ) { Point2D_F64 p = points . get ( i ) ; closestPoint . process ( p ) ; double d = closestPoint . getClosest ( ) . distance2 ( p ) ; if ( d > maxDistance2 ) { return false ; } } } else { for ( int i = 0 ; i < maxSamples ; i ++ ) { Point2D_F64 p = points . get ( i * points . size ( ) / maxSamples ) ; closestPoint . process ( p ) ; double d = closestPoint . getClosest ( ) . distance2 ( p ) ; if ( d > maxDistance2 ) { return false ; } } } return true ; }
Look at the maximum distance contour points are from the ellipse and see if they exceed a maximum threshold