返回题库

用 (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}


英文解析

Set

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

and output

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

The angular variable is uniform on [0,2π)[0,2\pi). For a point to be uniform by area in the unit disk, the probability of falling inside radius rr must be r2r^2, because the disk area scales as πr2\pi r^2. If yy is uniform on [0,1][0,1] and r=yr=\sqrt{y}, then P(Rr)=P(yr2)=r2P(R\le r)=P(y\le r^2)=r^2, so the radial distribution matches area. Therefore this transform gives a uniform point in the disk.