Simplest way to plot points randomly inside a circle

前端 未结 3 1613
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 11:20

I have a basic JSFiddle whereby I want to have random points plotted inside a circle.

But I do not know how to limit the points to be inside the circle.

This is

3条回答
  •  盖世英雄少女心
    2021-02-06 11:56

    Randomly pick dSquared (0..radius^2) and theta (0..2pi), then

    x = sqrt(dSquared) cos(theta)
    y = sqrt(dSquared) sin(theta)
    

提交回复
热议问题