# Calculating the circumference of the Earth

**URL:** <https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375>\
**Category:** Offtopic\
**Tags:** geo\
**Created:** [July 9, 2023, 5:08am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375 "2023-07-09T05:08:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [July 9, 2023, 5:08am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/1 "2023-07-09T05:08:49Z")

</div>

```julia
"""
According to this website
https://en.wikipedia.org/wiki/Wikipedia:Reference_desk/Archives/Science/2006_September_27
I only need to use 64 decimal digits of Pi.
However I need an additional 4 decimal digits for guard digits
So I need a total of 68 decimal digits of Pi
I need to use 3.32 binary digits of accuracy for each 1 decimal digit of accuracy
Thus I need 226 binary digits of Pi.
So I need to use BigFloat with 226 binary digits of accuracy
""";

println("Start of program")

using Printf

setprecision(226) # Set BigFloat to 226 binary digits of accuracy

# Check the accurary of pi using mathematica
# according to Mathematica N[Pi, 68]
# the 68 decimal digits of pi is
# 3.1415926535897932384626433832795028841971693993751058209749445923078
pi68 = BigFloat("3.1415926535897932384626433832795028841971693993751058209749445923078")
println("accurary of pi is ",BigFloat(pi) - pi68)

"""
  Now consider that earth is a ellipsoid with
  A = 6378137.000000 # Semi-major Axis for Earth in metres
  B = 6356752.314245 # Semi-minor Axis for Earth in metres

  Then the length of equator of earth is

  circumference = 2 * pi * r # where r = A

""";

A = BigFloat("6378137.000000") # Semi-major Axis for Earth in metres
B = BigFloat("6356752.314245") # Semi-minor Axis for Earth in metres

r = A
println("typeof(r) is ",typeof(r))

circumference = BigFloat(2) * BigFloat(pi) * r
@printf("equatorial circumference is %76.68f",circumference)

"""
    Calculating the polar circumference of an ellipsoid is not EASY
    https://www.mathsisfun.com/geometry/ellipse-perimeter.html

    A much easier problem is to calculate the quarter circumference
    which turns the whole problem into calculating the quarter meridian

    https://en.wikipedia.org/wiki/Meridian_arc#Quarter_meridian

    The polar circumference is just 4 times the quarter meridian

""";

```

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _ | |
  | | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

accurary of pi is 3.709206150687421385731735261547639513367564778757791002453039058917581e-68
typeof(r) is BigFloat
equatorial circumference is 40075016.68557848615317681776140035737460936288284427863135134035429705953315

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/076f329d3b9ac7ca564bb109dcd3da01fc0d742b.png)

---

<div class="post-metadata">

**Author:** ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)\
**Post date:** [July 9, 2023, 6:22am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/2 "2023-07-09T06:22:09Z")

</div>

vs 40,075.017 km

Well done!

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [July 9, 2023, 11:44am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/3 "2023-07-09T11:44:53Z")

</div>

Now the next step with both of these results from the point of view of a physicist (or actually any scientifically thinking person bar pure mathematicians) would be estimation of the deviation of the real world from the mathematical model. E.g. due to tidal motion. How many digits of precision are “physical”?

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [July 9, 2023, 12:27pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/4 "2023-07-09T12:27:00Z")

</div>

What tide? The solid one?

```julia
using GMT

G = earthtide(T="2022-07-07T12:00:00");
C = grd2cpt(G, cmap=:geo);
imshow(G, proj=:guess, cmap=C, shade=true, coast=true, colorbar=true, title="Earth tide at noon 7-July-2022")

```

