package helper; import java.awt.Polygon; public class Polygons { public static double area(Polygon poly) { double area = 0; // make list out of polygon. see // http://anklick-bar.de/matheprojekt/kurbel-gauss.pdf Point[] list = new Point[poly.npoints + 2]; for (int i = 0; i < poly.npoints; i++) { list[i] = new Point(poly.xpoints[i], poly.ypoints[i]); } list[poly.npoints] = new Point(poly.xpoints[0], poly.ypoints[0]); list[poly.npoints + 1] = new Point(poly.xpoints[1], poly.ypoints[1]); for (int i = 1; i <= poly.npoints; i++) { // area of polygon is left to the line area = area + (list[i + 1].y - list[i - 1].y) * list[i].x; } return area * (-1); } } class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } }