Formula

double area(Point[] poly) {
  double sum = 0;
  int n = poly.length;
  for (int i = 0; i < n; i++) {
    Point a = poly[i], b = poly[(i+1) % n];
    sum += a.x * b.y - b.x * a.y;
  }
  return Math.abs(sum) / 2.0;
}
Advertisement

Orientation check

Sign of signed area → orientation. Positive: counter-clockwise. Negative: clockwise. Zero: collinear.

Advertisement

Complexity

O(N). Single pass.

Integer arithmetic

Twice signed area is integer for integer vertices. Avoid float rounding.