public void writeBounds( DataOutput out, Bounds bounds ) throws IOException { if (bounds==null) { out.writeInt( 0 ); } else if (bounds instanceof BoundingBox) { out.writeInt( 1 ); // Type Point3d p = new Point3d(); ((BoundingBox)bounds).getLower( p ); writePoint3d( out, p ); ((BoundingBox)bounds).getUpper( p ); writePoint3d( out, p ); } else if (bounds instanceof BoundingSphere) { out.writeInt( 2 ); // Type Point3d p = new Point3d(); ((BoundingSphere)bounds).getCenter( p ); writePoint3d( out, p ); out.writeDouble( ((BoundingSphere)bounds).getRadius() ); } else if (bounds instanceof BoundingPolytope ) { out.writeInt( 3 ); // Type Vector4d[] planes = new Vector4d[ ((BoundingPolytope)bounds).getNumPlanes() ]; ((BoundingPolytope)bounds).getPlanes( planes ); out.writeInt( planes.length ); for(int i=0; i<planes.length; i++) writeVector4d( out, planes[i] ); } else { throw new IOException( "Unsupported bounds class "+bounds.getClass().getName() ); } }
static boolean edgeIntersectSphere (BoundingSphere sphere, Point3d start, Point3d end) { double abLenSq, acLenSq, apLenSq, abDotAp, radiusSq; Vector3d ab = new Vector3d(); Vector3d ap = new Vector3d(); Point3d center = new Point3d(); sphere.getCenter (center); double radius = sphere.getRadius (); ab.x = end.x - start.x; ab.y = end.y - start.y; ab.z = end.z - start.z; ap.x = center.x - start.x; ap.y = center.y - start.y; ap.z = center.z - start.z; abDotAp = ab.dot(ap); if (abDotAp < 0.0) return false; // line segment points away from sphere. abLenSq = ab.lengthSquared(); acLenSq = abDotAp * abDotAp / abLenSq; if (acLenSq < abLenSq) return false; // C doesn't lies between end points of edge. radiusSq = radius * radius; apLenSq = ap.lengthSquared(); if ((apLenSq - acLenSq) <= radiusSq) return true; return false; }
boolean esFlag; Point3d center = new Point3d(); sphere.getCenter (center); double radius = sphere.getRadius ();
Point3d sphCenter = ((BoundingSphere)bounds).getCenter(); double sphRadius = ((BoundingSphere)bounds).getRadius(); double sqDist = Utils.ptToSegSquare(sphCenter, origin, end, null); BoundingSphere bsphere = new BoundingSphere (bounds); bsphere.getCenter (sphCenter); double sphRadius = bsphere.getRadius();
Point3d sphCenter = ((BoundingSphere)bounds).getCenter(); double sphRadius = ((BoundingSphere)bounds).getRadius(); double sqDist = Utils.ptToRaySquare(sphCenter, origin, direction, null); BoundingSphere bsphere = new BoundingSphere (bounds); bsphere.getCenter (sphCenter); double sphRadius = bsphere.getRadius();
Point3d sphCenter = ((BoundingSphere)bounds).getCenter(); double sphRadius = ((BoundingSphere)bounds).getRadius(); double sqDist = Utils.ptToRaySquare(sphCenter, origin, direction, rayPt); BoundingSphere bsphere = new BoundingSphere (bounds); bsphere.getCenter (sphCenter); double sphRadius = bsphere.getRadius();
Point3d sphCenter = ((BoundingSphere)bounds).getCenter(); double sphRadius = ((BoundingSphere)bounds).getRadius(); double sqDist = Utils.ptToSegSquare(sphCenter, origin, end, rayPt); BoundingSphere bsphere = new BoundingSphere (bounds); bsphere.getCenter (sphCenter); double sphRadius = bsphere.getRadius();