6

Suppose we have an ellipse x^2/a^2 + y^2/b^2 .

Taking a point (a*cos(t),b*sint(t)) on the ellipse, what is the fastest way to find another point on the ellipse such that distance between them is a given d. [d is less than pi*a*b].

The problem was encountered when i have a corner [quarter ellipse] and need to find points along it seperated by some 'd'.

Anil Shanbhag
  • 950
  • 1
  • 13
  • 31
  • 3
    Do you mean distance along the circumference, or along the chord? – NPE May 20 '11 at 11:06
  • 1
    [This might help](http://en.wikipedia.org/wiki/Elliptic_integral#Complete_elliptic_integral_of_the_second_kind). – R. Martinho Fernandes May 20 '11 at 11:10
  • 2
    A computational method would be to find the opposite point on the ellipse and then use binary search along either side in terms of distance. – Peteris May 20 '11 at 11:15
  • 1
    This is a "hard" problem. If you want it fast, you'll have to approximate it (google for 'ellipse arc length' if you want to know why). – etarion May 20 '11 at 11:19
  • @Peteris +1 If OP doesnt know what is binary search - it is very easy to do (when you know that you will be able to find the point, it gets a bit ugly if that there is no guarantee that that point exists). – NoSenseEtAl May 20 '11 at 16:34
  • @NoSenseEtAl: In this case the point is guaranteed to exist, but you are virtually guaranteed to not find it exactly. Therefore you have to terminate when you're within a close enough tolerance of the exact answer. – btilly May 20 '11 at 17:22
  • @btilly I know that you cant find a real number with binary search. :) My point was that if he isnt sure that d is such that there exist a point that is d from the current one it becomes a harder problem. – NoSenseEtAl May 20 '11 at 17:38
  • Problem is to find along circumference - so binary search wont work Yes i had a look at elliptic integral of second kind and i wanted to know what would be fastest implementation for it . – Anil Shanbhag May 21 '11 at 11:01
  • binary search will work, but the length is not analytical and must be computed for each new point. See my answer below – Dov May 24 '11 at 17:26

2 Answers2

3

The length of a subsection of an ellipse is an elliptic integral, with no closed form solution.

In order to compute the distance along the ellipse, you will need a numerical integration routine. I recommend Romberg, or Gauss Quadrature (look up on Wikipedia). If you are doing this repeatedly, then precompute the distance across a bunch of points around the Ellipse so that you can rapidly get to the right region, then start integrating.

You will need to bisect (look up on Wikipedia) to find the desired length.

Dov
  • 8,000
  • 8
  • 46
  • 75
  • You might want to look at numerical recipes. This is the old FORTRAN version, but they cover the math. It's worth buying the new book, 3rd ed. http://ftp.eq.uc.pt/books/NumericalRecipes/f6-11.pdf – Dov May 24 '11 at 17:33
  • I also found this library with a solver: http://www.alglib.net/specialfunctions/ellipticintegrals.php – Dov May 24 '11 at 18:15
0

There is no analytical solution for the length of an elliptical arc. This means you won't be able to plug numbers into an equation to find a result, but instead use a method of numerical integration.

Simpsons rule is very easy to implement although most likely slower than the methods mentioned in other answers.

Now that you have a way to find the length of an elliptical arc, just measure different end points until you find one of length d to some acceptable tolerance

ggStack
  • 1
  • 1