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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              function ellipseCircumference(a, b) {
//direct implementation from http://en.wikipedia.org/wiki/Ellipse#Circumference    
//Compute the circumference of an ellipse with semi-axes a and b.
//Require a >= 0 and b >= 0.  Relative accuracy is about 0.5^53.
var t,
	x = Math.max(a, b),
	y = Math.min(a, b),
	digits = 64,
	tol = Math.sqrt(Math.pow(0.5, digits)),
	s = 0,
	m = 1
;

    if (digits * y < tol * x) {
        return 4 * x;
	}
	
  while (x - y > tol * y) {
    // fixed thanks to cffk
    // http://gis.stackexchange.com/a/72582/2591
    t = x;
    x = 0.5 * (t + y);
    y = Math.sqrt(t * y)
		m = m * 2;
		s = s + m * Math.pow(x - y, 2);
	}
	
    return Math.PI * (Math.pow(a + b, 2) - s) / (x + y);
}

function ellipseCircumferenceSimple(a, b) {
	return 2 * Math.PI * (Math.sqrt((a*a + b* b) /2));
}
  
function addElement (content, element, id) {
  if (element === undefined) {element = "p";}
  var 
    e = document.createElement(element),
    c = document.createTextNode(content);
  document.body.appendChild(e).appendChild(c);
}
  
function addLink (url, title) {
  var 
    p = document.createElement("p"),
    a = document.createElement("a"),
    t = document.createTextNode(title);
  a.setAttribute("href", url);
  document.body.appendChild(p).appendChild(a).appendChild(t);
}

function drawEllipse () {
  var c = document.createElement("canvas");
  c.setAttribute("id", "canvas1");
  c.setAttribute("width", "400");
  c.setAttribute("height", "400");
  document.body.appendChild(c);

  var canvas = document.getElementById("canvas1");
  if (canvas.getContext){
    var ctx = canvas.getContext('2d');
    var centerX = canvas.width / 2;
    var centerY = canvas.height / 2;
    var radius = 150;
      // exagerration = 100
      ctx.scale(1,1 - (100/WGS84Flattening));
      ctx.strokeStyle = '#000000';
      ctx.lineWidth = 1;
      ctx.beginPath();
      ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
      ctx.stroke();
      // arc
      ctx.strokeStyle = '#4444FF';
      ctx.lineWidth = 6;
      ctx.beginPath();
      ctx.arc(centerX, centerY, radius, - Math.PI/2, 0, false);
      ctx.stroke();
      ctx.lineWidth = 2;
    // major axis a
      ctx.strokeStyle = '#990000';
      ctx.beginPath();
      ctx.moveTo(centerX, centerY);
      ctx.lineTo(centerX + radius, centerY);
      ctx.stroke();
      // minor axis b
      ctx.strokeStyle = '#00DD00';
      ctx.beginPath();
      ctx.moveTo(centerX, centerY);
      ctx.lineTo(centerX, centerY - radius);
      ctx.stroke();
  }
} 

var
  distanceProper = 10001966,
  WGS84AxisA = 6378137,
  WGS84Flattening = 298.257223563,
  WGS84AxisB = WGS84AxisA * (1 - 1/WGS84Flattening),
  polarCircumference = ellipseCircumference(WGS84AxisA, WGS84AxisB),
  polarCircumferenceSimple = ellipseCircumferenceSimple(WGS84AxisA, WGS84AxisB),
  distanceIntegrated = polarCircumference/4,
  distanceSimple = polarCircumferenceSimple/4
;
addElement("Distance from pole to equator", "h1");
addElement("for WGS84 ellipsoid", "h2");
addElement("Proper Distance: ~" +
           distanceProper + "m"); 
addElement("Integrated Distance: ~" +
           distanceIntegrated.toFixed(1) + "m");  
addElement("Simple Distance: ~" +
           distanceSimple.toFixed(1) + "m");
addElement("Error proper-simple: ~" +
           (distanceProper - distanceSimple).toFixed(1) + "m");
addElement("Error proper-integrated: ~" +
           (distanceProper - distanceIntegrated).toFixed(1) + "m");

addLink("http://math.stackexchange.com/questions/444623/ellipse-circumference-calculation-method", "Simple Circumference Calculation (stackoverflow)");
addLink("http://en.wikipedia.org/wiki/Ellipse#Circumference", "Integrated Circumference Calculation (wikipedia)");   
addElement("WGS84 Ellipsoid Definition", "h4"); 
addElement("WGS84 defined semi-major axis a (red): " + WGS84AxisA + "m");
addElement("WGS84 defined flattening: " + WGS84Flattening);
addElement("WGS84 derived semi-minor axis b (green): ~" + WGS84AxisB.toFixed(6) + "m");
addElement("Sketch (100x-exagerrated)", "h4"); 
drawEllipse();
            
          
!
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.

Console