How to randomly select a point in a circle with a radius of 1

Source: Internet
Author: User

The first thought of most people getting this question is

Select a random point in the square of the X axis [-] and y axis. Then, determine whether the vertex is in the circle (by calculating the distance from this vertex to the center of the circle ). If it is in the circle, this point is the result. If it is not in the circle, it is re-selected until it is found. The square area is 4, and the circle area is pi. Therefore, the probability of random points in the Square within the circle is PI/4.

If you are familiar with machine learning algorithms, this method is calledReject sampling.It is to use a probability distribution that is easy to generate (this is the uniform distribution of squares) to simulate the probability that is not easy to generate.

To simulate uniform distribution on the unit circle, it is necessary to simulate a probability distribution.FRandom Variable, whereFYes.

We select g to be evenly distributed on a square with a center at the origin and a side length of 2.

Note that the probability of falling into the circle is PI/4 (the area of the circle is pi, and the area of the square is 4). The probability of not falling into the circle is 1-PI/4, the probability that K tests do not fall into the circle is (1-PI/4) ^ K. When k = 20, the result is similar. 00000000000004. When k = 50, it is approximately 10 ^ {-34}. It takes some time.

Another method is

Select an angle randomly from [* PI), corresponding to a radius in the circle, and then select a point on the radius. However, the points on the radius cannot be evenly selected. The selected probability should be proportional to the length from the center of the circle, so that the random points are evenly distributed within the circle.

Http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.