5
$\begingroup$

I want to generate a list of n coordinate points which are on the circumference of an ellipse. I wrote this code:

n = 150;

ellipseFunc[a_,b_,t_] := {(a*b*Cos[t]/Sqrt[b*b*Cos[t]*Cos[t] + a*a*Sin[t]*Sin[t]]), (a*b*Sin[t]/Sqrt[b*b*Cos[t]*Cos[t] + a*a*Sin[t]*Sin[t]])};

listell = Table[ellipseFunc123[4, 1, (i - 1)*2*Pi/n], {i, 1, n}];

Graphics[{Red, PointSize[0.01], Point@listell, Blue,Circle[{0, 0}, {4, 1}]}]

This results in an image like this

enter image description here

However, I want the n points to be equidistant on the circumference of the ellipse. The problem with this approach is that of taking equal angles to compute coordinates. I checked onto this question for circle. But most of the answers take similar approach which works well for a circle but not for an ellipse.

$\endgroup$
2
  • 3
    $\begingroup$ Now, which of these two is appropriate for your problem? $\endgroup$ Commented Oct 15, 2015 at 14:50
  • 2
    $\begingroup$ (In fact, things are slightly easier here than in the general case, since the elliptic integral of the second kind (EllipticE[]) is built-in.) $\endgroup$ Commented Oct 15, 2015 at 14:53

2 Answers 2

9
$\begingroup$

As @JM pointed out, this has been discussed before. My favorite method was mentioned by Vitaly Kaurov in his answer to this question: Generating evenly spaced points on a curve, and it relies on letting ParametricPlot do all the work for you by using the MeshFunctions -> {"ArcLength"} option (here I am using ellipseFunc, i.e. your own parametrization of the ellipse, with some arbitrary numbers):

points = Cases[
  Normal@
    (plot = ParametricPlot[
         ellipseFunc[10, 3, t], {t, 0, 2 Pi},
         Mesh -> 45, MeshFunctions -> {"ArcLength"}
       ]),
    Point[l_] -> l, Infinity
  ];

Show[
  plot, Graphics[{PointSize[0.015], Red, Point@points}],
  AspectRatio -> Automatic
]

Mathematica graphics

As a side note, ParametricPlot returns a form of Graphics that uses a GraphicsComplex object and "relative coordinates" (for lack of a better term). However, it is easier to deal with absolute coordinates, so I turned the GraphicsComplex into a plain Graphics object using Normal before extracting the Point expressions.

$\endgroup$
3
  • $\begingroup$ I use "indexed" and "actual" coordinates myself, not knowing if there is more standard terminology. $\endgroup$ Commented Oct 15, 2015 at 16:14
  • $\begingroup$ @J.M. I like "indexed": that makes sense to me. That's what I should call them from now on! $\endgroup$
    – MarcoB
    Commented Oct 15, 2015 at 16:38
  • $\begingroup$ @MarcoB I just noticed that the ellipse looks like it always has a gap. In your image, it has a gap on the end of the ellipse on the right. A gap shows every time I try the code on an ellipse. $\endgroup$
    – Teg Louis
    Commented Feb 16 at 1:20
9
$\begingroup$

J.M.'s suggestion to use EllipticE can be implemented like this:

sample[t_, {a_, b_}] := {a Cos[theta], b Sin[theta]} /. FindRoot[b EllipticE[theta, 1 - a^2/b^2] - t, {theta, 0}]

samples[n_, {a_, b_}] := Module[{perimeterLength},
  perimeterLength = 4 b EllipticE[1 - a^2/b^2];
  Table[sample[t, {a, b}], {t, 0, perimeterLength, perimeterLength/n}]
  ]

ListPlot@samples[45, {10, 3}]

Mathematica graphics

Of course, ArcLength can be used just as well, but I thought I should post this as it distinguishes this question from the previous ones.

$\endgroup$
2
  • $\begingroup$ C. E., nice! Thanks for putting this together; I was curious to follow up on that suggestion myself to see how it would be used. (+1) $\endgroup$
    – MarcoB
    Commented Oct 15, 2015 at 16:40
  • 1
    $\begingroup$ We are fortunate here that Mathematica is able to evaluate the elliptic integrals when the parameter (second argument) is negative. In most other computing environments, the parameter is restricted to the interval $[0,1)$; in which case, the arclength function used is a (EllipticE[t + π/2, 1 - (b/a)^2] - EllipticE[1 - (b/a)^2]), and the circumference is thus 4 a EllipticE[1 - (b/a)^2]. Note that in this formulation, the parameter is equal to the square of the ellipse's eccentricity. $\endgroup$ Commented Oct 15, 2015 at 16:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.