More at [Earth tides](https://www.generic-mapping-tools.org/GMTjl_doc/geophysics/earthtides/)

 ![mt](https://global.discourse-cdn.com/julialang/original/3X/5/7/5749e7ae82f2f43982df01f0e55cf497a0827de2.png)

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [July 9, 2023, 1:06pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/5 "2023-07-09T13:06:35Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f8c55c01c2941fb5e7efc1ee2fa5ba61fc55f39.png)

```julia
using QuadGK
using Printf

println("Start of program")
setprecision(226) # Set BigFloat to 226 binary digits of accuracy

A = BigFloat("6378137.000000")
B = BigFloat("6356752.314245")
e_square = ( (A+B)*(A-B) )/(A^2)

integral, error = quadgk(x -> sqrt(1 - e_square * sin(x)), BigFloat(0), BigFloat(pi)/2,rtol=1e-68)

println("integral is ",integral)

quartermeridian = A * integral

circumference = 4 * quartermeridian

@printf("equatorial circumference is %76.68f",circumference)

```

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _ | |
  | | |_| | | | (_| | | Version 1.9.2 (2023-07-05)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

Start of program
integral is 1.567444724577919670791384090705783384345415625384518766551994250585625
equatorial circumference is 39989508.77314095534120938460056765247071486472257255348855854781378953208270

```

![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/974ca3f52c6d61266c09646152345392c4269456.png)

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [July 9, 2023, 1:10pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/6 "2023-07-09T13:10:47Z")

</div>

> [@Eben60](#):
>
> How many digits of precision are “physical”?

It’s hard to even define what is meant here. I mean if you rolled a surveyor wheel along the surface of the earth frozen in time it probably couldn’t be more than 3 digits, there are even smallish mountains that would add kilometers of distance just in the up and down undulations not to mention ocean waves.

It’d be an interesting calculation to just add a sinusoidal perturbation of height 3m and period 300m (emulating ocean waves) and calculate the difference via integration.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [July 9, 2023, 1:16pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/7 "2023-07-09T13:16:12Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [July 9, 2023, 2:13pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/8 "2023-07-09T14:13:12Z")

</div>

And I disguised it a bit by using a discrete colormap. Try it with

```julia
C = makecpt(range=(-0.2,0.2), cmap=:geo);

```

and see the difference

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [July 9, 2023, 2:45pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/9 "2023-07-09T14:45:01Z")

</div>

> [@dlakelan](#):
>
> It’d be an interesting calculation to just add a sinusoidal perturbation of height 3m and period 300m (emulating ocean waves) and calculate the difference via integration.

Considering a right triangle setup with 300m base, height 3m, the hypotenuse is x1.00005 longer than 300m. So overall, 5 significant digits are to be expected. The land portion of the circumference may be more crucial as it can support wilder curves, so we can assume only 4 significant digits are “physical”.

Another physical issue is the length of the measuring rod (like in the famous coastline length paradox). A km long rod can overlook the ocean waves, while a micrometer long rod will measure molecular crevices.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [July 9, 2023, 3:05pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/10 "2023-07-09T15:05:02Z")

</div>

> [@dlakelan](#):
>
> It’s hard to even define what is meant here.

Well, 3 digits is presumably a reasonable lower limit of the precision estimation. I’d also maintain it makes little sense to give the result in micrometer: that could be an upper limit estimation. Thus  
`3 <= p <= 11` , where p is the number of decimal digits.

Sure, “estimation by feeling” is not a mathematically rigorous thing.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [July 9, 2023, 3:19pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/11 "2023-07-09T15:19:22Z")

</div>

> [@Eben60](#):
>
> Sure, “estimation by feeling” is not a mathematically rigorous thing.

Since the French originally **defined** the meter as ten-million’th of the distance between equator and pole. My feeling is the only accurate circumference of the Earth is the mathematically exact 40,000km. 😜

Surprisingly, despite the Earth’s unspherical shape, this is a really good value (40,075.017 km i.e. 3 significant digits).

The only greater surprise might be the accurate estimation by Eratosthenes in ancient times.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [July 9, 2023, 3:47pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/12 "2023-07-09T15:47:15Z")

</div>

> [@Dan](#):
>
> Surprisingly, despite the Earth’s unspherical shape, this is a really good value

The nonspherical shape of the Earth was known by that time, and to my knowledge was taken into account. By the way, the history of triangulation is quite fascinating, as it combined the most modern mathematical and technical achievements of the time with quite adventurous expeditions.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [July 9, 2023, 7:36pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/13 "2023-07-09T19:36:49Z")

</div>

> [@Eben60](#):
>
> Sure, “estimation by feeling” is not a mathematically rigorous thing.

I find it quite enjoyable though. For other ways of thinking about it consider an equipotential surface. The gravitational acceleration at the surface of the earth varies already in the 2nd decimal place

> **[Gravity of Earth](https://en.m.wikipedia.org/wiki/Gravity_of_Earth)**
>
> The gravity of Earth, denoted by g, is the net acceleration that is imparted to objects due to the combined effect of gravitation (from mass distribution within Earth) and the centrifugal force (from the Earth's rotation).
> It is a vector quantity, whose direction coincides with a plumb bob and strength or magnitude is given by the norm 
>   
>     
>       
> g
> =
> ‖
>         
>           
>             
> g
>             
>           
>         
> ‖
>       
>     
> {\\d In ...

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [July 9, 2023, 8:01pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/14 "2023-07-09T20:01:05Z")

</div>

> [@dlakelan](#):
>
> > [@Eben60](#):
> >
> > Sure, “estimation by feeling” is not a mathematically rigorous thing.
> 
> I find it quite enjoyable though.

Then there is another name for it, which my employer normally uses when selling our services: Expert opinion 😀

As to the Earth’s shape: A friend of mine, who used to work for a navigation software company once told me, on some map the sea level had a step like a meter or two (can’t remember that exactly). No, if you travel by sea, you wouldn’t feel it - it was just different countries using different models of the Earth, so that non-existing step “marked” the sea border.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [July 9, 2023, 8:08pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/15 "2023-07-09T20:08:14Z")

</div>

> [@Eben60](#):
>
> step like a meter or two

Many countries (like mine) have the _Hydrographic zero_ as \> 2 meters bellow the mean sea level for navigation reasons in harbors (so that even in low tide there is water to navigate). Not all countries follow this so to say convention. But this makes a difference only in shallow waters. On the other hand it is a permanent source of troubles when depths and height data are join.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [July 9, 2023, 10:06pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/16 "2023-07-09T22:06:53Z")

</div>

And if one looks at the Geoid anomaly with respect to the ellipsoid (the geoid is the equipotential corresponding to the mean sea level) we can see that the south of India is \> 100 meters close to center of the Earth, whilst other places may be as ~80 further when comparing to the ellipsoid.

```julia
using GMT

G = gmtread("@earth_geoid_06m_g");
viz(G, region=:global, proj=:guess, shade=true, coast=true, colorbar=true, title="Geoid (meters)")

```

 ![geod-or8](https://global.discourse-cdn.com/julialang/original/3X/f/3/f376eae59a22a1e188a2db4e8715bfd8f0b3936d.jpeg)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 9, 2023, 10:44pm UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/17 "2023-07-09T22:44:36Z")

</div>

[Meet the Censors](https://youtu.be/rXFwiESB9WI) - Bra Bra Bra.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [July 10, 2023, 2:57am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/18 "2023-07-10T02:57:27Z")

</div>

> It’d be an interesting calculation to just add a sinusoidal perturbation of height 3m and period 300m (emulating ocean waves) and calculate the difference via integration.

```julia
#=
(360.0 deg)/(39989508.77314 m) = 9.002361145326282e-6 deg/m

300 m * 9.002361145326282e-6 deg/m = 0.0027007083435978845 deg
convert to rad = 4.713625273186541e-5 rad
=#

integral2, error2 = quadgk(x -> sqrt(1 - e_square * sin(x)) + 1.5 * sin(2*pi*x/4.713625273186541e-5), BigFloat(0), BigFloat(pi)/2,rtol=1e-68)

quartermeridian2 = A * integral2

circumference2 = 4 * quartermeridian2

@printf("equatorial circumference2 is %76.68f",circumference2)
println()

```

```julia
equatorial circumference2 is 39990037.63922746734945825554723989362469830257394170332800238910744266711623

```

compared to equatorial circumference is 39989508.77314095534120

I think I made a mistake in my calculation.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/7/472530db680815e2812568ef6d8e32ede55aba85.png)

if I replace a “straight line” with a curvy line, I just need to multiply the length of the straight line with a constant. And use the formula above to find the constant.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [July 10, 2023, 3:35am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/19 "2023-07-10T03:35:51Z")

</div>

> [@StevenSiew](#):
>
> `integral2, error2 = quadgk(x -> sqrt(1 - e_square * sin(x)) + 1.5 * sin(2*pi*x/4.713625273186541e-5), BigFloat(0), BigFloat(pi)/2,rtol=1e-68)`

I think my suggestion corresponds to making the “radius” undulate. So in polar coordinates, instead of r = constant, you do `r = constant * (1+epsilon*sin(k*x))`. then derive the arc length from that and integrate that arc length.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [July 10, 2023, 5:52am UTC](https://discourse.julialang.org/t/calculating-the-circumference-of-the-earth/101375/20 "2023-07-10T05:52:09Z")

</div>

> if I replace a “straight line” with a curvy line, I just need to multiply the length of the straight line with a constant. And use the formula above to find the constant.

I got something like this

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f4e95fab90720f058aa77300240dc638bd88ef7.png)

39989508.7731409553412093846 \* 1.00025  
is 39999506.15033423900604248046875

postscript: When calculated with high precision, the exact value of  
k is 1.000247298782811260248467386335844858029916513022277202636312860931
