<?PHP

foreach ( $_POST as $key )
{
    
}

$stemlength = (float)$_POST['stem_length'];
$headangle = (float)$_POST['head_tube_angle'];
$stemangle = (float)$_POST['stem_angle'];
$clamp = (float)$_POST['clamp'];
$spacer = (float)$_POST['spacer'];
$headset = (float)$_POST['headset'];

$reach = 0;
$stack = 0; 

// calculate stack and reach
$stretch = ($stemlength*cos(deg2rad(90-$headangle+$stemangle))) - (($clamp/2) + $spacer + $headset)*cos(deg2rad($headangle));
$rise = ($stemlength*sin(deg2rad(90-$headangle+$stemangle))) + (($clamp/2) + $spacer + $headset)*sin(deg2rad($headangle));      

//echo($xser." - (".$stemlength."*cos(deg2rad(90-".$headangle."+".$stemangle."))) - ((".$clamp."/2) + ".$spacer." + ".$headset.")*cos(deg2rad(".$headangle."))");
//$stack = $yser - ($stemlength*sin(deg2rad(90-$headangle+$stemangle))) - (($clamp/2) + $spacer + $headset)*sin(deg2rad($headangle));   

$rise = round($rise, 0);
$stretch = round($stretch, 0);

//echo ("STACK: ".$stack);
//echo ("REACH: ".$reach);
//exit();

?>
<?PHP include("config.php"); ?>
<!DOCTYPE html >
<html lang="en">
<head>
<title>&lt;:: Welcome to Slowtwitch.com ::&gt;: Stem Rise &amp; Stretch Calculator</title>
<meta name="KEYWORDS" content="bike, geometry, custom" />
<meta name="DESCRIPTION" content="Are you trying to calculate the rise and stretch of a stem? Use our calculator to help."/>
<? include($common_path . "/templates/include_global_head.php"); ?>
<? include($common_path . "/templates/google_analytics.html"); ?>
<!-- Begine script for calculator -->
<script src="js/fit_calculator.js" type="text/javascript" language="JavaScript"></script>
<!-- end script for calculator -->
</head>

<body id="home">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>
  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">
        <? include("include_breadcrumb.php"); ?>

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <? include("include_sidebar.php") ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">

              <div class="clearfix">
                <h1>F.I.S.T Stem Calculator</h1>
                <hr class="line" />
                <div class="clearfix">
                  <div class="col-2-3">
                    <h3>Input</h3>
                    <div class="dtable form">
                        <div class="drow">
                            <div class="dcell name">Head Tube Angle</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $headangle."&deg;"; ?>
                            </div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Stem Length</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $stemlength."mm"; ?>
                            </div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Stem Angle</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $stemangle."&deg;"; ?>
                            </div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Stem Clamp Height</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $clamp."mm"; ?>
                            </div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Spacer Height</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $spacer."mm"; ?>
                            </div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Headset Topcap</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value">
                                <? echo $headset."mm"; ?>
                            </div>
                        </div>
                    </div>
                  </div>
                  <div class="col-1-3">
                    <h3>Output</h3>
                    <p>Rise: <? echo $rise."mm"; ?></p>
                    <p>Stretch: <? echo $stretch."mm"; ?></p>
                  </div>
                </div>
                <p class="center"><a href="stem_calc.php" class="btn default">Return to the Stem Calculator</a></p>
                <p>
                    Even if the fit is performed correctly, pitfalls loom.  You must have the
                    tools to accurately find the stack and reach of the bike that fits under the
                    rider.  The fitter is required to account for the stem length, stem pitch,
                    height of the stem clamp, headset upper stack, spacers under the stem if
                    any, and of course the choice of aerobar.  He then must have an accurate way
                    of generating the stack and reach measures, using either a fit bike (best is
                    the bike made by Exit Cycling) that accurately generates these values
                    (taking into consideration <a href="/Bike_Fit/Fudging_for_negative_reach_123.html">negative reach</a> if applicable), or he must use an external tool, such
                    as Serotta's X/Y tool.
                    </p>
              </div><!-- end col-2/3 -->

            </div><!-- end grid -->
          </div><!-- end content -->
        </section>

      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>

