There are three relevant solution states for the problem: (A) the cylinder lies diagonally in the box, (B) the cylinder is diagonal in the plane of one of the sides, and (C) the cylinder lies lengthwise along the longest dimension of the box. The solution resulting in the longest cylinder length is chosen. Solution C is trivial, and solution B is found by projecting the cylinder onto one of the box sides, resulting in a picture like this:
. The cylinder length can then be found by solving the fourth-degree polynomial equation for the value of the dihedral angle formed by the sides of the larger green rectangle and the smaller red one (the variable twodsol
contains the relevant solution).
One approach to obtaining solution A is to find the center of the circular rim of the cylinder. The distance between this point and a similar point on the opposite end of the cylinder is the cylinder length. To find the coordinates of the center, solve a system of nine equations with nine unknowns, which are the
coordinates of the three points at which the rim is tangent to the coordinate planes, translated so that the center point lies at the origin. Given the vector normal to the plane of the rim,
, and the radius of the cylinder,
, gives three sets of three equations: the distance between each of the three tangent points and the center is
; the vector normal and the vector differences between the tangent points and the center are perpendicular, and their dot products are zero; the intersections of the plane of the rim with each of the coordinate planes simultaneously lie in a coordinate plane and the rim planes and are tangent to the rim, each one perpendicular to an appropriate difference vector, just as the cross product of the vector normal and the difference vector lies in the plane of the rim and perpendicular to the difference vector. This vector will thus lie parallel to an appropriate coordinate plane and will have a component equal to zero. The resulting system is solved, translated back, and the solution that lies in the positive orthant is chosen. Finally, a numerical root search is used to obtain the vector normal that maximizes the length of a cylinder lying diagonally.
 R. Jerrard, J. Schneider, R. Smallberg, and J. Wetzel, "Straw in a Box," The College Mathematics Journal
(2), 2006 pp. 93–102.