private Point findDiagonal(Triangle triangle, Point point) { Point p1 = triangle.getA(); Point p2 = triangle.getB(); Point p3 = triangle.getC(); if ((p1.pointLineTest(point, p3) == Point.LEFT) && (p2.pointLineTest(point, p3) == Point.RIGHT)) return p3; if ((p3.pointLineTest(point, p2) == Point.LEFT) && (p1.pointLineTest(point, p2) == Point.RIGHT)) return p2; if ((p2.pointLineTest(point, p1) == Point.LEFT) && (p3.pointLineTest(point, p1) == Point.RIGHT)) return p1; return null; }
private Triangle treatDegeneracyInside(Triangle t, Point p) { if (t.getAbTriangle().isHalfplane() && p.pointLineTest(t.getB(), t.getA()) == Point.ONSEGMENT) return extendOutside(t.getAbTriangle(), p); if (t.getBcTriangle().isHalfplane() && p.pointLineTest(t.getC(), t.getB()) == Point.ONSEGMENT) return extendOutside(t.getBcTriangle(), p); if (t.getCaTriangle().isHalfplane() && p.pointLineTest(t.getA(), t.getC()) == Point.ONSEGMENT) return extendOutside(t.getCaTriangle(), p); return null; }
private Triangle extendcounterclock(Triangle t, Point p) { t.setHalfplane(false); t.setC(p); t.circumcircle(); Triangle tca = t.getCaTriangle(); if (p.pointLineTest(tca.getA(), tca.getB()) >= Point.RIGHT) { Triangle nT = new Triangle(t.getA(), p); nT.setAbTriangle(t); t.setCanext(nT); nT.setCanext(tca); tca.setBcTriangle(nT); return nT; } return extendcounterclock(tca, p); }
private Triangle extendclock(Triangle t, Point p) { t.setHalfplane(false); t.setC(p); t.circumcircle(); Triangle tbc = t.getBcTriangle(); if (p.pointLineTest(tbc.getA(), tbc.getB()) >= Point.RIGHT) { Triangle nT = new Triangle(p, t.getB()); nT.setAbTriangle(t); t.setBcTriangle(nT); nT.setBcTriangle(tbc); tbc.setCanext(nT); return nT; } return extendclock(tbc, p); }
Circle circumcircle() { double u = ((a.getX() - b.getX()) * (a.getX() + b.getX()) + (a.getY() - b.getY()) * (a.getY() + b.getY())) / 2.0f; double v = ((b.getX() - c.getX()) * (b.getX() + c.getX()) + (b.getY() - c.getY()) * (b.getY() + c.getY())) / 2.0f; double den = (a.getX() - b.getX()) * (b.getY() - c.getY()) - (b.getX() - c.getX()) * (a.getY() - b.getY()); if (den == 0) // oops, degenerate case circum = new Circle(a, Double.POSITIVE_INFINITY); else { Point cen = new Point((u * (b.getY() - c.getY()) - v * (a.getY() - b.getY())) / den, (v * (a.getX() - b.getX()) - u * (b.getX() - c.getX())) / den); circum = new Circle(cen, cen.distance2(a)); } return circum; }
/** * Locates the grid cell point covering the given coordinate * * @param coordinate * world coordinate to locate * @return cell covering the coordinate */ private PointInt getCellOf(Point coordinate) { int xCell = (int) ((coordinate.getX() - indexRegion.minX()) / xSize); int yCell = (int) ((coordinate.getY() - indexRegion.minY()) / ySize); return new PointInt(xCell, yCell); }
/** * Create a bounding box between lowerLeft and upperRight * * @param lowerLeft * lower left point of the box * @param upperRight * upper left point of the box */ public BoundingBox(Point lowerLeft, Point upperRight) { init(lowerLeft.getX(), upperRight.getX(), lowerLeft.getY(), upperRight.getY(), lowerLeft.getZ(), upperRight.getZ()); }
/** * compute the Z value for the X,Y values of q. assume this triangle * represent a plane --> q does NOT need to be contained in this triangle. * * @param q * query point (its Z value is ignored). * @return q with updated Z value. * */ public Point getZ(Point q) { double z = zValue(q); return new Point(q.getX(), q.getY(), z); }
/** * Checks if the given point is a corner of this triangle. * * @param p * The given point. * @return True iff the given point is a corner of this triangle. * * By Eyal Roth & Doron Ganel. */ public boolean isCorner(Point p) { return (p.getX() == a.getX() && p.getY() == a.getY()) || (p.getX() == b.getX() && p.getY() == b.getY()) || (p.getX() == c.getX() && p.getY() == c.getY()); }
/** * * @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(); }
/** * compute the Z value for the X,Y values of q. assume this triangle * represent a plane --> q does NOT need to be contained in this triangle. * * @param x * x-coordinate of the query point. * @param y * y-coordinate of the query point. * @return z (height) value approximation given by the triangle it falls in. * */ public double getZ(double x, double y) { return zValue(new Point(x, y)); }
/** * @return Maximum coordinate of bounding box */ public Point getMinPoint() { return new Point(minX, minY, minZ); }
/** * Creates an empty bounding box */ public BoundingBox() { setToNull(); }
/** * Index the triangulation using a grid index * * @param xCellCount * number of grid cells in a row * @param yCellCount * number of grid cells in a column */ public void indexData(int xCellCount, int yCellCount) { gridIndex = new GridIndex(this, xCellCount, yCellCount); }
/** * Finds a triangle near the given point * * @param point * a query point * @return a triangle at the same cell of the point */ public Triangle findCellTriangleOf(Point point) { int xIndex = (int) ((point.getX() - indexRegion.minX()) / xSize); int yIndex = (int) ((point.getY() - indexRegion.minY()) / ySize); return grid[xIndex][yIndex]; }
/** * @return Minimum coordinate of bounding box */ public Point getMaxPoint() { return new Point(maxX, maxY, maxZ); } }