# Box3

Represents an axis-aligned bounding box (AABB) in 3D space.

## Code Example

``` const box = new v3d.Box3(); const mesh = new v3d.Mesh( new v3d.SphereGeometry(), new v3d.MeshBasicMaterial() ); // ensure the bounding box is computed for its geometry // this should be done only once (assuming static geometries) mesh.geometry.computeBoundingBox(); // ... // in the animation loop, compute the current bounding box with the world matrix box.copy(mesh.geometry.boundingBox).applyMatrix4(mesh.matrixWorld); ```

## Constructor

### Box3(min : Vector3, max : Vector3)

min — (optional) Vector3 representing the lower (x, y, z) boundary of the box. Default is `(+Infinity, +Infinity, +Infinity)`.
max — (optional) Vector3 representing the upper (x, y, z) boundary of the box. Default is `(-Infinity, -Infinity, -Infinity)`.

Creates a Box3 bounded by min and max.

## Properties

### # .isBox3 : Boolean

Read-only flag to check if a given object is of type Box3.

### # .min : Vector3

Vector3 representing the lower (x, y, z) boundary of the box.
Default is `(+Infinity, +Infinity, +Infinity)`.

### # .max : Vector3

Vector3 representing the upper (x, y, z) boundary of the box.
Default is `(-Infinity, -Infinity, -Infinity)`.

## Methods

### # .applyMatrix4(matrix : Matrix4) → this

matrix — The Matrix4 to apply.

Transforms this Box3 with the supplied matrix.

### # .clampPoint(point : Vector3, target : Vector3) → Vector3

pointVector3 to clamp.
target — the result will be copied into this Vector3.

Clamps the point within the bounds of this box.

### # .clone() → Box3

Returns a new Box3 with the same min and max as this one.

### # .containsBox(box : Box3) → Boolean

boxBox3 to test for inclusion.

Returns true if this box includes the entirety of box. If this and box are identical,
this function also returns true.

### # .containsPoint(point : Vector3) → Boolean

pointVector3 to check for inclusion.

Returns true if the specified point lies within or on the boundaries of this box.

### # .copy(box : Box3) → this

boxBox3 to copy.

Copies the min and max from box to this box.

### # .distanceToPoint(point : Vector3) → Float

pointVector3 to measure distance to.

Returns the distance from any edge of this box to the specified point. If the point lies inside of this box, the distance will be 0.

### # .equals(box : Box3) → Boolean

box — Box to compare with this one.

Returns true if this box and box share the same lower and upper bounds.

### # .expandByObject(object : Object3D, precise : Boolean) → this

objectObject3D to expand the box by.
precise — (optional) expand the bounding box as little as necessary at the expense of more computation. Default is `false`.

Expands the boundaries of this box to include object and its children, accounting for the object's, and children's, world transforms. The function may result in a larger box than strictly necessary (unless the precise parameter is set to true).

### # .expandByPoint(point : Vector3) → this

pointVector3 that should be included in the box.

Expands the boundaries of this box to include point.

### # .expandByScalar(scalar : Float) → this

scalar — Distance to expand the box by.

Expands each dimension of the box by scalar. If negative, the dimensions of the box will be contracted.

### # .expandByVector(vector : Vector3) → this

vectorVector3 to expand the box by.

Expands this box equilaterally by vector. The width of this box will be expanded by the x component of vector in both directions. The height of this box will be expanded by the y component of vector in both directions. The depth of this box will be expanded by the z component of `vector` in both directions.

### # .getBoundingSphere(target : Sphere) → Sphere

target — the result will be copied into this Sphere.

Gets a Sphere that bounds the box.

### # .getCenter(target : Vector3) → Vector3

target — the result will be copied into this Vector3.

Returns the center point of the box as a Vector3.

### # .getParameter(point : Vector3, target : Vector3) → Vector3

pointVector3.
target — the result will be copied into this Vector3.

Returns a point as a proportion of this box's width, height and depth.

### # .getSize(target : Vector3) → Vector3

target — the result will be copied into this Vector3.

Returns the width, height and depth of this box.

### # .intersect(box : Box3) → this

box — Box to intersect with.

Computes the intersection of this and box, setting the upper bound of this box to the lesser of the two boxes' upper bounds and the lower bound of this box to the greater of the two boxes' lower bounds. If there's no overlap, makes this box empty.

### # .intersectsBox(box : Box3) → Boolean

box — Box to check for intersection against.

Determines whether or not this box intersects box.

### # .intersectsPlane(plane : Plane) → Boolean

planePlane to check for intersection against.

Determines whether or not this box intersects plane.

### # .intersectsSphere(sphere : Sphere) → Boolean

sphereSphere to check for intersection against.

Determines whether or not this box intersects sphere.

### # .intersectsTriangle(triangle : Triangle) → Boolean

triangleTriangle to check for intersection against.

Determines whether or not this box intersects triangle.

### # .isEmpty() → Boolean

Returns `true` if this box includes zero points within its bounds.
Note that a box with equal lower and upper bounds still includes one point, the one both bounds share.

### # .makeEmpty() → this

Makes this box empty.

### # .scale(s : Vector3) → this

s — Scale vector.

Scales the bounding box by a given vector value.

### # .set(min : Vector3, max : Vector3) → this

minVector3 representing the lower (x, y, z) boundary of the box.
maxVector3 representing the upper (x, y, z) boundary of the box.

Sets the lower and upper (x, y, z) boundaries of this box.
Please note that this method only copies the values from the given objects.

### # .setFromArray(array : Array) → this

array — An array of position data that the resulting box will envelop.

Sets the upper and lower bounds of this box to include all of the data in `array`.

### # .setFromBufferAttribute(attribute : BufferAttribute) → this

attribute — A buffer attribute of position data that the resulting box will envelop.

Sets the upper and lower bounds of this box to include all of the data in attribute.

### # .setFromCenterAndSize(center : Vector3, size : Vector3) → this

center — Desired center position of the box.
size — Desired x, y and z dimensions of the box.

Centers this box on center and sets this box's width, height and depth to the values specified in size

### # .setFromObject(object : Object3D, precise : Boolean) → this

objectObject3D to compute the bounding box of.
precise — (optional) compute the smallest world-axis-aligned bounding box at the expense of more computation. Default is `false`.

Computes the world-axis-aligned bounding box of an Object3D (including its children), accounting for the object's, and children's, world transforms. The function may result in a larger box than strictly necessary.

### # .setFromPoints(points : Array) → this

points — Array of Vector3s that the resulting box will contain.

Sets the upper and lower bounds of this box to include all of the points in points.

### # .translate(offset : Vector3) → this

offset — Direction and distance of offset.

Adds offset to both the upper and lower bounds of this box, effectively moving this box offset units in 3D space.

### # .union(box : Box3) → this

box — Box that will be unioned with this box.

Computes the union of this box and box, setting the upper bound of this box to the greater of the two boxes' upper bounds and the lower bound of this box to the lesser of the two boxes' lower bounds.