de.jreality.util
Class Rectangle3D

java.lang.Object
  extended by de.jreality.util.Rectangle3D

public class Rectangle3D
extends java.lang.Object

A Rectangle3D represents a rectangular parallelopiped in three dimensional space: a "box".

It exists primarily to provide bounding boxes for 3D geometry.

Author:
Charles Gunn
See Also:
TODO: add dirty flag to avoid unnecessary recalculation of extent and center

Field Summary
static Rectangle3D EMPTY_BOX
           
static Rectangle3D unitCube
           
 
Constructor Summary
Rectangle3D()
           
Rectangle3D(double[][] vlist)
           
Rectangle3D(double w, double h, double d)
           
 
Method Summary
 void add(double d)
           
 Rectangle3D computeFromVectorList(double[][] vlist)
          Receiver configures himself as bounding box of the vertices in the list vlist.
 java.awt.geom.Rectangle2D convertToRectangle2D(java.awt.geom.Rectangle2D rec)
          Project this box onto its first two dimensions
 void copyInto(Rectangle3D bb)
           
 double[][] getBounds()
          Get the two opposite corners of this box (min(x,y,z) and max(x,y,z)).
 double[][] getBounds(double[][] store)
           
 double[] getCenter()
          Get the center of this box.
 double[] getCenter(double[] store)
           
 double[] getExtent()
          Get the dimensions of the box (length, width, depth).
 double[] getExtent(double[] store)
           
 double getMaxExtent()
           
 double getMaxX()
           
 double getMaxY()
           
 double getMaxZ()
           
 double getMinX()
           
 double getMinY()
           
 double getMinZ()
           
 void initialize()
           
 boolean isEmpty()
           
 void scale(double d)
           
 void setBounds(double[][] b)
          Get the two opposite corners of this box (min(x,y,z) and max(x,y,z)).
 java.lang.String toString()
           
 Rectangle3D transformByMatrix(Rectangle3D target, double[] aTransform)
          Transform a bounding box by a matrix.
 Rectangle3D unionWith(Rectangle3D aBound, Rectangle3D target)
          Finds the union of the receiver and aBound, places result in target and returns it.
 void update()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_BOX

public static final Rectangle3D EMPTY_BOX

unitCube

public static final Rectangle3D unitCube
Constructor Detail

Rectangle3D

public Rectangle3D()

Rectangle3D

public Rectangle3D(double w,
                   double h,
                   double d)

Rectangle3D

public Rectangle3D(double[][] vlist)
Method Detail

initialize

public void initialize()

copyInto

public void copyInto(Rectangle3D bb)

toString

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

isEmpty

public boolean isEmpty()

update

public void update()

transformByMatrix

public Rectangle3D transformByMatrix(Rectangle3D target,
                                     double[] aTransform)
Transform a bounding box by a matrix. The corners of the box are transformed and the bounding box of the resulting 8 vertices is computed. If flag is true, then return a new instance containing the result, else overwrite this.

Parameters:
aTransform -
copyflag -
Returns:

computeFromVectorList

public Rectangle3D computeFromVectorList(double[][] vlist)
Receiver configures himself as bounding box of the vertices in the list vlist. The vectors can be either 3-vectors or homogeneous 4-vectors. In the latter case the input vectors are dehomogenized before the bounds are calculated.

Parameters:
vlist -
Returns:

unionWith

public Rectangle3D unionWith(Rectangle3D aBound,
                             Rectangle3D target)
Finds the union of the receiver and aBound, places result in target and returns it. If target is null, allocates new instance. Behaves correctly if either or both of union-ands are empty.

Parameters:
aBound -
target -
Returns:

getCenter

public double[] getCenter()
Get the center of this box.

Returns:
double[3]

getExtent

public double[] getExtent()
Get the dimensions of the box (length, width, depth).

Returns:
double[3]

getMaxExtent

public double getMaxExtent()

convertToRectangle2D

public java.awt.geom.Rectangle2D convertToRectangle2D(java.awt.geom.Rectangle2D rec)
Project this box onto its first two dimensions

Parameters:
rec -
Returns:

getBounds

public double[][] getBounds()
Get the two opposite corners of this box (min(x,y,z) and max(x,y,z)).

Returns:
double[2][3]

setBounds

public void setBounds(double[][] b)
Get the two opposite corners of this box (min(x,y,z) and max(x,y,z)).


getMinX

public double getMinX()

getMaxX

public double getMaxX()

getMinY

public double getMinY()

getMaxY

public double getMaxY()

getMinZ

public double getMinZ()

getMaxZ

public double getMaxZ()

getCenter

public double[] getCenter(double[] store)

getExtent

public double[] getExtent(double[] store)

getBounds

public double[][] getBounds(double[][] store)
Parameters:
store - double[2][3]
Returns:

scale

public void scale(double d)

add

public void add(double d)