hello i want to ask a question how to make a circle in matlab and mark its center and g
I don't know matlab, so I can't help you there, but if you want to do this without rejection you can generate the points in polar coordinates. If rand()
returns a Uniform(0,1) random number, then:
r = radius * sqrt(rand())
theta = 2 * Pi * rand()
x = r * cos(theta)
y = r * sin(theta)
will yield values which are uniformly distributed within a circle of radius radius
. Note the square root on the calculation of r
, which adjusts the distribution of distance from the center of the circle so that the number of points at a given distance is always proportional to the area and hence is uniform. For spherical uniformity you'd take the cube root to keep proportionality to the volume, and in general the kth root for a k-dimensional hypersphere.