private void updateBoundingBox(Point p) { double x = p.getX(), y = p.getY(), z = p.getZ(); if (bbMin == null) { bbMin = new Point(p); bbMax = new Point(p); } else { if (x < bbMin.getX()) bbMin.setX(x); else if (x > bbMax.getX()) bbMax.setX(x); if (y < bbMin.getY()) bbMin.setY(y); else if (y > bbMax.getY()) bbMax.setY(y); if (z < bbMin.getZ()) bbMin.setZ(z); else if (z > bbMax.getZ()) bbMax.setZ(z); } }
boolean isLess(Point p) { return compareTo(p) < 0; }
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; }
/** * 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()); }
/** * 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()); }
/** * @return The bounding rectange between the minimum and maximum coordinates * of the triangle */ public BoundingBox getBoundingBox() { Point lowerLeft, upperRight; lowerLeft = new Point(Math.min(a.getX(), Math.min(b.getX(), c.getX())), Math.min(a.getY(), Math.min(b.getY(), c.getY()))); upperRight = new Point(Math.max(a.getX(), Math.max(b.getX(), c.getX())), Math.max(a.getY(), Math.max(b.getY(), c.getY()))); return new BoundingBox(lowerLeft, upperRight); }
if (!neighbor.getA().equals(halfplane.getA()) && !neighbor.getA().equals(halfplane.getB())) third = neighbor.getA(); if (!neighbor.getB().equals(halfplane.getA()) && !neighbor.getB().equals(halfplane.getB())) third = neighbor.getB(); if (!neighbor.getC().equals(halfplane.getA()) && !neighbor.getC().equals(halfplane.getB())) third = neighbor.getC(); double halfplaneDelta = (halfplane.getA().getY() - halfplane.getB().getY()) / (halfplane.getA().getX() - halfplane.getB().getX()); double yOrient = halfplaneDelta * (third.getX() - halfplane.getA().getX()) + halfplane.getA().getY(); boolean above = true; if (yOrient > third.getY()) above = false; double xCellLine = (circumcircle.getX() + (500.0 * sign)); double yCellLine = perpDelta * (xCellLine - circumcircle.getX()) + circumcircle.getY(); result[1] = new Point(xCellLine, yCellLine);
/** * @return Maximum coordinate of bounding box */ public Point getMinPoint() { return new Point(minX, minY, minZ); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((center == null) ? 0 : center.hashCode()); long temp; temp = Double.doubleToLongBits(radius); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; }
boolean circumcircleContains(Point p) { return circum.radius() > circum.center().distance2(p); }
case Point.ONSEGMENT: u = firstT; while (p.isGreater(u.getA())) u = u.getCaTriangle(); t = new Triangle(p, u.getB());
/** * 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); }
/** * @return Minimum coordinate of bounding box */ public Point getMaxPoint() { return new Point(maxX, maxY, maxZ); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Circle other = (Circle) obj; if (center == null) { if (other.center != null) return false; } else if (!center.equals(other.center)) return false; if (Double.doubleToLongBits(radius) != Double.doubleToLongBits(other.radius)) return false; return true; }