A PHP Function to Compute the Circumference or Perimeter of an Ellipse, Spheroid, Circle
or Sphere by Evaluating the Complete Elliptic Integral of the Second Kind Using an Infinite
Power Series Summation Based on Legendre Polynomials.

PHP Function by Jay Tanner - 2020


The Basic Ellipse

Generally, the idealized equations equate the major radius (R) to unity or (R = 1) and this is often left invisible and not clearly indicated.  In the real world, we need to be able to use any units of measure we wish, so we will use R rather than an implied invisible 1.  Thus, R can be interpreted as any implied units, meters, kilometers, miles, etc.

The Complete Elliptic Integral of The Second Kind

The complete elliptic integral of the second kind may be symbolized as:

To make use of the integral, we need to adapt it to our purpose, which in this case, is to 'simply' compute the circumference of an ellipse. 

The integral defines the length of the elliptic arc from 0 to (or 0 to 90°) or only of the full 360° span of the ellipse.  It is a line integral in the sense that it defines the length of a line, in this case, one quarter of the ellipse circumference. 

Numerically solving the integral is difficult enough as it is, so solving only for the first quarter and then multiplying the result by 4 seems like the simplest way to go about it.

Notice that the angular arc-span is measured positively counter-clockwise.


Eccentricity

The elliptic eccentricity (ε), may be found from:
The eccentricity tells us how much the form of the ellipse deviates from a perfect circle.  Zero means the form is a perfect circle and the greater the value of ε, within the contstraints (0 ≤ ε < 1), the 'flatter' the ellipse.  If (r = R), then (ε = 0) and the form is a perfect circle.

The symbol ε (Greek lower-case letter epsilon) is used here for the eccentricity instead of e, so as not to confuse it with Euler's number (e = 2.71828...), used as the base of natural logarithms.

To be able to use any desired units of length or distance measure, simply specify the (R) value in any units (ft, m, km, mi, etc.), and the resulting circumference (C) will be expressed in the same units as (R).

We could substitute (ε 2)  for  in (Eq. 1), which leads to (Eq. 3) below.
Since the integral equates to only the circumference, we must multiply it by 4 to obtain the full length of the circumference.
The integral above formally defines the problem and the summation equation below provides one of several possible numerical solutions adopted to solve the problem, defined purely in terms of the basic ellipse parameters (R, r).


Numerical Solution

The numerical computation of the above elliptic integral will involve evaluating the infinite power series summation below until a given precision limit is reached.  This solution is based on Legendre polynomials.

The numerical solution for the quarter-ellipse can be expressed by this power series:
As stated above, since (Eq.4) only solves for the length of of the ellipse, we have to multply it by 4 to obtain the full circumference.

Multiplying by 4 gives the equation:
Other numerical solutions are possible, but this solution was adopted due to the simplicity of programming it as well as its fast convergence for many practical problems.  (Eq. 6) is numerically evaluated by the PHP function defined below.

If the ellipse is the cross-section of an ellipsoid, then the (R, r) parameters respectively represent the equatorial and polar radii, sometimes symbolized as (a, b), where (ab).

In the special case of a circle, where (R = r), (ε = 0), then [Summation = 0], and the equation for the circumference reduces to the classical circular circumference equation:

When (Rr), then (0 < ε < 1) and the form is an ellipse, and computing the circumference will require solving the elliptic integral via a power series summation like the one used here. 

Below is a listing of a PHP function designed to compute the high-precision general circumference of an ellipse.  It is based on (Eq. 6) above and makes use of arbitrary-precision arithmetic to compute the EXACT values of the extremely large integer fractions involved, so it could take several seconds in some extreme cases.

For most practical applications, such as geodesic and meridian computations, the function should converge sufficiently fast and accurately to 16 decimals  Also, the function could be easily tweaked for higher accuracy, if actually needed. 


The PHP Code

The demonstration program below demonstrates using the function to compute the equatorial and polar meridian circumferences of the Earth according to the WGS-84 Earth ellipsoid model used by the GPS system.  The parameters for any other ellipsoid model could also be used instead.

The function is an implementation of (Eq. 6), above.

Double-Click to select ALL code



Below is the PHP code for only the ellipse circumference function, without all the comments.

Double-Click to select ALL code


What the function above does is delineated by the first few terms of the infinite series worked out
numerically below.  Due to the extremely large numbers, arbitrary-precision is used to maintain
accuracy within the program.

Notice how quickly the numbers become very large in the series.  Although very large at first, the integer
fractions can subsequently be reduced to lowest terms, which reduces the sizes of the numbers used in
the terms, as demonstrated below.

As a visual and mental aid, the first few terms of the summation series are worked out numerically below in 6 forms.

This is the summation that is evaluated to 16 decimals by the PHP function defined above.




In all of the final reduced fractions, the numerator is always an odd integer and the denominator is always
an even power of 2.

When (ε = 0), then the form is a perfect circle and (Summation = 0).

When (0 < ε < 1), then the form is an ellipse and (0 < Summation < 1).

The closer that the eccentricity (ε) gets to 1, the longer the series will take to converge.  However, for the
intended geophysical and astronomical applications, the elliptic eccentricities don't tend to be so extreme.

One can see that the integers become very large, while the numerator to denominator ratio diminishes
rather slowly, which translates to the series converging more slowly as the eccentricity, or the elliptical
deviation from a perfect circle, increases. 

For small values of eccentricity (ε), sufficient approximation formulas could possibly be derived from the
numbers in first few terms of the series.

Download This Page: 129 kB - Ellipse Circumference Function