Wikipedia:Reference desk/Archives/Mathematics/2023 December 9

= December 9 =

Longest cylinder in a box
Given a rectilinear box with interior dimensions a,b,c, what is the longest cylinder of radius r that can fit in the box? In the limit of r=0, the answer is just to place the cylinder along the space diagonal, so the length would be $$\sqrt{a^2+b^2+c^2}$$. But with a nonzero r, the geometry of how the cylinder meets the corner of the box seems rather complicated. Is there an easy way to solve this? CodeTalker (talk) 18:31, 9 December 2023 (UTC)


 * Don't expect an easy solution. An easy non-trivial lower bound on the length is given by $$d-2r$$ where $$d=\textstyle\sqrt{a^2+b^2+c^2},$$ but if $$r>0$$ it is not strict. In the general case the axis of the cylinder will not be aligned with a diagonal, but wlog the centres of box and cylinder can be made to coincide. It is tempting to assume that the longest fitting cylinder necessarily touches all six sides, but I don't think this is actually the case. --Lambiam 20:42, 9 December 2023 (UTC)


 * Just to clarify a bit, by a cylinder I assume you mean a right circular cylinder. And I'm going to assume (see the previous comment) that the cylinder touches all three side. If that's not the case then the problem reduces to find the longest rectangle with one side 2r that fits into a give rectangle, and that seems easier. Perhaps that problem should be solved first to get an idea how intractable things will get when you add a dimension. I think you can simplify things a bit by using symmetry. Double the size of the box and place it so the coordinates of the corners are (±a, ±b, ±c) This will double the length of the cylinder. Then by symmetry the origin is at the midpoint of the axis, so halve the length by only considering the length from the origin to an endpoint. Say the endpoint is E = (d, e, f). Let Pa = (a, y, z) be the point at which the end of the cylinder touches the side x=a. We know three things about this point: 1) It's on both the planes x=a and (d, e, f)⋅(x, y, z) = (d, e, f)⋅(d, e, f). 2) Its distance from E is r. 3) Of the points on the line of intersection of the planes x=a and (d, e, f)⋅(x, y, z) = (d, e, f)⋅(d, e, f), Pa is the closest to E. 3 implies Pa is a linear combination of (d, e, f) and (1, 0, 0) by Lagrange multipliers, so Pa can be written (a, ue, uf). Define Pb and Pc similarly and we get Pb = (vd, b, vf), Pc = (wd, we, c). We now have six unknowns d, e, f, u, v, w, and six equations from 1 and 2. There may be better ways of doing it, but that's how I would approach the problem. I haven't done all the algebra required to get to the final answer though. --RDBury (talk) 21:01, 9 December 2023 (UTC)
 * The same question was asked on StackExchange here, with no solution posted, while a version with a specified ratio $$a:b:c=10:6:5$$ was asked here. The latter one also has no solutions but contains the onset of a path that might lead to a solution; I have not tried to assess the correctness of the steps taken. --Lambiam 21:07, 9 December 2023 (UTC)
 * The section for the  Demonstrations Project "Tube in a Cube" confirms that the longest cylinder is not always in diagonal position. The statement that a numerical root search is used to find the solution for the diagonal case strongly suggests there is no algebraic solution for the general diagonal case. The text also refers to the paper "Straw in a Box", which I haven't read.  --Lambiam 11:22, 11 December 2023 (UTC)
 * I've just read through Straw in a Box; it does yield a solution for the length of the longest cylinder along the space diagonal in terms of the root of an equation (well, technically eight equations, one must choose $$\epsilon_{i} = \pm 1$$ that yields the longest cylinder), and according to them said equation yields a polynomial when it is squared 3 times, but that polynomial is of degree 16 in terms of the square of the length, and is thus for all intents and purposes too complicated to solve algebraically. But if you do manage to solve the equation for the length of the cylinder, then they also have equations for the coordinates of the centers of the circles forming the bases of the cylinder given that length. GalacticShoe (talk) 17:30, 11 December 2023 (UTC)
 * The "Straw in a Box" article does seem to address the problem as much as can be feasibly, though I haven't looked at in detail. I think it would be helpful, as I hinted at above, to use the two dimensional case as a starting point. The 2D problem is to find the longest rectangle with one side of fixed length 2r, that fits in a given rectangle with sides a and b. The article sets the origin to one of the corners, but I still think the problem is easier if you set the origin to the center. I think it simplifies things as well to look at the problem from the other direction; instead of inscribing the smaller rectangle in the larger one, circumscribe the larger one around the smaller one. So if the "axis" of the inner rectangle (i.e. line joining the midpoints of the sides of length 2r) is from (0, 0) to (d, e). Then it's not too hard to see that if the circumscribing rectangle goes from -a to a in the x direction and from -b to b in the y direction:
 * $$a = d + \frac{er}{\sqrt{d^2+e^2}}, b = e + \frac{dr}{\sqrt{d^2+e^2}}$$
 * This isn't too bad, and the real trick is solving for d and e.
 * Returning to three dimensions, the reversed problem might be stated as: Given a cylinder with axis from (-d, -e, -f) to (d, e, f) and radius r, find the smallest a, b, c so that the box from -a to a in the x direction, from -b to b in the y direction and from -c to c in the z direction contains the cylinder. While not exactly trivial, this problem does seem doable without having to solve higher order algebraic equations.. --RDBury (talk) 01:22, 12 December 2023 (UTC)
 * Elimination of $$e$$ from the pair of equations for a planar diagonal results in a sextic equation in $$d,$$ so it appears that in the general 2D case one also needs to resort to numerical methods. Equivalently, one can use the pair of non-algebraic equations
 * $$a=s\cos\varphi+r\sin\varphi,b=s\sin\varphi+r\cos\varphi$$
 * in the unknowns $$s$$ and $$\varphi.$$ Given a solution, use $$d=s\cos\varphi,e=s\sin\varphi.$$ --Lambiam 11:17, 12 December 2023 (UTC)
 * You cas use the substitution cos φ = (1-u2)/(1+u2), sin φ = 2u/(1+u2) to turn the trigonometric system back into an algebraic system, and there are other substitutions you can try. But if there is a simple formula I couldn't find it. The original question was whether there is an easy way to solve the problem; I'd say the short answer is no. Unless there's some clever way to approach it that everyone is missing. --RDBury (talk) 20:03, 12 December 2023 (UTC)