Sampling only from the uniform distribution $U(0,1)$, I am hoping to use transformations to create random values distributed uniformly around the perimeter of an ellipse. Eventually, I'd like to do the same on the surfaces of ellipsoids and other problematic objects.
My first idea was as follows. We can easily get $\Theta \sim U(0,2\pi)$. Then, from the parametric form of the ellipse,
$$X \equiv a \cos \Theta \\
Y \equiv b \sin \Theta $$
is a random point on the ellipse's perimeter.
Similarly, if we independently sample another angle $\Phi \sim U(0,\pi)$, we could use
$$X \equiv a \sin \Theta \cos\Phi \\
Y \equiv b \sin \Theta \sin\Phi\\
Z \equiv c \cos \Theta $$
The problem with these approaches is that they are uniformly distributed with respect to theta, not along the surface. They are equivalent to taking a uniform distribution on a circle and then projecting about the radius to the perimeter of the ellipse, so the density of points is higher near the major axis, as you can see here:
(This is itself counterintuitive to me: One would expect the points to be denser about the minor axis since they are being "sprayed" over a more concentrated region, right?)
How can I generate points distributed uniformly about the perimeter of the ellipse?
Here is an example of what I am trying to do but using a circle instead. The transformation used there doesn't work for the ellipse because it creates the same bunching behavior.
Best Answer
The following may be of some use in this question. (Note: Some of these points have also been sketched out in the above comments-included here for completeness). In particular, the below code computes the transformation based on the following derivation:
The points on the ellipse are assumed to have the coordinates defined by $$ x=a\cos{\theta} \\ y=b\sin{\theta} \\ $$
The arclength differential $\mathrm{d}s$ along the perimeter of the ellipse is obtained from
$$ {\mathrm{d}s}^{2}={\mathrm{d}x}^{2}+{\mathrm{d}y}^{2} $$
$$ {\mathrm{d}s}^{2}=a^{2}\sin^{2}{\theta}{\mathrm{d}\theta}^{2}+b^{2}\cos^{2}{\theta}{\mathrm{d}\theta}^{2} $$
$$ {\mathrm{d}s}^{2}=\left(a^{2}\sin^{2}{\theta}+b^{2}\cos^{2}{\theta}\right){\mathrm{d}\theta}^{2} $$
$$ {\mathrm{d}s}=\sqrt{a^{2}\sin^{2}{\theta}+b^{2}\cos^{2}{\theta}}{\mathrm{d}\theta} $$
$$ \frac{{\mathrm{d}s}}{\mathrm{d}\theta}=\sqrt{a^{2}\sin^{2}{\theta}+b^{2}\cos^{2}{\theta}} $$
Now, the probability function is taken to be
$$ p\left(\theta\right)=\frac{{\mathrm{d}s}}{\mathrm{d}\theta} $$
with the interpretation that when the rate-of-change of arclength increases, we want a higher probability of sample points in that interval to keep the density of points uniform.
We can then set up the following expression:
$$ p\left(\theta\right){\mathrm{d}\theta}=p\left(x\right){\mathrm{d}x} $$
and assuming a uniform distribution for $x$:
$$ \int p\left(\theta\right){\mathrm{d}\theta}=x+K $$.
Some plots of the uncorrected and corrected ellipses are shown in the below figure, using the above derivation and code implementation below. I hope this helps.
Python code below: