/** * Gets the box radius-squared. * @return the box radius-squared. */ public double getRadiusSquared() { Check.state(!isEmpty(),"bounding box is not empty"); double dx = _xmax-_xmin; double dy = _ymax-_ymin; double dz = _zmax-_zmin; return 0.25*(dx*dx+dy*dy+dz*dz); }
/** * Gets the point in this box with maximum coordinates. * @return the maximim point. */ public Point3 getMax() { Check.state(!isEmpty(),"bounding box is not empty"); return new Point3(_xmax,_ymax,_zmax); }
/** * Gets the point in this box with minimum coordinates. * @return the minimim point. */ public Point3 getMin() { Check.state(!isEmpty(),"bounding box is not empty"); return new Point3(_xmin,_ymin,_zmin); }
/** * Gets the point at a specified corner of this box. * The corner is specified by index, an integer between 0 and 7. From * least to most significant, the three bits of this index correspond * to x, y, and z coordinates of a corner point. A zero bit selects a * minimum coordinate; a one bit selects a maximum coordinate. * @param index the corner index. * @return the corner point. */ public Point3 getCorner(int index) { Check.state(!isEmpty(),"bounding box is not empty"); double x = ((index&1)==0)?_xmin:_xmax; double y = ((index&2)==0)?_ymin:_ymax; double z = ((index&4)==0)?_zmin:_zmax; return new Point3(x,y,z); }
/** * Gets the point at the center of this box. * @return the box center. */ public Point3 getCenter() { Check.state(!isEmpty(),"bounding box is not empty"); Check.state(!isInfinite(),"bounding box is not infinite"); return (isInfinite()) ? new Point3(0.0,0.0,0.0) : new Point3(0.5*(_xmin+_xmax),0.5*(_ymin+_ymax),0.5*(_zmin+_zmax)); }
if (!isInfinite()) { if (!bb.isInfinite()) { if (!bb.isEmpty()) { Point3 pmin = bb.getMin(); Point3 pmax = bb.getMax();
if (!isInfinite()) { if (!bb.isInfinite()) { if (!bb.isEmpty()) { Point3 pmin = bb.getMin(); Point3 pmax = bb.getMax();
/** * Computes the bounding sphere for this group, including its children. * @param finite true, to force bounding sphere to be finite. * @return the computed bounding sphere. */ protected BoundingSphere computeBoundingSphere(boolean finite) { if (countChildren()==1) { return _childList.get(0).getBoundingSphere(finite); } else { BoundingBox bb = new BoundingBox(); for (Node child : _childList) bb.expandBy(child.getBoundingSphere(finite)); if (bb.isEmpty()) return BoundingSphere.empty(); if (bb.isInfinite()) // should not happen if finite == true return BoundingSphere.infinite(); BoundingSphere bs = new BoundingSphere(bb.getCenter(),0.0); for (Node child : _childList) bs.expandRadiusBy(child.getBoundingSphere(finite)); return bs; } }
public void testBoxExpand() { int ntrial = 100; for (int itrial=0; itrial<ntrial; ++itrial) { BoundingBox bb = new BoundingBox(); assertTrue(bb.isEmpty()); int nexpand = 100; for (int iexpand=0; iexpand<nexpand; ++iexpand) { Point3 c = randomPoint3(); double r = randomDouble(); BoundingSphere bs = new BoundingSphere(c,r); bb.expandBy(bs); assertTrue(!bb.isEmpty()); int npoint=100; for (int ipoint=0; ipoint<npoint; ++ipoint) { Point3 p = randomPoint3(); if (bs.contains(p)) assertTrue(bb.contains(p)); } } } }