/** * Expands this sphere to include the specified point. * Changes only the radius, if necessary, not the center of this sphere. * @param p the point. */ public void expandRadiusBy(Point3 p) { expandRadiusBy(p.x,p.y,p.z); }
double y = ((i&2)==0)?ymin:ymax; double z = ((i&4)==0)?zmin:zmax; expandRadiusBy(x,y,z);
/** * 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 testSphereExpand() { int ntrial = 100; for (int itrial=0; itrial<ntrial; ++itrial) { BoundingSphere bs = new BoundingSphere(); assertTrue(bs.isEmpty()); int nexpand = 100; for (int iexpand=0; iexpand<nexpand; ++iexpand) { Point3 p = randomPoint3(); Point3 q = randomPoint3(); BoundingBox bb = new BoundingBox(p,q); if (randomDouble()>0.5) { bs.expandBy(bb); } else { bs.expandRadiusBy(bb); } assertTrue(!bs.isEmpty()); int npoint=100; for (int ipoint=0; ipoint<npoint; ++ipoint) { Point3 r = randomPoint3(); if (bb.contains(r)) assertTrue(bs.contains(r)); } } } }