y25.graphics
Class BoundingBox

java.lang.Object
  extended byy25.graphics.BoundingBox

public class BoundingBox
extends Object

Represents an axis-aligned bounding box in three dimensional space.

Note that an axis-aligned bounding box is fully specified by knowing the point with the smallest x,y,z-coordinates and the point with the biggest x,y,z-coordinates that still lies inside the bounding box.

A newly created bounding box does not bound anything and therefore it isCollapsed(). After one point has been added to the bounding box, it is no longer collapsed, since now it bounds something - the point. It has still no volume though and therefore it isEmpty(). As long as only points that lie on the same plane are added, the bounding box still isEmpty(). Only when the bounding box actually encompasses a region of 3D-space that has a volume, it is no longer empty.


Field Summary
protected  Point3D max
          The point with the biggest x,y,z-coordinates that is still inside the bounding box.
protected  Point3D min
          The point with the smallest x,y,z-coordinates that is still inside the bounding box.
 
Constructor Summary
BoundingBox()
          Creates a collapsed bounding box.
BoundingBox(BoundingBox bb)
          Creates a bounding box that is a copy of the passed bounding box.
BoundingBox(Point3D pmin, Point3D pmax)
          Creates a bounding box by specifying the points in 3D space with the smallest and biggest x,y,z-coordinates that are still inside the bounding box.
 
Method Summary
 BoundingBox addBorder(float size)
          Adds a border of the specified size around this bounding box.
 Point3D getCenter()
          Returns the center of this bounding box.
 Point3D getMax()
          Returns the point with the biggest x,y,z-coordinates that still lies inside the bounding box.
 Point3D getMin()
          Returns the point with the smallest x,y,z-coordinates that still lies inside the bounding box.
 float getRadius()
          Returns the radius of a bounding sphere that would encompass the entire bounding box if it was positioned at getCenter().
 BoundingBox include(BoundingBox bb)
          If necessary, enlarges this bounding box to also include the passed bounding box.
 BoundingBox include(Point3D p)
          If necessary, enlarges this bounding box to include the passed point.
 BoundingBox includeX(float x)
          If necessary, enlarges this bounding box to include at least one point that has the passed x-coordinate.
 BoundingBox includeY(float y)
          If necessary, enlarges this bounding box to include at least one point that has the passed y-coordinate.
 BoundingBox includeZ(float z)
          If necessary, enlarges this bounding box to include at least one point that has the passed z-coordinate.
 boolean isCollapsed()
          Returns true if this bounding box is collapsed, false otherwise.
 boolean isEmpty()
          Returns true if this bounding box has no volume, false otherwise.
 BoundingBox scale(float s)
          Scales the entire bounding box by the given scaling factor.
 BoundingBox set(BoundingBox bb)
          Sets this bounding box to the same extent as the passed bounding box.
 BoundingBox setCollapsed()
          Returns this boudning box to a collapsed state.
 String toString()
           
 BoundingBox translate(Vector3D v)
          Moves the entire bounding box by the given vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

min

protected Point3D min
The point with the smallest x,y,z-coordinates that is still inside the bounding box.


max

protected Point3D max
The point with the biggest x,y,z-coordinates that is still inside the bounding box.

Constructor Detail

BoundingBox

public BoundingBox()
Creates a collapsed bounding box.


BoundingBox

public BoundingBox(BoundingBox bb)
Creates a bounding box that is a copy of the passed bounding box.


BoundingBox

public BoundingBox(Point3D pmin,
                   Point3D pmax)
Creates a bounding box by specifying the points in 3D space with the smallest and biggest x,y,z-coordinates that are still inside the bounding box.

Method Detail

set

public BoundingBox set(BoundingBox bb)
Sets this bounding box to the same extent as the passed bounding box.

Returns a reference to this bounding box.


include

public BoundingBox include(BoundingBox bb)
If necessary, enlarges this bounding box to also include the passed bounding box.

If the passed bounding box is collapsed, calling this method has no effect.

Returns a reference to this bounding box.


include

public BoundingBox include(Point3D p)
If necessary, enlarges this bounding box to include the passed point.

Returns a reference to this bounding box.


includeX

public BoundingBox includeX(float x)
If necessary, enlarges this bounding box to include at least one point that has the passed x-coordinate.

Returns a reference to this bounding box.


includeY

public BoundingBox includeY(float y)
If necessary, enlarges this bounding box to include at least one point that has the passed y-coordinate.

Returns a reference to this bounding box.


includeZ

public BoundingBox includeZ(float z)
If necessary, enlarges this bounding box to include at least one point that has the passed z-coordinate.

Returns a reference to this bounding box.


getCenter

public Point3D getCenter()
Returns the center of this bounding box.


getMin

public Point3D getMin()
Returns the point with the smallest x,y,z-coordinates that still lies inside the bounding box.


getMax

public Point3D getMax()
Returns the point with the biggest x,y,z-coordinates that still lies inside the bounding box.


getRadius

public float getRadius()
Returns the radius of a bounding sphere that would encompass the entire bounding box if it was positioned at getCenter().


isCollapsed

public boolean isCollapsed()
Returns true if this bounding box is collapsed, false otherwise.


setCollapsed

public BoundingBox setCollapsed()
Returns this boudning box to a collapsed state.


isEmpty

public boolean isEmpty()
Returns true if this bounding box has no volume, false otherwise.

Note that a collapsed bounding box also has no volume, so true is returned in this case as well.


translate

public BoundingBox translate(Vector3D v)
Moves the entire bounding box by the given vector.

Returns a reference to this bounding box.


scale

public BoundingBox scale(float s)
Scales the entire bounding box by the given scaling factor.

Returns a reference to this bounding box.


addBorder

public BoundingBox addBorder(float size)
Adds a border of the specified size around this bounding box.

Returns a reference to this bounding box.


toString

public String toString()