<?PHP
include("config.php");
foreach ( $_POST as $key ) {

}

$xser = (float)$_POST['barboreX'];
$yser = (float)$_POST['barboreY'];
$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
$reach = $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));     

//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));   

$reach = round($reach, 0);
$stack = round($stack, 0);

//echo ("STACK: ".$stack);
//echo ("REACH: ".$reach);
//exit();
?>
<!DOCTYPE html >
<html lang="en">
<head>
<title>&lt;:: Welcome to Slowtwitch.com ::&gt;: Bar to Head Tube Calculator</title>
<meta name="KEYWORDS" content="bike, geometry, custom" />
<meta name="DESCRIPTION" content="Need to know stack and reach from an X-Y bar-bore measurement? Use our calculator to help."/>
<? include($common_path . "/templates/include_global_head.php"); ?>
<? include($common_path . "/templates/google_analytics.html"); ?>
</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. Bar to Head Tube Calculator</h1>
                <hr class="line" />
                <div class="clearfix">
                  <div class="col-2-3">
                    <h3 class="section-title">Input</h3>
                    <div class="dtable form">
                        <div class="drow">
                            <div class="dcell name">Bar-Bore Y</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value"><? echo $yser."mm"; ?></div>
                        </div>
                        <div class="drow">
                            <div class="dcell name">Bar-Bore X</div>
                            <div class="dcell divider"></div>
                            <div class="dcell value"><? echo $xser."mm"; ?></div>
                        </div>
                        <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 class="section-title">Output</h3>
                    <p>Stack: <? echo $stack."mm"; ?></p>
                    <p>Reach: <? echo $reach."mm"; ?></p>
                  </div>
                </div>
                <div class="center">
                  <a href="bar_bore_calc.php" class="btn default">Return to the Bar-Bore to X-Y Calculator</a>
                </div>
                <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>


