/** * Constructs a bounding box for points with specified coordinates. * The (x,y,z) coordinates are packed into the specified array such * that (xyz[0],xyz[1],xyz[2]) are the (x,y,z) coordinates of the * 1st point, (xyz[3],xyz[4],xyz[5]) are the (x,y,z) coordinates of * the 2nd point, and so on. * @param xyz array of packed (x,y,z) coordinates. */ public BoundingBox(float[] xyz) { this(); expandBy(xyz); }
/** * Constructs a bounding box for points with specified coordinates. * @param x array of x coordinates. * @param y array of y coordinates. * @param z array of z coordinates. */ public BoundingBox(float[] x, float[] y, float[] z) { this(); expandBy(x,y,z); }
/** * Expands this box to include the points with specified coordinates. * @param x array of x coordinates. * @param y array of y coordinates. * @param z array of z coordinates. */ public void expandBy(float[] x, float[] y, float[] z) { int n = x.length; for (int i=0; i<n; ++i) expandBy(x[i],y[i],z[i]); }
/** * Expands this box to include the specified point. * @param p the point. */ public void expandBy(Point3 p) { expandBy(p.x,p.y,p.z); }
/** * Expands this box to include the points with specified coordinates. * The (x,y,z) coordinates are packed into the specified array, such * that (xyz[0],xyz[1],xyz[2]) are the (x,y,z) coordinates of the 1st * point, (xyz[3],xyz[4],xyz[5]) are the (x,y,z) coordinates of the 2nd * point, and so on. * @param xyz array of packed (x,y,z) coordinates. */ public void expandBy(float[] xyz) { int n = xyz.length; for (int i=0; i<n; i+=3) expandBy(xyz[i],xyz[i+1],xyz[i+2]); }
/** * 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)); } } } }
public void testBox() { BoundingBox bb = new BoundingBox(); bb.expandBy(0,0,0); bb.expandBy(1,1,1); double a = 10.0*DBL_EPSILON; double b = 1.0-a; assertTrue(bb.contains(new Point3(a,a,a))); assertTrue(bb.contains(new Point3(a,a,b))); assertTrue(bb.contains(new Point3(a,b,a))); assertTrue(bb.contains(new Point3(a,b,b))); assertTrue(bb.contains(new Point3(b,a,a))); assertTrue(bb.contains(new Point3(b,a,b))); assertTrue(bb.contains(new Point3(b,b,a))); assertTrue(bb.contains(new Point3(b,b,b))); a = -10.0*DBL_EPSILON; b = 1.0-a; assertTrue(!bb.contains(new Point3(a,a,a))); assertTrue(!bb.contains(new Point3(a,a,b))); assertTrue(!bb.contains(new Point3(a,b,a))); assertTrue(!bb.contains(new Point3(a,b,b))); assertTrue(!bb.contains(new Point3(b,a,a))); assertTrue(!bb.contains(new Point3(b,a,b))); assertTrue(!bb.contains(new Point3(b,b,a))); assertTrue(!bb.contains(new Point3(b,b,b))); }