public static boolean isPointInPolygon(Point2D[] polygon, Point2D point) {
	if (polygon == null) {
	    return false;
	}
	int size = polygon.length;
	if (size <= 1) {
	    return false;
	}

	int intersections_num = 0;
	int prev = size - 1;
	boolean prev_under = polygon[prev].getY() < point.getY();

	for (int i = 0; i < size; ++i) {
	    boolean cur_under = polygon[i].getY() < point.getY();

	    Point2D a = polygon[prev].subPoint(point);
	    Point2D b = polygon[i].subPoint(point);

	    double t = (a.getX() * (b.getY() - a.getY()) - a.getY() * (b.getX() - a.getX()));
	    if (cur_under && !prev_under) {
		if (t > 0) {
		    intersections_num += 1;
		}
	    }
	    if (!cur_under && prev_under) {
		if (t < 0) {
		    intersections_num += 1;
		}
	    }
	    prev = i;
	    prev_under = cur_under;
	}
	return (intersections_num & 1) != 0;
    }