A Couple 3D AABB Tricks

https://news.ycombinator.com/rss Hits: 3
Summary

A Couple 3D AABB Tricks published on Dec 23 2025 Axis-aligned bounding boxes are ubiquitous in 3D programming, typically used as stand-ins for some other shape (for example, for purposes of collision detection or determining visibility). The main characteristic of an AABB is that it is, well, axis-aligned: its sides line up with the coordinate axes. Over the years I've encountered a couple useful tricks for working with them that I want to share here. None of these are new. AABB Representation The first trick has to do with AABB representation. In some learning materials, I've seen AABB represented as a point (usually the centroid) plus the dimensions of the box: struct aabb { float centroid[3]; float width_height_depth[3]; }; Sometimes the width/height/depth are stored divided by 2, but you get the idea. A better (in my opinion) representation is storing the min and max values for the x, y and z coordinates within the AABB: struct aabb { float x_minmax[2]; float y_minmax[2]; float z_minmax[2]; }; Incidentally, this representation is used in Peter Shirley's raytracing series. A slighly different version of this is just storing min and max corners of the box. Those "minmax" regions are also referred to as "slabs", because the AABB can be thought of as the intersection between three "slabs" of 3D space (think of a slab as an infinite region bounded by two parallel 3D planes). This representation occupies the same amount of memory as the point-plus-dimensions one, but I think it's nicer because many operations call for computing those boundary values anyway. For example, computing the bounding box that encloses any two given bounding boxes is extremely trivial with this representation, whereas the point-plus-dimensions one requires some extra computation: aabb enclosing_aabb(const aabb& b0, const aabb& b1) { return aabb { {std::min(b0.x_minmax[0], b1.x_minmax[0]), std::max(b0.x_minmax[1], b1.x_minmax[1])}, {std::min(b0.y_minmax[0], b1.y_minmax[0]), std::max(b0.y_minmax...

First seen: 2026-01-12 19:02

Last seen: 2026-01-12 21:02