/** * Returns a new empty bounding sphere. * @return a new empty bounding sphere. */ public static BoundingSphere empty() { return new BoundingSphere(); }
/** * Gets the world sphere used to parameterize this view. * @return the world sphere; null, if none. */ public BoundingSphere getWorldSphere() { return new BoundingSphere(_worldSphere); }
protected BoundingSphere computeBoundingSphere(boolean finite) { return new BoundingSphere(0.0,0.0,0.0,Math.sqrt(3.0)); } }
protected BoundingSphere computeBoundingSphere(boolean finite) { Point3 c = new Point3(0.5,0.5,0.5); double r = 0.5*Math.sqrt(3.0); return new BoundingSphere(c,r); }
/** * Sets the bounding sphere of the frame with a given center point and * radius. * @param p the center point. * @param r the radius. */ public void setWorldSphere(Point3 p, int r) { setWorldSphere(new BoundingSphere(p,r)); }
/** * Sets the bounding sphere of the frame with a given center x, y, z and * radius. * @param x the center X-coordinate. * @param y the center Y-coordinate. * @param z the center Z-coordinate. * @param r the radius. */ public void setWorldSphere(double x, double y, double z, double r) { setWorldSphere(new BoundingSphere(x,y,z,r)); }
BoundingSphere computeBoundingSphereOfFrame(boolean finite) { double dx = _p[3].x-_p[0].x; double dy = _p[3].y-_p[0].y; double dz = _p[3].z-_p[0].z; double r = sqrt(dx*dx+dy*dy+dz*dz); double x = 0.5*(_p[0].x+_p[3].x); double y = 0.5*(_p[0].y+_p[3].y); double z = 0.5*(_p[0].z+_p[3].z); Point3 c = new Point3(x,y,z); return new BoundingSphere(c,r); }
/** * Returns a new infinite bounding sphere. * @return a new infinite bounding sphere. */ public static BoundingSphere infinite() { BoundingSphere bs = new BoundingSphere(); bs.setInfinite(); return bs; }
/** * Computes the bounding sphere for this panel. This implementation * delegates this computation to its frame; or, if not in a frame, * this implementation returns an empty bounding sphere. * <p> * Panels that extend this class typically inherit this implementation, * but may of course override it as necessary. */ protected BoundingSphere computeBoundingSphere(boolean finite) { if (_frame==null) { return new BoundingSphere(); } else { return _frame.computeBoundingSphereOfFrame(finite); } }
protected BoundingSphere computeBoundingSphere(boolean finite) { Rectangle2D rect = _renderer.getBounds(_text); double w = rect.getWidth(); double h = rect.getHeight(); return new BoundingSphere(0.0,0.0,0.0,sqrt(w*w+h*h)); } }
/** * Gets the bounding sphere for this constraint. * @return the bounding sphere. */ public BoundingSphere getBoundingSphere() { BoundingSphere bs = new BoundingSphere(); bs.expandBy(getBoundingBox()); return bs; }
public LineNode(float[] xyz, float[] rgb) { BoundingBox bb = new BoundingBox(xyz); _bs = new BoundingSphere(bb); _np = xyz.length/3; int np = _np; int nv = np; int nc = np; _vb = Direct.newFloatBuffer(3*nv); _cb = (rgb!=null)?Direct.newFloatBuffer(3*nc):null; for (int ip=0,iv=0,ic=0; ip<np; ++ip) { int i = 3*ip; _vb.put(iv++,xyz[i+X]); _vb.put(iv++,xyz[i+Y]); _vb.put(iv++,xyz[i+Z]); if (_cb!=null) { _cb.put(ic++,rgb[i+R]); _cb.put(ic++,rgb[i+G]); _cb.put(ic++,rgb[i+B]); } } }
public PointNode( BoundingBoxTree.Node bbtNode, float[] xyz, float[] rgb) { BoundingBox bb = bbtNode.getBoundingBox(); _bs = new BoundingSphere(bb); _np = bbtNode.getSize(); int np = _np; int nv = np; int nc = np; int[] index = bbtNode.getIndices(); _vb = Direct.newFloatBuffer(3*nv); _cb = (rgb!=null)?Direct.newFloatBuffer(3*nc):null; for (int ip=0,iv=0,ic=0; ip<np; ++ip) { int i = 3*index[ip]; _vb.put(iv++,xyz[i+X]); _vb.put(iv++,xyz[i+Y]); _vb.put(iv++,xyz[i+Z]); if (_cb!=null) { _cb.put(ic++,rgb[i+R]); _cb.put(ic++,rgb[i+G]); _cb.put(ic++,rgb[i+B]); } } }
/** * Sets the bounding sphere of the frame. * @param xmin the minimum x coordinate. * @param ymin the minimum y coordinate. * @param zmin the minimum z coordinate. * @param xmax the maximum x coordinate. * @param ymax the maximum y coordinate. * @param zmax the maximum z coordinate. */ public void setWorldSphere( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax) { setWorldSphere( new BoundingSphere( new BoundingBox(xmin,ymin,zmin,xmax,ymax,zmax))); }
/** * 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 static void main(String[] args) { float[] xyz = makeSineWave(); xyz = addBulge(xyz); xyz = addTear(xyz); float[] rgb = makeColors(xyz); System.out.println("Making QuadGroup ..."); QuadGroup tg = new QuadGroup(true,xyz,rgb); System.out.println("QuadGroup bounding sphere =\n" + tg.getBoundingSphere(true)); StateSet states = new StateSet(); ColorState cs = new ColorState(); cs.setColor(Color.CYAN); states.add(cs); LightModelState lms = new LightModelState(); lms.setTwoSide(true); states.add(lms); MaterialState ms = new MaterialState(); ms.setColorMaterial(GL_AMBIENT_AND_DIFFUSE); ms.setSpecular(Color.white); ms.setShininess(100.0f); states.add(ms); tg.setStates(states); World world = new World(); world.addChild(tg); DemoFrame frame = new DemoFrame(world); OrbitView view = frame.getOrbitView(); view.setWorldSphere(new BoundingSphere(5,5,5,5)); frame.setSize(new Dimension(800,600)); frame.setVisible(true); }
if (r<ly) r = ly; if (r<lz) r = lz; bs = new BoundingSphere(c,r);
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 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))); }