Package toxi.geom

Class AABB

All Implemented Interfaces:
Comparable<ReadonlyVec3D>, ReadonlyVec3D, Shape3D
Direct Known Subclasses:
PointOctree

public class AABB extends Vec3D implements Shape3D
Axis-aligned bounding box with basic intersection features for Ray, AABB and Sphere classes.
  • Constructor Details

    • AABB

      public AABB()
    • AABB

      public AABB(AABB box)
      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

      public AABB(ReadonlyVec3D pos, float extent)
      Creates a new instance from centre point and uniform extent in all directions.
      Parameters:
      pos -
      extent -
    • AABB

      public AABB(ReadonlyVec3D pos, ReadonlyVec3D 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 Details

    • 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
    • getBoundingBox

      public static final AABB getBoundingBox(List<? extends Vec3D> points)
      Factory method, computes & returns the bounding box for the given list of points.
      Parameters:
      points -
      Returns:
      bounding rect
    • containsPoint

      public boolean containsPoint(ReadonlyVec3D p)
      Description copied from interface: Shape3D
      Checks if the point is within the given shape/volume.
      Specified by:
      containsPoint in interface Shape3D
      Returns:
      true, if inside
    • copy

      public AABB copy()
      Description copied from interface: ReadonlyVec3D
      Copy.
      Specified by:
      copy in interface ReadonlyVec3D
      Overrides:
      copy in class Vec3D
      Returns:
      a new independent instance/copy of a given vector
    • getBoundingSphere

      public Sphere getBoundingSphere()
    • 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(ReadonlyVec3D) for those purposes)
      Returns:
      box size
    • getMax

      public final Vec3D getMax()
    • getMin

      public final Vec3D getMin()
    • getNormalForPoint

      public Vec3D getNormalForPoint(ReadonlyVec3D p)
    • growToContainPoint

      public AABB growToContainPoint(ReadonlyVec3D p)
      Adjusts the box size and position such that it includes the given point.
      Parameters:
      p - point to include
      Returns:
      itself
    • 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
    • intersectsTriangle

      public boolean intersectsTriangle(Triangle3D tri)
    • 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:
    • set

      public AABB set(ReadonlyVec3D v)
      Updates the position of the box in space and calls updateBounds() immediately
      Overrides:
      set in class Vec3D
      See Also:
    • setExtent

      public AABB setExtent(ReadonlyVec3D extent)
      Updates the size of the box and calls updateBounds() immediately
      Parameters:
      extent - new box size
      Returns:
      itself, for method chaining
    • toMesh

      public Mesh3D toMesh()
    • toMesh

      public Mesh3D toMesh(Mesh3D mesh)
    • toString

      public String toString()
      Overrides:
      toString in class Vec3D
    • union

      public AABB union(AABB box)
    • 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