Package toxi.geom
Class AABB
java.lang.Object
toxi.geom.Vec3D
toxi.geom.AABB
- All Implemented Interfaces:
Comparable<ReadonlyVec3D>
,ReadonlyVec3D
,Shape3D
- Direct Known Subclasses:
PointOctree
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
-
Constructor Summary
ConstructorDescriptionAABB()
AABB
(float extent) Creates a new box of the given size at the world origin.Creates an independent copy of the passed in boxAABB
(ReadonlyVec3D pos, float extent) Creates a new instance from centre point and uniform extent in all directions.AABB
(ReadonlyVec3D pos, ReadonlyVec3D extent) Creates a new instance from centre point and extent -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if the point is within the given shape/volume.copy()
Copy.static final AABB
fromMinMax
(Vec3D min, Vec3D max) Creates a new instance from two vectors specifying opposite corners of the boxstatic final AABB
getBoundingBox
(List<? extends Vec3D> points) Factory method, computes & returns the bounding box for the given list of points.final Vec3D
Returns the current box size as new Vec3D instance (updating this vector will NOT update the box size! UsesetExtent(ReadonlyVec3D)
for those purposes)final Vec3D
getMax()
final Vec3D
getMin()
Adjusts the box size and position such that it includes the given point.boolean
intersectsBox
(AABB box) Checks if the box intersects the passed in one.intersectsRay
(Ray3D ray, float minDist, float maxDist) Calculates intersection with the given ray between a certain distance interval.boolean
boolean
intersectsSphere
(Vec3D c, float r) boolean
set
(float x, float y, float z) Updates the position of the box in space and callsupdateBounds()
immediatelyset
(ReadonlyVec3D v) Updates the position of the box in space and callsupdateBounds()
immediatelysetExtent
(ReadonlyVec3D extent) Updates the size of the box and callsupdateBounds()
immediatelytoMesh()
toString()
final AABB
Updates the min/max corner points of the box.Methods inherited from class toxi.geom.Vec3D
abs, add, add, add, addSelf, addSelf, addSelf, angleBetween, angleBetween, clear, compareTo, constrain, constrain, cross, cross, crossInto, crossSelf, distanceTo, distanceToSquared, dot, dot, equals, equals, equalsWithTolerance, floor, frac, fromXYTheta, fromXZTheta, fromYZTheta, getAbs, getCartesian, getClosestAxis, getComponent, getComponent, getConstrained, getFloored, getFrac, getInverted, getLimited, getMapped, getNormalized, getNormalizedTo, getReciprocal, getReflected, getRotatedAroundAxis, getRotatedX, getRotatedY, getRotatedZ, getRoundedTo, getSignum, getSpherical, hashCode, headingXY, headingXZ, headingYZ, immutable, interpolateTo, interpolateTo, interpolateTo, interpolateTo, interpolateToSelf, interpolateToSelf, invert, isInAABB, isInAABB, isMajorAxis, isZeroVector, jitter, jitter, jitter, jitter, jitter, jitter, limit, magnitude, magSquared, max, maxSelf, min, minSelf, modSelf, modSelf, normalize, normalizeTo, randomVector, randomVector, reciprocal, reflect, rotateAroundAxis, rotateX, rotateY, rotateZ, roundTo, scale, scale, scale, scale, scaleSelf, scaleSelf, scaleSelf, scaleSelf, set, setComponent, setComponent, setX, setXY, setY, setZ, shuffle, signum, snapToAxis, sub, sub, sub, subSelf, subSelf, subSelf, to2DXY, to2DXZ, to2DYZ, to4D, to4D, toArray, toArray4, toCartesian, toSpherical, x, y, z
-
Constructor Details
-
AABB
public AABB() -
AABB
Creates an independent copy of the passed in box- Parameters:
box
-
-
AABB
public AABB(float extent) Creates a new box of the given size at the world origin.- Parameters:
extent
-
-
AABB
Creates a new instance from centre point and uniform extent in all directions.- Parameters:
pos
-extent
-
-
AABB
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 Details
-
fromMinMax
Creates a new instance from two vectors specifying opposite corners of the box- Parameters:
min
- first corner pointmax
- second corner point- Returns:
- new AABB with centre at the half point between the 2 input vectors
-
getBoundingBox
Factory method, computes & returns the bounding box for the given list of points.- Parameters:
points
-- Returns:
- bounding rect
-
containsPoint
Description copied from interface:Shape3D
Checks if the point is within the given shape/volume.- Specified by:
containsPoint
in interfaceShape3D
- Returns:
- true, if inside
-
copy
Description copied from interface:ReadonlyVec3D
Copy.- Specified by:
copy
in interfaceReadonlyVec3D
- Overrides:
copy
in classVec3D
- Returns:
- a new independent instance/copy of a given vector
-
getBoundingSphere
-
getExtent
Returns the current box size as new Vec3D instance (updating this vector will NOT update the box size! UsesetExtent(ReadonlyVec3D)
for those purposes)- Returns:
- box size
-
getMax
-
getMin
-
getNormalForPoint
-
growToContainPoint
Adjusts the box size and position such that it includes the given point.- Parameters:
p
- point to include- Returns:
- itself
-
intersectsBox
Checks if the box intersects the passed in one.- Parameters:
box
- box to check- Returns:
- true, if boxes overlap
-
intersectsRay
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 rayminDist
-maxDist
-- Returns:
- intersection point on the bounding box (only the first is returned) or null if no intersection
-
intersectsSphere
-
intersectsSphere
- Parameters:
c
- sphere centrer
- sphere radius- Returns:
- true, if AABB intersects with sphere
-
intersectsTriangle
-
set
-
set
Updates the position of the box in space and callsupdateBounds()
immediately -
set
Updates the position of the box in space and callsupdateBounds()
immediately -
setExtent
Updates the size of the box and callsupdateBounds()
immediately- Parameters:
extent
- new box size- Returns:
- itself, for method chaining
-
toMesh
-
toMesh
-
toString
-
union
-
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
-