how to make circle in matlab and generate random points inside it

后端 未结 3 912
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 18:52

\"enterhello i want to ask a question how to make a circle in matlab and mark its center and g

3条回答
  •  礼貌的吻别
    2021-01-12 19:53

    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.

提交回复
热议问题