This post will show how to find the length of piece of an ellipse and explain what elliptic integrals have to do with ellipses.

Assume we have an ellipse centered at the origin with semi-major axis *a* and semi-minor axis *b*. So *a* > *b *> 0, the longest diameter of the ellipse is 2*a* and the shortest is 2*b*. The ellipse can be parameterized by

## Special case: quarter of an ellipse

Let’s first find the perimeter of a 1/4 of the ellipse.

This is given by the integral

The change of variables *u* = π/2 – *t* turns the integral into

because *E*, the “elliptic integral of the second kind,” is defined by

Therefore the perimeter of the entire ellipse is 4*aE*(1 – *b*²/*a*²). Let’s define

for the rest of the post. Incidentally, *m* = *e*² where *e* is the eccentricity of the ellipse.

## General case

Now let’s find the length of an arc where *t* ranges from 0 to *T* and *T* is not necessarily π/2.

The derivation is similar to that above.

where *E*, now with two arguments, is the “incomplete elliptic integral of the second kind” defined by

It is “incomplete” because we haven’t completed the integral by integrating all the way up to π/2.

To find the length of a general arc whose parameterization runs from *t* = *T*_{0} to *t* = *T*_{1} we find the length from 0 out to *T*_{1} and subtract the length from 0 out to *T*_{0} which gives us

The elliptic integrals are so named because they came out of the problem we’re looking at in this post. The integrals cannot be computed in elementary terms, so we introduce new functions that are defined by the integrals. I expand this idea in this post.

**NB**: We are specifying arcs by the range of our parameterization parameter *t*, not by the angle from the center of the ellipse. If our ellipse were a circle the two notions would be the same, but in general they are not. The central angle θ and the parameter *T* are related via

I wrote about this here.

## Python code

Let’s calculate the length of an arc two ways: using our formula and using numerical integration. Note that the Python implementation of the (complete) elliptic integral is `ellipe`

and the implementation of the incomplete elliptic integral is `ellipeinc`

. The “e” at the end of `ellipe`

distinguishes this elliptic integral, commonly denoted by *E*, from other kinds of elliptic integrals.

from numpy import pi, sin, cos from scipy.special import ellipe, ellipeinc from scipy.integrate import quad def arclength(T0, T1, a, b): m = 1 - (b/a)**2 t1 = ellipeinc(T1 - 0.5*pi, m) t0 = ellipeinc(T0 - 0.5*pi, m) return a*(t1 - t0) def numerical_length(T0, T1, a, b): f = lambda t: (a**2*sin(t)**2 + b**2*cos(t)**2)**0.5 return quad(f, T0, T1) T0, T1, a, b = 0, 1, 3, 2 y, err = numerical_length(T0, T1, a, b) ell = arclength(T0, T1, a, b) assert(abs(ell - y) < 1e-12) T0, T1, a, b = 7, 1, 4, 3 y, err = numerical_length(T0, T1, a, b) ell = arclength(T0, T1, a, b) assert(abs(ell - y) < 1e-12)

The tests pass. This increases our confidence that the derivation above is correct.