edu.mines.jtk.sgl
Class BoundingBox

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

public class BoundingBox
extends java.lang.Object

An axis-aligned bounding box.

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

A bounding box may be infinite. An infinite box contains all points. Its minimum and maximum points are at Double.NEGATIVE_INFINITY and Double.POSITIVE_INFINITY, respectively, and its center is undefined.

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

Constructor Summary
BoundingBox()
          Constructs an empty bounding box.
BoundingBox(BoundingBox bb)
          Constructs a copy of the specified bounding box.
BoundingBox(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
          Constructs a bounding box with specified bounds.
BoundingBox(float[] xyz)
          Constructs a bounding box for points with specified coordinates.
BoundingBox(float[] x, float[] y, float[] z)
          Constructs a bounding box for points with specified coordinates.
BoundingBox(Point3 p)
          Constructs the smallest bounding box that contains one point.
BoundingBox(Point3 p, Point3 q)
          Constructs the smallest bounding box that contains two points.
 
Method Summary
 boolean contains(BoundingBox bb)
          Determines whether this box contains the specified bounding box.
 boolean contains(double x, double y, double z)
          Determines whether this box contains the point with specified coordinates.
 boolean contains(Point3 p)
          Determines whether this box contains the specified point.
static BoundingBox empty()
          Returns a new empty bounding box.
 void expandBy(BoundingBox bb)
          Expands this box to include the specified bounding box.
 void expandBy(BoundingSphere bs)
          Expands this box to include the specified bounding sphere.
 void expandBy(double x, double y, double z)
          Expands this box to include the point with specified coordinates.
 void expandBy(float[] xyz)
          Expands this box to include the points with specified coordinates.
 void expandBy(float[] x, float[] y, float[] z)
          Expands this box to include the points with specified coordinates.
 void expandBy(Point3 p)
          Expands this box to include the specified point.
 Point3 getCenter()
          Gets the point at the center of this box.
 Point3 getCorner(int index)
          Gets the point at a specified corner of this box.
 Point3 getMax()
          Gets the point in this box with maximum coordinates.
 Point3 getMin()
          Gets the point in this box with minimum coordinates.
 double getRadius()
          Gets the box radius, the distance from the center to any corner.
 double getRadiusSquared()
          Gets the box radius-squared.
static BoundingBox infinite()
          Returns a new infinite bounding box.
 boolean intersects(BoundingBox bb)
          Determines whether this box intersects the specified bounding box.
 boolean isEmpty()
          Determines whether this box is empty.
 boolean isInfinite()
          Determines whether this box 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

BoundingBox

public BoundingBox()
Constructs an empty bounding box.


BoundingBox

public BoundingBox(Point3 p)
Constructs the smallest bounding box that contains one point.

Parameters:
p - a point.

BoundingBox

public BoundingBox(Point3 p,
                   Point3 q)
Constructs the smallest bounding box that contains two points. The two points represent two of the eight corners of the box.

Parameters:
p - a point.
q - a point.

BoundingBox

public BoundingBox(double xmin,
                   double ymin,
                   double zmin,
                   double xmax,
                   double ymax,
                   double zmax)
Constructs a bounding box with specified bounds.

Parameters:
xmin - the minimum x coordinate.
ymin - the minimum y coordinate.
zmin - the minimum z coordinate.
xmax - the maximum x coordinate.
ymax - the maximum y coordinate.
zmax - the maximum z coordinate.

BoundingBox

public BoundingBox(float[] xyz)
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.

Parameters:
xyz - array of packed (x,y,z) coordinates.

BoundingBox

public BoundingBox(float[] x,
                   float[] y,
                   float[] z)
Constructs a bounding box for points with specified coordinates.

Parameters:
x - array of x coordinates.
y - array of y coordinates.
z - array of z coordinates.

BoundingBox

public BoundingBox(BoundingBox bb)
Constructs a copy of the specified bounding box.

Parameters:
bb - the bounding box.
Method Detail

isEmpty

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

Returns:
true, if empty; false, otherwise.

isInfinite

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

Returns:
true, if infinite; false, otherwise.

getMin

public Point3 getMin()
Gets the point in this box with minimum coordinates.

Returns:
the minimim point.

getMax

public Point3 getMax()
Gets the point in this box with maximum coordinates.

Returns:
the maximim point.

getCenter

public Point3 getCenter()
Gets the point at the center of this box.

Returns:
the box center.

getRadius

public double getRadius()
Gets the box radius, the distance from the center to any corner.

Returns:
the box radius.

getRadiusSquared

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

Returns:
the box radius-squared.

getCorner

public Point3 getCorner(int index)
Gets the point at a specified corner of this box. The corner is specified by index, an integer between 0 and 7. From least to most significant, the three bits of this index correspond to x, y, and z coordinates of a corner point. A zero bit selects a minimum coordinate; a one bit selects a maximum coordinate.

Parameters:
index - the corner index.
Returns:
the corner point.

expandBy

public void expandBy(Point3 p)
Expands this box to include the specified point.

Parameters:
p - the point.

expandBy

public void expandBy(double x,
                     double y,
                     double z)
Expands this box to include the point with specified coordinates.

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

expandBy

public void expandBy(float[] xyz)
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.

Parameters:
xyz - array of packed (x,y,z) coordinates.

expandBy

public void expandBy(float[] x,
                     float[] y,
                     float[] z)
Expands this box to include the points with specified coordinates.

Parameters:
x - array of x coordinates.
y - array of y coordinates.
z - array of z coordinates.

expandBy

public void expandBy(BoundingBox bb)
Expands this box to include the specified bounding box.

Parameters:
bb - the bounding box.

expandBy

public void expandBy(BoundingSphere bs)
Expands this box to include the specified bounding sphere.

Parameters:
bs - the bounding sphere.

contains

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

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

contains

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

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

contains

public boolean contains(BoundingBox bb)
Determines whether this box contains the specified bounding box.

Parameters:
bb - the bounding box.
Returns:
true, if this box contains the specified box; false, otherwise.

intersects

public boolean intersects(BoundingBox bb)
Determines whether this box intersects the specified bounding box.

Parameters:
bb - the bounding box.
Returns:
true, if intersects; false, otherwise.

empty

public static BoundingBox empty()
Returns a new empty bounding box.

Returns:
a new empty bounding box.

infinite

public static BoundingBox infinite()
Returns a new infinite bounding box.

Returns:
a new infinite bounding box.

toString

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