1
votes

In MATLAB, say I have the parameters for an ellipse:

  • (x,y) center
  • Minor axis radius
  • Major axis radius
  • Angle of rotation

Now, I want to generate random points that lie within that ellipse, approximated from a 2D gaussian.

My attempt thus far is this:

num_samps = 100;
data = [randn(num_samps, 1)+x_center  randn(num_samps, 1)+y_center];

This gives me a cluster of data that's approximately centered at the center, however if I draw the ellipse over the top some of the points might still be outside.

How do I enforce the axis rules and the rotation?

Thanks.

1

1 Answers

0
votes

my assumptions

x_center = h

y_center = k

Minor Axis Radius = b

Major Axis Raduis = a

rotation angle = alpha

h=0;
k=0;
b=5;
a=10;
alpha=30;
num_samps = 100;
data = [randn(num_samps, 1)+h  randn(num_samps, 1)+k];
chk=(((((data(:,1)-h).*cos(alpha)+(data(:,2)-k).*sin(alpha))./a).^2) +...
    (((data(:,1)-h).*sin(alpha)+(data(:,2)-k).*cos(alpha))./b).^2)<=1;
idx=find(chk==0);
if ~isempty(idx)
    data(idx,:)=data(idx,:)-.5*ones(length(idx),2);
end