Skip to main content

Box3

3D axis-aligned bounding box (AABB) stored as [minX, minY, minZ, maxX, maxY, maxZ]. Functions modify the first argument in-place unless noted.


Functions Reference

Creation

FunctionReturnsDescription
box3_create(minVec, maxVec)ArrayCreates a new Box3. Defaults to empty inverted bounds.
box3_set(b, minVec, maxVec)-Sets bounds directly.
box3_clone(b)ArrayReturns a new copy of the box.
box3_copy(b, src)-Copies bounds from src to b.

Operations

FunctionReturnsDescription
box3_expand_by_point(b, p)-Expands the box to include the point.
box3_contains_point(b, p)booleanTrue if point is inside.
box3_intersects_box(b, b2)booleanTrue if boxes intersect.
box3_get_center(b, [out])ArrayWrites/returns center vector.
box3_get_size(b, [out])ArrayWrites/returns size vector.
box3_equals(b, b2)booleanTrue if all bounds equal.
box3_contains_box(b, b2)booleanTrue if b fully contains b2.
box3_clamp_point(b, p, out?)Vector3Clamps point to box boundaries.
box3_distance_to_point(b, p)numberEuclidean distance to the box (0 if inside).
box3_expand_by_scalar(b, s)-Expands bounds by scalar in all directions.
box3_expand_by_vector(b, v)-Expands bounds by vector [x,y,z] in both directions.
box3_is_empty(b)booleanTrue if any min > max.
box3_make_empty(b)-Sets to empty ([inf,inf,inf,-inf,-inf,-inf]).
box3_union(b, other)Box3Sets b to union of both boxes.
box3_intersect(b, other)Box3Sets b to overlap with other (or empty if none).
box3_translate(b, ox, oy, oz)-Moves box by offset.
box3_set_from_center_and_size(b, center, size)Box3Sets from center [x,y,z] and size [w,h,d].
box3_set_from_points(b, points)Box3Sets to enclose array of [x,y,z] points.
box3_apply_matrix4(b, m)Box3Transforms the 8 corners by m and recomputes bounds.
box3_get_bounding_sphere(b)SphereReturns minimal sphere enclosing the box.
box3_get_parameter(b, p, out?)Vector3Returns normalized coordinates within the box.
box3_intersects_plane(b, plane)booleanTrue if plane intersects box.
box3_intersects_sphere(b, sphere)booleanTrue if sphere intersects box.
box3_intersects_triangle(b, a, c, d)booleanApproximates intersection via triangle AABB overlap.

Usage Examples

var b = box3_create();
box3_set(b, -1, -2, -3, 4, 5, 6);

box3_expand_by_point(b, 10, 0, 0); // b.maxX becomes 10
var center = box3_get_center(b); // [ (minX+maxX)/2, ... ]