Article 65CSS How to calculate length of an elliptic arc

How to calculate length of an elliptic arc

by
John
from John D. Cook on (#65CSS)

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 2a and the shortest is 2b. The ellipse can be parameterized by

ep1.svg

Special case: quarter of an ellipse

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

ep13.png

This is given by the integral

ep2.svg

The change of variables u = /2 - t turns the integral into

ep3.svg

because E, the elliptic integral of the second kind," is defined by

ep4.svg

Therefore the perimeter of the entire ellipse is 4E(1 - b^2a^2). Let's define

ep5.svg

for the rest of the post. Incidentally, m = e^2 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.

ep14.png

The derivation is similar to that above.

ep12.svg

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

elliptic_e_def.svg

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 = T0 to t = T1 we find the length from 0 out to T1 and subtract the length from 0 out to T0 which gives us

ep11.svg

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

ep8.svg

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.

The post How to calculate length of an elliptic arc first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments