3
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by m_goldberg, bbgodfrey, MarcoB, ilian, user9660 Oct 16 '15 at 4:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    $\begingroup$ Now, which of these two is appropriate for your problem? $\endgroup$ – J. M. will be back soon Oct 15 '15 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$ – J. M. will be back soon Oct 15 '15 at 14:53
7
$\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$
  • $\begingroup$ I use "indexed" and "actual" coordinates myself, not knowing if there is more standard terminology. $\endgroup$ – J. M. will be back soon Oct 15 '15 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 Oct 15 '15 at 16:38
8
$\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$
  • $\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 Oct 15 '15 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$ – J. M. will be back soon Oct 15 '15 at 16:57

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