static boolean isSelfCrossed(Polygon p) {
		if (p == null || p.npoints == 0)
			return false;
		int n = p.npoints;
		Line2D[] lines = new Line2D.Float[n];
		for (int i = 0; i < n - 1; i++) {
			lines[i] = new Line2D.Float(p.xpoints[i], p.ypoints[i], p.xpoints[i + 1], p.ypoints[i + 1]);
		}
		lines[n - 1] = new Line2D.Float(p.xpoints[n - 1], p.ypoints[n - 1], p.xpoints[0], p.ypoints[0]);
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 2; j < n - 1; j++) {
				if (lines[i].intersectsLine(lines[j]))
					return true;
			}
		}
		return false;
	}