OBB(center, halfSizes, rotation)

Class representing an oriented bounding box (OBB). Similar to an AABB, it's a rectangular block but with an arbitrary orientation. When using OBB#fromPoints, the implementation tries to provide a tight-fitting oriented bounding box. In many cases, the result is better than an AABB or bounding sphere but worse than a convex hull. However, it's more efficient to work with OBBs compared to convex hulls. In general, OBB's are a good compromise between performance and tightness.

new OBB(center, halfSizes, rotation)

Constructs a new OBB with the given values.

Parameters:
Name Type Description
center Vector3

The center of this OBB.

halfSizes Vector3

The half sizes of the OBB (defines its width, height and depth).

rotation Matrix3

The rotation of this OBB.

Author:

Members

center :Vector3

The center of this OBB.

halfSizes :Vector3

The half sizes of the OBB (defines its width, height and depth).

rotation :Matrix3

The rotation of this OBB.

Methods

clampPoint(point, result) → {Vector3}

Ensures the given point is inside this OBB and stores the result in the given vector.

Reference: Closest Point on OBB to Point in Real-Time Collision Detection by Christer Ericson (chapter 5.1.4)

Parameters:
Name Type Description
point Vector3

A point in 3D space.

result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

clone() → {OBB}

Creates a new OBB and copies all values from this OBB.

Returns:
OBB -

A new OBB.

containsPoint(point) → {Boolean}

Returns true if the given point is inside this OBB.

Parameters:
Name Type Description
point Vector3

A point in 3D space.

Returns:
Boolean -

Whether the given point is inside this OBB or not.

copy(obb) → {OBB}

Copies all values from the given OBB to this OBB.

Parameters:
Name Type Description
obb OBB

The OBB to copy.

Returns:
OBB -

A reference to this OBB.

equals(obb) → {Boolean}

Returns true if the given OBB is deep equal with this OBB.

Parameters:
Name Type Description
obb OBB

The OBB to test.

Returns:
Boolean -

The result of the equality test.

fromAABB(aabb) → {OBB}

Computes the OBB from an AABB.

Parameters:
Name Type Description
aabb AABB

The AABB.

Returns:
OBB -

A reference to this OBB.

fromJSON(json) → {OBB}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
OBB -

A reference to this OBB.

fromPoints(points) → {OBB}

Computes the minimum enclosing OBB for the given set of points. The method is an implementation of Collision Queries using Oriented Bounding Boxes by Stefan Gottschalk. According to the dissertation, the quality of the fitting process varies from the respective input. This method uses the best approach by computing the covariance matrix based on the triangles of the convex hull (chapter 3.4.3).

However, the implementation is susceptible to regular polygons like cubes or spheres. For such shapes, it's recommended to verify the quality of the produced OBB. Consider to use an AABB or bounding sphere if the result is not satisfying.

Parameters:
Name Type Description
points Array.<Vector3>

An array of 3D vectors representing points in 3D space.

Returns:
OBB -

A reference to this OBB.

getSize(result) → {Vector3}

Computes the size (width, height, depth) of this OBB and stores it into the given vector.

Parameters:
Name Type Description
result Vector3

The result vector.

Returns:
Vector3 -

The result vector.

intersectsAABB(aabb) → {Boolean}

Returns true if the given AABB intersects this OBB.

Parameters:
Name Type Description
aabb AABB

The AABB to test.

Returns:
Boolean -

The result of the intersection test.

intersectsBoundingSphere(sphere) → {Boolean}

Returns true if the given bounding sphere intersects this OBB.

Parameters:
Name Type Description
sphere BoundingSphere

The bounding sphere to test.

Returns:
Boolean -

The result of the intersection test.

intersectsOBB(obb, epsilon) → {Boolean}

Returns true if the given OBB intersects this OBB.

Reference: OBB-OBB Intersection in Real-Time Collision Detection by Christer Ericson (chapter 4.4.1)

Parameters:
Name Type Description
obb OBB

The OBB to test.

epsilon Number

The epsilon (tolerance) value.

Returns:
Boolean -

The result of the intersection test.

intersectsPlane(plane) → {Boolean}

Returns true if the given plane intersects this OBB.

Reference: Testing Box Against Plane in Real-Time Collision Detection by Christer Ericson (chapter 5.2.3)

Parameters:
Name Type Description
plane Plane

The plane to test.

Returns:
Boolean -

The result of the intersection test.

set(center, halfSizes, rotation) → {OBB}

Sets the given values to this OBB.

Parameters:
Name Type Description
center Vector3

The center of this OBB

halfSizes Vector3

The half sizes of the OBB (defines its width, height and depth).

rotation Matrix3

The rotation of this OBB.

Returns:
OBB -

A reference to this OBB.

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.