<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Deflection Calculator for Square Tubing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="generator" content="BBEdit 8.0" />
    <style type="text/css">
/* <![CDATA[ */
h1 { font-size: 150%; }
h2 { font-size: 120%; }
.warn
{
    color: red;
    font-weight: bold;
}
.blue { color: blue; }
.red { color: #c00; }
/* ]]> */
</style>
</head>
<body>
<h1>Deflection Calculator for Square Tubing</h1>

<?php
$mattype = $_POST['mattype']; // steel or aluminum
$ends    = $_POST['ends'];    // free or fixed
$od      = $_POST['od'];      // tube dimension
$thick   = $_POST['thick'];   // gauge
$length  = $_POST['length'];  // length of beam
$force   = $_POST['force'];   // load

if ($mattype < 2) {$ym = 29700000; // modulus for steel
$matlabel = "steel";
$matwt    = 3.4;        // weight for steel  (tweaked)
$fudge = pow($thick,4); // fudge factor for rolled tube
$color = "\"red\"";
}
else {$ym = 10000000;   // modulus for aluminum
$matlabel = "aluminum";
$matwt    = 1.16389;    // weight for aluminum (tweaked)
$color = "\"blue\"";
} 
if ($ends < 2) {$end_type = 48;
$endlabel = "free";
} 
else {$end_type = 192;
$endlabel = "fixed";
} 
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<div>
<select id="mattype" name="mattype">
<option label="Steel tube" <?php if ($mattype<2){echo "selected=\"selected\"";} ?> value="1">Steel tube</option>
<option label="Aluminum tube" <?php if ($mattype==2){echo "selected=\"selected\"";} ?> value="2">Aluminum tube</option>
</select>
<br />
<select id="ends" name="ends">
<option label="ends free" <?php if ($ends<2){echo "selected=\"selected\"";} ?> value="1">ends free</option>
<option label="ends fixed" <?php if ($ends==2){echo "selected=\"selected\"";} ?> value="2">ends fixed</option>
</select>
<br />
tube size in inches &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp;<input type="text" maxlength="5" size="5" name="od" value="<?php if ($od<.1){$od = 2;echo $od; }else {echo $od;} ?>" />
<br />
decimal gauge &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="text" maxlength="5" size="5" name="thick" value="<?php if ($thick<.01){$thick = .065;echo $thick; }else {echo $thick;} ?>" />
<br />
length of beam in inches &nbsp; <input type="text" maxlength="5" size="5" name="length" value="<?php if ($length<1){$length = 96;echo $length; }else {echo $length;} ?>" />
<br />
center load in pounds &nbsp; &nbsp; &nbsp; <input type="text" maxlength="5" size="5" name="force" value="<?php if ($force<.001){$force = 500;echo $force; }else {echo $force;} ?>" />
<br />
<p>
<input type="submit" value="calculate" />
</p>
</div>
</form>

<?php
$id = $od - 2 * $thick ;
$size = pow($od, 2) - pow($id, 2);
$weight = $size * $matwt - $fudge; 
$w2 = round ($weight, 4); 
$moment_s = pow($od-$fudge, 4) / 12; // moment of solid
$moment_v = pow($id, 4) / 12;        // moment of void
$moment_t = $moment_s - $moment_v ;  // moment of tube
$moment_r = round ($moment_t, 4) ;   // moment rounded
$deflect = (($force * (pow($length,3)))/($end_type * $ym * $moment_t));
$deflect = round ($deflect , 4);

if ($id < 0) {
echo "<div class=\"warn\">Umm...<br />
you might wanna check your tube thickness</div>";}
else {echo "<div class=$color><pre>
type = $matlabel   ends = $endlabel
est. weight = $w2# per foot
OD = $od\"  ID = $id\"
Moment of Inertia = $moment_r

Deflection = $deflect\"
</pre></div>";
}
?>
<h2>Important Caveats:</h2>
<div><strong>
This calculator may give you a rough idea of the deflection of metal tubing, but it's not accurate enough to do any more than estimate it. If the deflection is large enough to permanently bend the tube, then all bets are off.
<br /><br />
The steel weights are tweaked for mechanical tubing, and will be less accurate for structural tubing.
<br /><br />
The moduli of elasticity used are 29,700,000 psi for steel and 10,000,000 psi for aluminum.
<br /><br />
Use at your own risk. &nbsp; &nbsp; Or you'll be sorry.
</strong>
<br /><br />
formulas and data gleaned from:
<br />
<a href="http://www.aps.anl.gov/asd/me/Calculators/ElasticBeam2.html">http://www.aps.anl.gov/asd/me/Calculators/ElasticBeam2.html</a>
<br />
<a href="http://en.wikipedia.org/wiki/Main_Page">Wikipedia</a>
<br />
<a href="http://www.matweb.com/index.asp">MatWeb</a>
<br /><br />
<a href="http://www.metalgeek.com/encoded.php">comments?</a>
<br /><br />
<a href="http://www.metalgeek.com/static/deflection.html">source code</a>
</div>
</body>
</html>