public static boolean isConvex ( double [ ] data , int points ) { if ( points < 3 ) { return true ; } for ( int i1 = 0 ; i1 < points ; i1 ++ ) { int i2 = ( i1 + 1 ) % points ; int i3 = ( i2 + 1 ) % points ; double x1 = data [ 2 * i1 ] ; double y1 = data [ 2 * i1 + 1 ] ; double x2 = data [ 2 * i2 ] ; double y2 = data [ 2 * i2 + 1 ] ; double x3 = data [ 2 * i3 ] ; double y3 = data [ 2 * i3 + 1 ] ; if ( Vectors . isClockwise ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { return false ; } } return true ; }
Returns true if polygon is convex .