Java examples for java.lang:Math Geometry Shape
point In Polygon
//package com.java2s; public class Main { public static boolean pointInPolygon(double[] point, double[][] polygon) { int i, j; boolean c = false; for (i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { if ((((polygon[i][1] <= point[1]) && (point[1] < polygon[j][1])) || ((polygon[j][1] <= point[1]) && (point[1] < polygon[i][1]))) && (point[0] < (polygon[j][0] - polygon[i][0]) * (point[1] - polygon[i][1]) / (polygon[j][1] - polygon[i][1]) + polygon[i][0])) { c = !c;/*w w w. j av a 2 s .c om*/ } } return c; } public static boolean pointInPolygon(double x, double y, double[][] polygon) { int i, j; boolean c = false; for (i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { if ((((polygon[i][1] <= y) && (y < polygon[j][1])) || ((polygon[j][1] <= y) && (y < polygon[i][1]))) && (x < (polygon[j][0] - polygon[i][0]) * (y - polygon[i][1]) / (polygon[j][1] - polygon[i][1]) + polygon[i][0])) { c = !c; } } return c; } }