From 08d5f7b0a0b24c042aa5976f66bf3a1b5b754478 Mon Sep 17 00:00:00 2001 From: Richard Zahoransky Date: Mon, 7 Nov 2011 16:29:56 +0100 Subject: Localization Code. How-To will follow... --- helper/Polygons.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 helper/Polygons.java (limited to 'helper/Polygons.java') diff --git a/helper/Polygons.java b/helper/Polygons.java new file mode 100644 index 0000000..9d3c6ad --- /dev/null +++ b/helper/Polygons.java @@ -0,0 +1,34 @@ +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; + } +} -- cgit v1.2.3-55-g7522