public static List < Point2D_F64 > orderCCW ( List < Point2D_F64 > points ) { Point2D_F64 center = mean ( points , null ) ; double angles [ ] = new double [ points . size ( ) ] ; for ( int i = 0 ; i < angles . length ; i ++ ) { Point2D_F64 p = points . get ( i ) ; double dx = p . x - center . x ; double dy = p . y - center . y ; angles [ i ] = Math . atan2 ( dy , dx ) ; } int order [ ] = new int [ points . size ( ) ] ; QuickSort_F64 sorter = new QuickSort_F64 ( ) ; sorter . sort ( angles , 0 , points . size ( ) , order ) ; List < Point2D_F64 > out = new ArrayList < Point2D_F64 > ( points . size ( ) ) ; for ( int i = 0 ; i < points . size ( ) ; i ++ ) { out . add ( points . get ( order [ i ] ) ) ; } return out ; }
Puts the points into counter - clockwise order around their center .