public static double getPolygonArea ( int [ ] x , int [ ] y , int N ) { int i , j ; double area = 0 ; for ( i = 0 ; i < N ; i ++ ) { j = ( i + 1 ) % N ; area += x [ i ] * y [ j ] ; area -= y [ i ] * x [ j ] ; } area /= 2 ; return ( area < 0 ? - area : area ) ; }
Calculates the area of a polygon from its vertices .