Create Random Points in Elliptical Belt

5 visualizzazioni (ultimi 30 giorni)
Hi,
I need to generate uniformly distributed points inside an elliptical belt.
I know how to randomly generate uniform points inside an ellipse, but I need uniform points between two ellipses of different sizes, both centred at the origin.
Thanks!

Risposta accettata

John D'Errico
John D'Errico il 23 Nov 2020
Modificato: John D'Errico il 23 Nov 2020
If you already know how to generate random points uniformly over an elliptical region, then you already have the simple answer.
  1. Generate uniform points inside the LARGER ellipse. You will want to oversample, thus taking more points than you really need.
  2. Discard all points inside the smaller ellipse. This test is simple if you know the equation of the smaller ellipse.
  3. If the size of set that remains is greater than the final number you want to achieve, then discard some of them randomly.
  4. If the set that remains is smaller than the final number you want to achieve, then return to step 1 to generate more points to fill out the set.
This "rejection" scheme is sometimes the best and most efficient eay to generate points that are randomly distributed over a domain. It is good as long as the rejected fraction will not be too large. Since the original sampling scheme is RELATIVELY easy to generate points inside an ellipse, it is not difficult to oversample. And the test is also simple to identify points inside an ellipse.
As such, the rejection scheme as described is simple and will often be quite efficient. The only case where this becomes a problem is when the two ellipses are almost identically the same size and shape. In that case, you have other options, but they will be more intensive in terms of the code you must write, but they will also require additional computations, making the oversampling/rejection scheme best unless the rejected fraction is quite large. So I won't spend the time to discuss your alternative options at length unless there is a good reason.
The main alternative option would be to modify the scheme whereby you generate points inside the larger ellipse. The modification is not that extensive, but would require a fair amount of explanation on my part.
  4 Commenti
John D'Errico
John D'Errico il 23 Nov 2020
Excellent. As I said, rejection is often a great way to generate uniformly distributed samples.

Accedi per commentare.

Più risposte (1)

Bruno Luong
Bruno Luong il 23 Nov 2020
Modificato: Bruno Luong il 23 Nov 2020
If the two ellipse has the same aspect ratio and aligned then this is the method without rejection.
n=1e4;
ax=3;
ay=1;
rint=1;
rext=2;
% "Straight" ellipse bell
% B = { (x,y) in R^2 st
% (x/axext)+^2 + (y/ayext)+^2 < 1 &
% (x/axint)+^2 + (y/ayint)+^2 > 1
% ellipses have the same aspect
% axint = ax*rint; ayint = ay*rint;
% axext = ax*rext; ayext = ay*rext;
% generate n points in B
xy=randn(2,n);
rxy=sqrt(sum(xy.^2,1));
r=rint^2+rand(1,size(xy,2))*(rext^2-rint^2);
xy=xy.*(r.^(1/2)./rxy);
xy=[ax;ay].*xy;
x=xy(1,:);
y=xy(2,:);
plot(x,y,'.')
axis equal
And it works just fine on thin-bell (rext=1.05)
or supper thin rext=1.001

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by