/** * finds the triangle the query point falls in, note if out-side of this * triangulation a half plane triangle will be returned (see contains). the * search starts from the the start triangle * * @param p * query point * @param start * the triangle the search starts at. * @return the triangle that point p is in.. */ public Triangle find(Point p, Triangle start) { if (start == null) start = this.startTriangle; Triangle T = find(start, p); return T; }
Vector<Triangle> triangles = null; Triangle triangle = find(point);
/** * * @param p * query point * @return true iff p is within this triangulation (in its 2D convex hull). */ public boolean contains(Point p) { Triangle tt = find(p); return !tt.isHalfplane(); }
/** * * @param q * Query point * @return the q point with updated Z value (z value is as given the * triangulation). */ public Point z(Point q) { Triangle t = find(q); return t.getZ(q); }
private void updateCellValues(int startXCell, int startYCell, int lastXCell, int lastYCell, Triangle startTriangle) { // Go over each grid cell and locate a triangle in it to be the cell's // starting search triangle. Since we only pass between adjacent cells // we can search from the last triangle found and not from the start. // Add triangles for each column cells for (int i = startXCell; i <= lastXCell; i++) { // Find a triangle at the begining of the current column startTriangle = indexDelaunay.find(middleOfCell(i, startYCell), startTriangle); grid[i][startYCell] = startTriangle; Triangle prevRowTriangle = startTriangle; // Add triangles for the next row cells for (int j = startYCell + 1; j <= lastYCell; j++) { grid[i][j] = indexDelaunay.find(middleOfCell(i, j), prevRowTriangle); prevRowTriangle = grid[i][j]; } } }
/** * finds the triangle the query point falls in, note if out-side of this * triangulation a half plane triangle will be returned (see contains), the * search has expected time of O(n^0.5), and it starts form a fixed triangle * (this.startTriangle), * * @param p * query point * @return the triangle that point p is in. */ public Triangle find(Point p) { // If triangulation has a spatial index try to use it as the starting // triangle Triangle searchTriangle = startTriangle; if (gridIndex != null) { Triangle indexTriangle = gridIndex.findCellTriangleOf(p); if (indexTriangle != null) searchTriangle = indexTriangle; } // Search for the point's triangle starting from searchTriangle return find(searchTriangle, p); }
/** * * @param x * - X cordination of the query point * @param y * - Y cordination of the query point * @return the q point with updated Z value (z value is as given the * triangulation). */ public double z(double x, double y) { Point q = new Point(x, y); Triangle t = find(q); return t.zValue(q); }
/** * Finds a valid (existing) trinagle adjacent to a given invalid cell * * @param minInvalidCell * minimum bounding box invalid cell * @return a valid triangle adjacent to the invalid cell */ private Triangle findValidTriangle(PointInt minInvalidCell) { // If the invalid cell is the minimal one in the grid we are forced to // search the // triangulation for a trinagle at that location if (minInvalidCell.x == 0 && minInvalidCell.y == 0) return indexDelaunay.find(middleOfCell(minInvalidCell.getX(), minInvalidCell.getY()), null); else // Otherwise we can take an adjacent cell triangle that is still // valid return grid[Math.min(0, minInvalidCell.getX())][Math.min(0, minInvalidCell.getY())]; }
/** * Initialize the grid index * * @param delaunay * delaunay triangulation to index * @param xCellCount * number of grid cells in a row * @param yCellCount * number of grid cells in a column * @param region * geographic region to index */ private void init(DelaunayTriangulation delaunay, int xCellCount, int yCellCount, BoundingBox region) { indexDelaunay = delaunay; indexRegion = region; xSize = region.getWidth() / yCellCount; ySize = region.getHeight() / xCellCount; // The grid will hold a trinagle for each cell, so a point (x,y) will // lie // in the cell representing the grid partition of region to a // xCellCount on yCellCount grid grid = new Triangle[xCellCount][yCellCount]; Triangle colStartTriangle = indexDelaunay.find(middleOfCell(0, 0)); updateCellValues(0, 0, xCellCount - 1, yCellCount - 1, colStartTriangle); }
private Triangle insertPointSimple(Point p) { Triangle t = find(startTriangle, p); if (t.isHalfplane()) startTriangle = extendOutside(t, p);
Triangle triangle = find(pointToDelete); Point p1 = triangle.getA(); Point p2 = triangle.getB();