cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <h1 class="page-header">Earth Curvature Bulge Calculator</h1>
  <div class="row">
    <div class="col-sm-6">
      <h2>The calculator</h2>
      <p>Simply enter the distance you want to work out the bulge due to curvature for below, choose your units and press <i>calculate</i>.</p>
      <div class="form-inline">
        <div class="form-group">
          <label for="distance">Distance</label>
          <input type="text" class="form-control" id="distance" placeholder="Enter distance">
        </div>
        <div class="form-group">
          <select id="units" class="form-control">
            <option value="0">Metric (kilometers)</option>
            <option value="1">Imperial (miles)</option>
          </select>
        </div>
        <button id="calc" class="btn btn-default">Calculate</button>
      </div>

      <h1 id="answer"></div>
    
    <div class="col-sm-6">
      <h2>The mathematics</h2>
      
      <p>We want to work out the height <i>h</i>, for a given distance <i>d</i>.</p>
      <p><img class="img-responsive" src="http://teknohippy.net/ecc/step1.png"></p>
      <p>To calculate this we need to first work out the distance <i>l</i> through the earth to the center point .</p>
      <p><img class="img-responsive" src="http://teknohippy.net/ecc/step2.png"></p>
      <p>We'll need this angle <i>θ</i> in degrees first of all.</p>
      <p><img class="img-responsive" src="http://teknohippy.net/ecc/step3.png"></p>
      <p>Given that <i>d</i> is a fraction of the earth's diameter <i>r</i>, then <i>θ</i> is simply calculated with the following equation.</p>
      <p><img style="width: 50%;margin-left:25%" src="http://teknohippy.net/ecc/form1.svg"></p>
      <p>Once we have <i>θ</i>, we can work out <i>l</i> as so.</p>
      <p><img class="img-responsive" src="http://teknohippy.net/ecc/step4.png"></p>
      <p>The radius of the earth <i>r</i> and <i>l</i> form a right angle triangle, so using half of <i>θ</i> we can work out <i>l</i> with the following bit of trig, that you will have most likely learned in school.</p>
      <p><img style="width: 50%;margin-left:25%" src="http://teknohippy.net/ecc/form2.svg"></p>
      <p>Now that we know <i>l</i>, calculating <i>h</i> is simple using pythagoras.</p>
      <p><img class="img-responsive" src="http://teknohippy.net/ecc/step5.png"></p>
      <p>As you can see we simply need to calculate <i>f</i> and subtract it from <i>r</i> to find <i>h</i>, the following formula will do that. See if you can spot the reverse pythagoras you also may have learned in school.</p>
      <p><img style="width: 50%;margin-left:25%" src="http://teknohippy.net/ecc/form3.svg"></p>
      <p>And there you have it, quite simple maths when broken down to its base components, yet understandable by any secondary level student the world over. The whole thing can be simplified down to the following.</p>
      <p><img style="width: 80%;margin-left:10%" src="http://teknohippy.net/ecc/form4.svg"></p>
      <p>To be honest I'd <a href="#">use the calculator</a>. It's easier, and if you check the javascript you can see it doing all the same maths as above, albeit with radians instead of degrees.</p>
    </div>
      
  </div>
</div>

<div class="container text-center" style="margin-top: 30px;">
  <small>Made with &hearts;, a little effort and honest mathematics. View on <a href="https://gist.github.com/0270d0ed1d0ce7a4fc6b">Github</a></small>
</div>
            
          
!
            
              body { font-family: verdana;}

i { font-family: serif; font-size: bigger; font-weight: bold; font-style: italic; }
            
          
!
            
              $('#distance').keypress(function(){ $('#answer').hide()});

$('#calc').click(function() {
  var converter = 1;
  
  if ($('#units').val() == 1)
    {
      converter = 0.621371;
    }
  
  var arcLength = Number($('#distance').val());
  var earthRadius = 6371 * converter;

  var earthCirc = 2 * Math.PI * earthRadius;

  var chordAngle = (2 * Math.PI) * (arcLength / earthCirc);

  var chordLength = 2 * earthRadius * Math.sin(chordAngle / 2);

  var sagitta = earthRadius -
    Math.sqrt(Math.pow(earthRadius, 2) -
      Math.pow(chordLength / 2, 2));
  
    if (converter == 1)
    {
      $('#answer').html('The bulge <i>h</i> is ' + (1000 * sagitta).toFixed(2) + ' meters');
    }
  else
    {
      $('#answer').html('The bulge <i>h</i> is ' + (5280 * sagitta).toFixed(2) + ' feet');
    }
  
    $('#answer').fadeIn(2000);
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console