private Stack grahamScan ( Coordinate [ ] c ) { Coordinate p ; Stack ps = new Stack ( ) ; p = ( Coordinate ) ps . push ( c [ 0 ] ) ; p = ( Coordinate ) ps . push ( c [ 1 ] ) ; p = ( Coordinate ) ps . push ( c [ 2 ] ) ; for ( int i = 3 ; i < c . length ; i ++ ) { p = ( Coordinate ) ps . pop ( ) ; // check for empty stack to guard against robustness problems while ( ! ps . empty ( ) && CGAlgorithms . computeOrientation ( ( Coordinate ) ps . peek ( ) , p , c [ i ] ) > 0 ) { p = ( Coordinate ) ps . pop ( ) ; } p = ( Coordinate ) ps . push ( p ) ; p = ( Coordinate ) ps . push ( c [ i ] ) ; } p = ( Coordinate ) ps . push ( c [ 0 ] ) ; return ps ; }
Uses the Graham Scan algorithm to compute the convex hull vertices .