int insideTriangle(double x, double y) {
		int j = 2, k;
		boolean inside = false;

		for (k = lastTriangle(); k >= 0; k--) {
			Triangle t = Global.mainTriangles[k];
			for (int i = 0; i <= 2; i++) {
				if ((((t.y[i] <= y) && (y < t.y[j])) || ((t.y[j] <= y) && (y < t.y[i])))
						&& (x < (t.x[j] - t.x[i]) * (y - t.y[i])
								/ (t.y[j] - t.y[i]) + t.x[i])) {
					inside = !inside;
				}
				j = i;
			}
			if (inside) {
				break;
			}
		}

		if (inside) {
			return k;
		} else {
			return -1;
		}
	}