toxi.geom
Class AABB

java.lang.Object
  extended by toxi.geom.Vec3D
      extended by toxi.geom.AABB
All Implemented Interfaces:
java.lang.Comparable<Vec3D>
Direct Known Subclasses:
PointOctree

public class AABB
extends Vec3D

Axis-aligned bounding box with basic intersection features for Ray, AABB and Sphere classes.


Nested Class Summary
 
Nested classes/interfaces inherited from class toxi.geom.Vec3D
Vec3D.Axis
 
Field Summary
 
Fields inherited from class toxi.geom.Vec3D
MAX_VALUE, MIN_VALUE, x, X_AXIS, y, Y_AXIS, z, Z_AXIS, ZERO
 
Constructor Summary
AABB()
           
AABB(AABB box)
          Creates an independent copy of the passed in box
AABB(Vec3D pos, Vec3D extent)
          Creates a new instance from centre point and extent
 
Method Summary
 AABB copy()
          Copy.
static AABB fromMinMax(Vec3D min, Vec3D max)
          Creates a new instance from two vectors specifying opposite corners of the box
 Vec3D getExtent()
          Returns the current box size as new Vec3D instance (updating this vector will NOT update the box size! Use setExtent(Vec3D) for those purposes)
 Vec3D getMax()
           
 Vec3D getMin()
           
 boolean intersectsBox(AABB box)
          Checks if the box intersects the passed in one.
 Vec3D intersectsRay(Ray3D ray, float minDist, float maxDist)
          Calculates intersection with the given ray between a certain distance interval.
 boolean intersectsSphere(Sphere s)
           
 boolean intersectsSphere(Vec3D c, float r)
           
 float maxX()
          Deprecated. 
 float maxY()
          Deprecated. 
 float maxZ()
          Deprecated. 
 float minX()
          Deprecated. 
 float minY()
          Deprecated. 
 float minZ()
          Deprecated. 
 AABB set(AABB box)
           
 Vec3D set(float x, float y, float z)
          Updates the position of the box in space and calls updateBounds() immediately
 AABB set(Vec3D v)
          Updates the position of the box in space and calls updateBounds() immediately
 AABB setExtent(Vec3D extent)
          Updates the size of the box and calls updateBounds() immediately
 TriangleMesh toMesh()
           
 TriangleMesh toMesh(java.lang.String name)
           
 java.lang.String toString()
           
 AABB updateBounds()
          Updates the min/max corner points of the box.
 
Methods inherited from class toxi.geom.Vec3D
abs, add, add, addSelf, addSelf, angleBetween, angleBetween, clear, closestPointOnLine, compareTo, constrain, constrain, cross, crossInto, crossSelf, distanceTo, distanceToSquared, dot, equals, equalsWithTolerance, floor, frac, fromXYTheta, fromXZTheta, fromYZTheta, getAbs, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getNormalized, getNormalizedTo, getReciprocal, getRotatedAroundAxis, getRotatedX, getRotatedY, getRotatedZ, getSignum, hashCode, headingXY, headingXZ, headingYZ, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInAABB, isInAABB, isZeroVector, jitter, jitter, jitter, limit, magnitude, magSquared, max, maxSelf, min, minSelf, modSelf, modSelf, normalize, normalizeTo, randomVector, randomVector, reciprocal, rotateAroundAxis, rotateX, rotateY, rotateZ, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, setComponent, setXY, signum, sub, sub, subSelf, subSelf, to2DXY, to2DXZ, to2DYZ, toArray, toCartesian, toSpherical
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AABB

public AABB()

AABB

public AABB(AABB box)
Creates an independent copy of the passed in box

Parameters:
box -

AABB

public AABB(Vec3D pos,
            Vec3D extent)
Creates a new instance from centre point and extent

Parameters:
pos -
extent - box dimensions (the box will be double the size in each direction)
Method Detail

fromMinMax

public static final AABB fromMinMax(Vec3D min,
                                    Vec3D max)
Creates a new instance from two vectors specifying opposite corners of the box

Parameters:
min - first corner point
max - second corner point
Returns:
new AABB with centre at the half point between the 2 input vectors

copy

public AABB copy()
Description copied from class: Vec3D
Copy.

Overrides:
copy in class Vec3D
Returns:
a new independent instance/copy of a given vector

getExtent

public final Vec3D getExtent()
Returns the current box size as new Vec3D instance (updating this vector will NOT update the box size! Use setExtent(Vec3D) for those purposes)

Returns:
box size

getMax

public final Vec3D getMax()

getMin

public final Vec3D getMin()

intersectsBox

public boolean intersectsBox(AABB box)
Checks if the box intersects the passed in one.

Parameters:
box - box to check
Returns:
true, if boxes overlap

intersectsRay

public Vec3D intersectsRay(Ray3D ray,
                           float minDist,
                           float maxDist)
Calculates intersection with the given ray between a certain distance interval. Ray-box intersection is using IEEE numerical properties to ensure the test is both robust and efficient, as described in: Amy Williams, Steve Barrus, R. Keith Morley, and Peter Shirley: "An Efficient and Robust Ray-Box Intersection Algorithm" Journal of graphics tools, 10(1):49-54, 2005

Parameters:
ray - incident ray
minDist -
maxDist -
Returns:
intersection point on the bounding box (only the first is returned) or null if no intersection

intersectsSphere

public boolean intersectsSphere(Sphere s)

intersectsSphere

public boolean intersectsSphere(Vec3D c,
                                float r)
Parameters:
c - sphere centre
r - sphere radius
Returns:
true, if AABB intersects with sphere

maxX

@Deprecated
public final float maxX()
Deprecated. 


maxY

@Deprecated
public final float maxY()
Deprecated. 


maxZ

@Deprecated
public final float maxZ()
Deprecated. 


minX

@Deprecated
public final float minX()
Deprecated. 


minY

@Deprecated
public final float minY()
Deprecated. 


minZ

@Deprecated
public final float minZ()
Deprecated. 


set

public AABB set(AABB box)

set

public Vec3D set(float x,
                 float y,
                 float z)
Updates the position of the box in space and calls updateBounds() immediately

Overrides:
set in class Vec3D
Parameters:
x - the x
y - the y
z - the z
Returns:
itself
See Also:
Vec3D.set(float, float, float)

set

public AABB set(Vec3D v)
Updates the position of the box in space and calls updateBounds() immediately

Overrides:
set in class Vec3D
Parameters:
v - vector to be copied
Returns:
itself
See Also:
Vec3D.set(toxi.geom.Vec3D)

setExtent

public AABB setExtent(Vec3D extent)
Updates the size of the box and calls updateBounds() immediately

Parameters:
extent - new box size
Returns:
itself, for method chaining

toMesh

public TriangleMesh toMesh()

toMesh

public TriangleMesh toMesh(java.lang.String name)

toString

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

updateBounds

public final AABB updateBounds()
Updates the min/max corner points of the box. MUST be called after moving the box in space by manipulating the public x,y,z coordinates directly.

Returns:
itself