We have a box in 3D space defined by it's position, size and rotation. How can i find the smallest box that contains that box, but has a new rotation? I know this is a really bad description of the problem, i just can't describe it any better, i'm really bad at vector maths. i tried to draw a little scene in blender to clarify what i mean. here the white box is the original, and the red one is the one i want. the lines are the Forward vectors of these object. Sorry for the terrible formulation and thanks for reading :)
2026-03-29 08:13:23.1774772003
On
Rotated Box Constraints
92 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
A 3D rotation is usually expressed by a $3\times3$ matrix, such as that obtained via the Euler angles. See https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions.
When you have such a matrix, you can rotate any point around the origin, by a matrix/vector product.
The $8$ vertices of your box will have coordinates $(\pm a,\pm b,\pm c)$. Transform them using the matrix. The the new bounding box will be delimited by the minimum and maximum $x, y$ and $z$ values among those you just computed.
I don't know how your box is described, but at least one way is that you know the "forward" vector of the box (i.e., a length-one (or unit) vector that points parallel to one edge of the box) and you know two other vectors that are parallel to the other two edges of the box. If you call these $v_1, v_2, v_3$, and write them as columns, and put them into a matrix $M$, then you have $$ M^t M = I $$ because they're mutually perpendicular and are all unit vectors.
Let's put the corresponding half-edge lengths into a matrix $S$: $$ S = \begin{bmatrix} s_1 & 0 & 0 \\ 0 & s_2 & 0 \\ 0 & 0 & s_3 \end{bmatrix} $$ where $2s_1$ is the length of the cube-edge corresponding to $v_1$, etc. Then the matrix $$ T = MS $$ contains three column-vectors that each represent one side of the (white) cube.
In fact, if you apply $MS$ to each point of the b-unit cube $-1 \le x,y,z \le 1$, you'll get a cube that looks just like your white cube (except that it's centered at the origin, but not rotated or scaled at all).
For your target cube (the red one), you know three other unit edge-vectors, $w_1, w_2, w_3$, which we can write as the columns of a matrix $K$, but you don't know the half-edge-lengths, $r_1, r_2, r_3$, which we can place in a corresponding matrix $R$.
What you DO know is that if you compute $Tu$ for any vector $u$ in the bi-unit cube, you get a point in the white cube, and that if you then transform this to red-cube coordinates, by $$ v = (KR)^{-1} T u = R^{-1} K^t T u $$ then we must get a point inside the bi-unit cube, i.e., all coordinates of $v$ must be between $-1$ and $1$.
We can rewrite this equation in the form $$ Rv = K^t T u $$ Now the largest coordinates for points on the white cube are at the vertices, so you can compute the $8$ vectors $K^t Tu$ for $u = (\pm 1, \pm 1, \pm 1)$, and look at the $x$ coordinates of all those points, which might range from, say, $-3.7$ to $3.7$. If that happens, then you know that $r_1$ must be $3.7$.
In fact, you can define $$ r_1 = \max( v_x ) \\ r_2 = \max( v_y ) \\ r_3 = \max( v_z ) $$ where $v = \begin{bmatrix} v_x \\ v_y \\v_z \end{bmatrix}$ ranges over all the vectors $K^t Tu$, where $y = (\pm 1, \pm 1, \pm 1)$. And this turns out to give the result that $r_1$ is the sum of the absolute values of the entries of the first row of $K^t T$, $r_2$ is the sum of the absolute values of the entries in the second row, and $r_3$ is the sum of the absolute values of the entries of the third row.
When you double each of these, you get the edge-lengths for the red cube.