/** * Expands this sphere to include the specified point. * Adjusts the sphere center to minimize any increase in radius. * @param p the point. */ public void expandBy(Point3 p) { expandBy(p.x,p.y,p.z); }
/** * Constructs a bounding sphere that contains the specified bounding box. * @param bb the bounding box. */ public BoundingSphere(BoundingBox bb) { this(); expandBy(bb); }
/** * Gets the bounding sphere for this constraint. * @return the bounding sphere. */ public BoundingSphere getBoundingSphere() { BoundingSphere bs = new BoundingSphere(); bs.expandBy(getBoundingBox()); 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)); } } } }
public void testSphere() { BoundingSphere bs = new BoundingSphere(); bs.expandBy(0,0,0); bs.expandBy(1,1,1); double a = 10.0*DBL_EPSILON; double b = 1.0-a; assertTrue(bs.contains(new Point3(a,a,a))); assertTrue(bs.contains(new Point3(a,a,b))); assertTrue(bs.contains(new Point3(a,b,a))); assertTrue(bs.contains(new Point3(a,b,b))); assertTrue(bs.contains(new Point3(b,a,a))); assertTrue(bs.contains(new Point3(b,a,b))); assertTrue(bs.contains(new Point3(b,b,a))); assertTrue(bs.contains(new Point3(b,b,b))); a = -10.0*DBL_EPSILON; b = 1.0-a; assertTrue(!bs.contains(new Point3(a,a,a))); assertTrue(!bs.contains(new Point3(a,a,b))); assertTrue(!bs.contains(new Point3(a,b,a))); assertTrue(!bs.contains(new Point3(a,b,b))); assertTrue(!bs.contains(new Point3(b,a,a))); assertTrue(!bs.contains(new Point3(b,a,b))); assertTrue(!bs.contains(new Point3(b,b,a))); assertTrue(!bs.contains(new Point3(b,b,b))); }