Fr0stBit
Fr0stBit

Reputation: 1485

Can axis aligned bounding boxes be recalculated after rotation of object using trigonometry?

I have my axis aligned bounding boxes expressed as 2 3D vectors, one holding the left-down-back point (minimum) and one the right-up-front point (maximum).

After rotating the object in any direction, the aabb that encompasses it must, be recalculated to fit good. Take this image for example:

Pretsel

Can this be calculated using the two starting points that i have and the angle + direction of the rotation(s)? If so how? What is the most efficient way?

P.S. I am using glm for my math, so any ready way to do this using glm would be really useful!

Upvotes: 2

Views: 1226

Answers (2)

Kevin
Kevin

Reputation: 76184

To back up Nicol Bolas' answer with a visual proof, you can't find the smallest AABB of an object after rotation if all you know about the object is the size of its unrotated bounding box. Consider the case of two objects with identical AABBs:

enter image description here

The happy circle's bounding box is identical to the sad rectangle's. Now, rotate both of them 45 degrees. Are their new bounding boxes identical?

enter image description here

No - the sad rectangle's bounding box is a bit wider and a lot shorter, while the happy circle's box hasn't changed at all! So just knowing the coordinates of the bounding box's corners isn't sufficient to find its rotated counterpart.

Upvotes: 3

Nicol Bolas
Nicol Bolas

Reputation: 473174

Can you calculate a new AABB from a rotation with an existing AABB? Yes. It involves transforming all 8 points, then computing an AABB from that. You find the maximum extents of each dimension, the largest/smallest value in each of the 3 components of each of the 8 points.

However, that won't give you the effect of the picture you show. The reason being rather obvious. The picture is recomputing the AABB from the rotation of the actual mesh it encompass. Whereas you're wanting to recompute it from rotating a rectangle.

The box-based recomputation will always be bigger than is strictly necessary. Recomputing the AABB from the actual mesh will produce a tighter AABB.

Upvotes: 5

Related Questions