Tube in a Cube

For a given cylinder radius, this Demonstration finds the maximum-length cylinder that fits inside a rectangular box. For a cylinder radius approaching zero, the maximum-length cylinder lies on the diagonal connecting the opposite corners of the box. However, as the cylinder radius is increased, the longest cylinders lie along the longest dimension of the box.


  • [Snapshot]
  • [Snapshot]
  • [Snapshot]


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.
Another approach to this problem is found in [1].
[1] R. Jerrard, J. Schneider, R. Smallberg, and J. Wetzel, "Straw in a Box," The College Mathematics Journal, 37(2), 2006 pp. 93–102.
    • Share:

Embed Interactive Demonstration New!

Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details »

Files require Wolfram CDF Player or Mathematica.

Related Curriculum Standards

US Common Core State Standards, Mathematics

Mathematica »
The #1 tool for creating Demonstrations
and anything technical.
Wolfram|Alpha »
Explore anything with the first
computational knowledge engine.
MathWorld »
The web's most extensive
mathematics resource.
Course Assistant Apps »
An app for every course—
right in the palm of your hand.
Wolfram Blog »
Read our views on math,
science, and technology.
Computable Document Format »
The format that makes Demonstrations
(and any information) easy to share and
interact with.
STEM Initiative »
Programs & resources for
educators, schools & students.
Computerbasedmath.org »
Join the initiative for modernizing
math education.
Step-by-Step Solutions »
Walk through homework problems one step at a time, with hints to help along the way.
Wolfram Problem Generator »
Unlimited random practice problems and answers with built-in step-by-step solutions. Practice online or make a printable study sheet.
Wolfram Language »
Knowledge-based programming for everyone.
Powered by Wolfram Mathematica © 2017 Wolfram Demonstrations Project & Contributors  |  Terms of Use  |  Privacy Policy  |  RSS Give us your feedback
Note: To run this Demonstration you need Mathematica 7+ or the free Mathematica Player 7EX
Download or upgrade to Mathematica Player 7EX
I already have Mathematica Player or Mathematica 7+