返回题库

用 (x,y) 生成圆盘均匀点

Random point on disk

专题
Probability / 概率
难度
L6

题目详情

给定 x,yx,y 为独立均匀随机数,取值在 (0,1)(0,1)

用它们构造单位圆盘(半径 1)的一个均匀随机点(面积密度常数)。

提示:直角坐标到极坐标;圆面积随半径平方增长。

xx & yy are two random points selected uniformly between 00 & 11. Using them, create a point uniformly random in a circle of radius 11. (uniform means that the probability density is constant)

Hint

Convert Cartesian coordinates to Polar coordinates. And the area of a circle grows with the square of its radius.

解析

θ=2πx,r=y,\theta = 2\pi x,\quad r=\sqrt{y},

再输出点

(rcosθ, rsinθ).(r\cos\theta,\ r\sin\theta).

原因:面积元素为 rdrdθr\,dr\,d\theta,要让半径分布与面积匹配,需要 r2r^2 均匀,因此 r=yr=\sqrt{y}


Original Explanation

θ=2πx\theta = 2 \pi x and r=yr = \sqrt{y}, then take the point as (rcos(θ),rsin(θ))(r \cos(\theta),r \sin(\theta))

Solution

We could generate a random point in the square and reject it if it is not in the circle. However, the question asks to transform the point, not filter it. We need to somehow manipulate the given random point (x,y)(x, y)

Initial Misstep

The coordinates of the point in the circle are then given by (rcos(θ),rsin(θ))(r \cos(\theta), r \sin{(\theta)}) where rr is the radius and θ\theta is the angle. Thus, we can use polar coordinates, xx can be converted to the angle and yy can be used as the radius.

  1. Let θ=2πx\theta = 2 \pi x, its value ranged between 00 to 2π2\pi

  2. Let r=yr = y, the radius in the polar coordinates, its value is between 0 and 1.

  3. The Polar Coordinate (r,θ)(r, \theta) can be converted to the cartesian coordinate. Thus, (ycos(2πx),ysin(2πx))(y \cos(2 \pi x), y \sin(2\pi x)) will generate a random point within the disk of radius 1.

  4. However, to ensure uniform distribution, we can't just take r=yr=y. This is because points near the center of the circle are much more likely to be chosen if we just use a uniform distribution for the radius. Consider a small ring in the circle with radius rr and thickness drdr. The area of this ring (which is a very thin circular strip) is 2πrdr2\pi \cdot r \cdot dr. A larger ring has more area and should contain more points. If we take r=yr=y, we end up with the same number of points in each ring. This means that larger rings have a lower density of points. This is not uniform.

Correct Solution

We wish to use (rcos(θ),rsin(θ))(r \cos(\theta), r \sin(\theta)) as the random point, but we need a way to make it uniform.

Uniform distribution means that the probability of finding a point in any part is proportional to the size of that part.

In the case of 1D range [0,1][0, 1], given yy is uniform, i.e. P(y1yy2)=y2y1P(y_1 \le y \le y_2) = y_2 - y_1 (where 0y1<y210 \le y_1 < y_2 \le 1)

We want the same property for the disk.

Consider an annulus (ring) between radius r1r_1 and r2r_2 (where 0r1<r210 \leq r_1 < r_2 \leq 1)

Area of annulus=πr22πr12\text{Area of annulus} = \pi r_2^2 - \pi r_1^2

We want the probability to be in proportion to this area, i.e. we want P(r1rr2)(r22r12)P(r_1 \le r \le r_2 ) \propto (r_2^2 - r_1^2)

Taking r=yr = y gives P(r1yr2)=r2r1P(r_1 \le y \le r_2 ) = r_2 - r_1, which is not proportional to the area.

But, with a leap of faith, if we take r=yr = \sqrt{y}, we get

P(r1yr2)=P(r12yr12)P(r_1 \le \sqrt{y} \le r_2 ) =P(r_1^2 \le y \le r_1^2)

=r22r12= r_2^2 - r_1^2 (because yy is uniform in the range [0,1][0, 1])

Thus, we get the desired property.

Therefore, we can take r=yr = \sqrt{y} and θ=2πx\theta = 2 \pi x to get a uniform distribution of points in the disk.