edu.mines.jtk.sgl
Class BoundingSphere

java.lang.Object
  extended by edu.mines.jtk.sgl.BoundingSphere

public class BoundingSphere
extends java.lang.Object

A bounding sphere.

A bounding sphere may be empty. An empty sphere contains no points. A non-empty sphere contains at least one point. Some attributes, such as the sphere center and radius, are defined only for spheres that are not empty.

A bounding sphere may be infinite. An infinite sphere contains all points. Its radius is Double.POSITIVE_INFINITY, and its center is undefined.

Version:
2005.06.28
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
BoundingSphere()
          Constructs an empty bounding sphere.
BoundingSphere(BoundingBox bb)
          Constructs a bounding sphere that contains the specified bounding box.
BoundingSphere(BoundingSphere bs)
          Constructs a copy of the specified bounding sphere.
BoundingSphere(double x, double y, double z, double r)
          Constructs a bounding sphere with specified center and radius.
BoundingSphere(Point3 c, double r)
          Constructs a bounding sphere with specified center and radius.
 
Method Summary
 boolean contains(double x, double y, double z)
          Determines whether this sphere contains a point with specified coordinates.
 boolean contains(Point3 p)
          Determines whether this sphere contains the specified point.
static BoundingSphere empty()
          Returns a new empty bounding sphere.
 void expandBy(BoundingBox bb)
          Expands this sphere to include the specified bounding box.
 void expandBy(BoundingSphere bs)
          Expands this sphere to include the specified bounding sphere.
 void expandBy(double x, double y, double z)
          Expands this sphere to include the point with specified coordinates.
 void expandBy(Point3 p)
          Expands this sphere to include the specified point.
 void expandRadiusBy(BoundingBox bb)
          Expands this sphere to include the specified bounding box.
 void expandRadiusBy(BoundingSphere bs)
          Expands this sphere to include the specified bounding sphere.
 void expandRadiusBy(double x, double y, double z)
          Expands this sphere to include the point with specified coordinates.
 void expandRadiusBy(Point3 p)
          Expands this sphere to include the specified point.
 Point3 getCenter()
          Gets the sphere center.
 double getRadius()
          Gets the sphere radius.
 double getRadiusSquared()
          Gets the sphere radius-squared.
static BoundingSphere infinite()
          Returns a new infinite bounding sphere.
 boolean isEmpty()
          Determines whether this sphere is empty.
 boolean isInfinite()
          Determines whether this sphere is infinite.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoundingSphere

public BoundingSphere()
Constructs an empty bounding sphere.


BoundingSphere

public BoundingSphere(double x,
                      double y,
                      double z,
                      double r)
Constructs a bounding sphere with specified center and radius.

Parameters:
x - the center x coordinate.
y - the center y coordinate.
z - the center z coordinate.
r - the radius; must be non-negative.

BoundingSphere

public BoundingSphere(Point3 c,
                      double r)
Constructs a bounding sphere with specified center and radius.

Parameters:
c - the center.
r - the radius; must be non-negative.

BoundingSphere

public BoundingSphere(BoundingBox bb)
Constructs a bounding sphere that contains the specified bounding box.

Parameters:
bb - the bounding box.

BoundingSphere

public BoundingSphere(BoundingSphere bs)
Constructs a copy of the specified bounding sphere.

Parameters:
bs - the bounding sphere.
Method Detail

isEmpty

public boolean isEmpty()
Determines whether this sphere is empty.

Returns:
true, if empty; false, otherwise.

isInfinite

public boolean isInfinite()
Determines whether this sphere is infinite.

Returns:
true, if infinite; false, otherwise.

getCenter

public Point3 getCenter()
Gets the sphere center.

Returns:
the center.

getRadius

public double getRadius()
Gets the sphere radius.

Returns:
the radius.

getRadiusSquared

public double getRadiusSquared()
Gets the sphere radius-squared.

Returns:
the radius-squared.

expandBy

public void expandBy(double x,
                     double y,
                     double z)
Expands this sphere to include the point with specified coordinates. Adjusts the sphere center to minimize any increase in radius.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
z - the z coordinate of the point.

expandRadiusBy

public void expandRadiusBy(double x,
                           double y,
                           double z)
Expands this sphere to include the point with specified coordinates. Changes only the radius, if necessary, not the center of this sphere.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
z - the z coordinate of the point.

expandBy

public void expandBy(Point3 p)
Expands this sphere to include the specified point. Adjusts the sphere center to minimize any increase in radius.

Parameters:
p - the point.

expandRadiusBy

public void expandRadiusBy(Point3 p)
Expands this sphere to include the specified point. Changes only the radius, if necessary, not the center of this sphere.

Parameters:
p - the point.

expandBy

public void expandBy(BoundingSphere bs)
Expands this sphere to include the specified bounding sphere. Adjusts the sphere center to minimize any increase in radius.

Parameters:
bs - the bounding sphere.

expandRadiusBy

public void expandRadiusBy(BoundingSphere bs)
Expands this sphere to include the specified bounding sphere. Changes only the radius, if necessary, not the center of this sphere.

Parameters:
bs - the bounding sphere.

expandBy

public void expandBy(BoundingBox bb)
Expands this sphere to include the specified bounding box. Adjusts the sphere center to minimize any increase in radius.

Parameters:
bb - the bounding box.

expandRadiusBy

public void expandRadiusBy(BoundingBox bb)
Expands this sphere to include the specified bounding box. Changes only the radius, if necessary, not the center of this sphere.

Parameters:
bb - the bounding box.

contains

public boolean contains(double x,
                        double y,
                        double z)
Determines whether this sphere contains a point with specified coordinates.

Parameters:
x - the point x coordinate.
y - the point y coordinate.
z - the point z coordinate.
Returns:
true, if this sphere contains the point; false, otherwise.

contains

public boolean contains(Point3 p)
Determines whether this sphere contains the specified point.

Parameters:
p - the point.
Returns:
true, if this sphere contains the point; false, otherwise.

empty

public static BoundingSphere empty()
Returns a new empty bounding sphere.

Returns:
a new empty bounding sphere.

infinite

public static BoundingSphere infinite()
Returns a new infinite bounding sphere.

Returns:
a new infinite bounding sphere.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object