Name
Name

Reputation: 33

How to draw random points inside an ellipse?

I want to fill this ellipse with count random points inside it any help I'd be glad.

What algorithm of actions?

Upvotes: 1

Views: 981

Answers (1)

MBo
MBo

Reputation: 80325

To generate uniformly distributed points inside ellipse, use approach developed for disk and scale coordinates with needed ratio:

   generate two random values
r = A * sqrt(random(0..1))
fi = 2 * Pi * random(0..1)
  and point in ellipse with horizontal semiaxis A and vertical one B
x = center.x + r * cos(fi)
y = center.y + B / A *  r * sin(fi)

If ellipse is rotated, also rotate these coordinates enter image description here

Upvotes: 2

Related Questions