# Determine the length of the rod that can be inscribed in a cuboid

Question You have a cuboid of dimensions $$2a \times 2b \times 2c$$. I want the find the (maximum) length of the right circular cylindrical rod of radius $$r$$, that can inscribed in the cuboid.

Use whatever means, analytic or numerical, to find this length.

Note: A similar question concerning inscribing a square bar in a cuboid is addressed here.

My initial thoughts: We have to find the direction of the axis of the cylinder (the rod), and with an assumed length, we have the base (which is of known radius) touching the three adjacent intersecting faces of the cuboid near the end the of the rod. The unknowns here are spherical coordinates angles $$\theta$$ and $$\phi$$ specifying the direction of the axis, and in addition to that, the length of the rod. That's it, only three unknowns.

To that end, let the cuboid be centered at the origin, its faces that intersect in the first octant at $$x = a , y = b , z = c$$. Let the length of the cylinder be $$L = 2 \ell$$. The unit vector direction of the axis of cylinder which passes through the center of the cuboid (the origin) can be parameterized as follows

$$A = ( \sin \theta \cos \phi, \sin \theta \sin \phi, \cos \theta )$$

Two vectors that are orthogonal to $$A$$ are

$$u_1 = (\cos \theta \cos \phi, \cos \theta \sin \phi, - \sin \theta)$$

$$u_2 = (- \sin \phi, \cos \phi, 0 )$$

The top base of the cylinder is described by

$$P(t) = \ell A + r u_1 \cos t + r u_2 \sin t$$

And we want this circle to be tangent to the plane $$x = a$$, therefore, we want $$P_x(t) = \ell A_x + r u_{1x} \cos t + r u_{2x} \sin t$$ to have a single solution to $$P_x(t) = a$$

This implies that

$$a - \ell \sin \theta \cos \phi = r \sqrt{ \cos^2 \theta \cos^2 \phi + \sin^2 \phi }$$

Similarly for the other two faces, we have

$$b - \ell \sin \theta \sin \phi = r \sqrt{ \cos^2 \theta \sin^2 \phi + \cos^2 \phi}$$

and

$$c - \ell \cos \theta = r \sin \theta$$

This is a system of $$3$$ (nonlinear) equations in the three unknowns $$\theta, \phi, \ell$$. They can be solved numerically quite easily using the well-known Newton-Raphson multi-variate method, provided that you have a good initial guess of the unknowns vector $$X = [\theta, \phi, \ell ]$$.

This is what I have as a answer to this question. I appreciate other answers, or comments on the question and the attempted answer.

This problem can be solved easily with a minimization procedure.

By symmetry, the rod central axis should pass by the point $$q_0 = (a,b,c)$$. Now let be

$$\matrix{ p_0 = (x_0,y_0,z_0) & \text{inferior rod basis center}\\ p_1 = (0,y_1,z_1) & \text{inferior rod basis tangency point with plane } YZ\\ p_2 = (x_2,0,z_2) & \text{inferior rod basis tangency point with plane } XZ\\ p_3 = (x_3,y_3,0) & \text{inferior rod basis tangency point with plane } XY\\ \vec n = q_0 - p_0 & \text{rod semi-axis vector} }$$

then we have the constraints

$$\mathcal{C} = \cases{ \|p_0 - p_1\| = \|p_0-p_2\| = \|p_0-p_3\| = r\\ (p_0-p_1)\cdot \vec n = (p_0-p_2)\cdot \vec n = (p_0-p_3)\cdot \vec n = 0\\ x_0>0,y_0>0,z_0 > 0,y_1>0,z_1>0,x_2>0,z_2>0,x_3>0,y_3>0 }$$

and then

$$\{x_0^*,y_0^*,z_0^*,y_1^*,z_1^*,x_2^*,z_2^*,x_3^*,y_3^*\}=\arg\min_{x_0,y_0,z_0,y_1,z_1,x_2,z_2,x_3,y_3}\|\vec n\|\ \ \text{s. t.}\ \ \ \mathcal{C}$$

Follows a MATHEMATICA script which solves that

Clear[u, v, n]
parms = {a -> 20/2, b -> 30/2, c -> 40/2, r -> 5, uz -> 0};
q0 = {a, b, c};
p0 = {x0, y0, z0};
n = q0 - p0;
p1 = {0, y1, z1};
p2 = {x2, 0, z2};
p3 = {x3, y3, 0};
equs = {(p0 - p1) . (p0 - p1) - r^2, (p0 - p2) . (p0 - p2) - r^2, (p0 - p3) . (p0 - p3) - r^2, (p0 - p1) . n, (p0 - p2) . n, (p0 - p3) . n};
vars = {x0, y0, z0, y1, z1, x2, z2, x3, y3};
obj = Join[{n . n}, Join[Thread[equs == 0], {x0 > 0, y0 > 0, z0 > 0, y1 > 0, z1 > 0, x2 > 0, z2 > 0, x3 > 0, y3 > 0}]] /. parms;

sol = NMinimize[obj, vars]
equs /. parms /. sol[[2]]
2 Sqrt[sol[[1]]]

(**** GRAPHICAL REPRESENTATION ****)

gr4 = Graphics3D[{Green, Opacity[.1], Cuboid[{0, 0, 0}, {2 a, 2 b, 2 c}] /. parms}];
gr7 = Graphics3D[{Red, Opacity[.8], Cylinder[{p0, p0 + 2 n}, r] /. parms /. sol[[2]]}];
Show[gr4, gr7, PlotRange -> All, Axes -> False]

Note that the maximum length rod was obtained thru a minimization procedure.

I've implemented the method outlined in the question statement, and for a cuboid of dimensions $$20 \times 30 \times 40$$, and with a radius of the rod of $$5$$, the rod length was found to be $$41.735$$. The cuboid and the rod are shown in the figure below.