# 理论

## 概率论知识回顾

P x ( x ) = P r ( X ≤ x ) P_x(x)=Pr(X\leq x)

P x ( x ) = ∫ − ∞ x p x ( t ) d t P_x(x)=\int_{-\infty}^xp_x(t)dt

p x ( x ) = d d x P x ( x ) p_x(x) = \frac{d}{dx}P_x(x)

CDF和PDF有一些非常实用的性质，例如

∫ − ∞ ∞ p x ( x ) d x = 1 \int_{-\infty}^{\infty} p_x(x)dx = 1

### 随机变量之间的转换

P r ( Y ≤ y ( x ) ) = P r ( X ≤ x ) Pr(Y\leq y(x)) = Pr(X\leq x)

P y ( y ) = P y ( y ( x ) ) = P x ( x ) p y ( y ) d y d x = p x ( x ) p y ( y ) = ( d y d x ) − 1 p x ( x ) \begin{aligned} P_y(y)=P_y(y(x)) & =P_x(x) \\ p_y(y)\frac{dy}{dx} & =p_x(x) \\ p_y(y) & =\left(\frac{dy}{dx}\right)^{-1}p_x(x) \end{aligned}

p y ( y ) = p x ( x ) ∣ J T ( x ) ∣ p_y(y)=\frac{p_x(x)}{|J_T(x)|}

J T ( x ) = ( ∂ T 1 / ∂ x 1 ⋯ ∂ T 1 / ∂ x n ⋮ ⋱ ⋮ ∂ T n / ∂ x 1 ⋯ ∂ T n / ∂ x n ) J_T(x) = \begin{pmatrix} \partial T_1/\partial x_1 & \cdots & \partial T_1/\partial x_n \\ \vdots & \ddots & \vdots \\ \partial T_n/\partial x_1 & \cdots & \partial T_n/\partial x_n \\ \end{pmatrix}

x = r cos ⁡ θ y = r sin ⁡ θ \begin{aligned} x & = r\cos \theta \\ y & = r\sin \theta \\ \end{aligned}

J T ( x ) = ( ∂ x / ∂ r ∂ x / ∂ θ ∂ y / ∂ r ∂ y / ∂ θ ) = ( cos ⁡ θ − r sin ⁡ θ sin ⁡ θ r cos ⁡ θ ) J_T(x) = \begin{pmatrix} \partial x/\partial r & \partial x/\partial \theta \\ \partial y/\partial r & \partial y/\partial \theta \\ \end{pmatrix}= \begin{pmatrix} \cos \theta & -r\sin \theta \\ \sin \theta & r\cos \theta \\ \end{pmatrix}

p ( r , θ ) = r p ( x , y ) p(r,\theta)=rp(x,y)

x = r sin ⁡ θ cos ⁡ ϕ y = r sin ⁡ θ sin ⁡ ϕ z = r cos ⁡ θ \begin{aligned} x & = r\sin\theta\cos\phi \\ y & = r\sin\theta\sin\phi \\ z & = r\cos\theta \end{aligned}

p ( r , θ , ϕ ) = r 2 sin ⁡ θ p ( x , y , z ) p(r,\theta, \phi)=r^2\sin\theta p(x,y,z)

### 边缘概率

p ( x ) = ∫ p ( x , y ) d y p(x) = \int p(x,y) dy

### 条件概率

P r ( X ∣ Y ) = P r ( X ∩ Y ) P r ( Y ) Pr(X|Y) = \frac{Pr(X\cap Y)}{Pr(Y)}

p ( x ∣ y ) = p ( x , y ) p ( y ) p(x|y)=\frac{p(x, y)}{p(y)}

## 立体角

d ω = s i n θ d θ d ϕ d\omega = sin\theta d\theta d\phi

## 求解思路

1. 用PDF来描述题目要求，求出所有变量的联合PDF
2. 求出第一个变量的边缘PDF
3. 根据已知的边缘PDF或条件PDF，依次求其余变量的条件PDF
4. 求所有变量的CDf，并令其分别等于 ξ i \xi_i
5. 求出各个变量和 ξ i \xi_i 的关系

# 实践

## 单位圆盘均匀采样

p ( x , y ) = 1 π p(x,y) = \frac{1}{\pi}

p ( r , θ ) = r p ( x , y ) = r π p(r,\theta)=rp(x,y)=\frac{r}{\pi}

p ( r ) = ∫ 0 2 π p ( r , θ ) d θ = 2 r p(r) = \int_0^{2\pi}p(r,\theta)d\theta=2r

p ( θ ∣ r ) = p ( r , θ ) p ( r ) = 1 2 π p(\theta | r)=\frac{p(r,\theta)}{p(r)}=\frac{1}{2\pi}

P ( r ) = r 2 P ( θ ) = θ 2 π \begin{aligned} P(r) & = r^2 \\ P(\theta) & = \frac{\theta}{2\pi} \end{aligned}

r = ξ 1 θ = 2 π ξ 2 \begin{aligned} r & = \sqrt{\xi_1}\\ \theta & = 2\pi\xi_2 \end{aligned}

## 单位半球面均匀采样

p ( ω ) = 1 2 π p(\omega) = \frac{1}{2\pi}

p ( θ , ϕ ) = p ( ω ) sin ⁡ θ = sin ⁡ θ 2 π p(\theta, \phi) = p(\omega)\sin\theta=\frac{\sin\theta}{2\pi}

p ( θ ) = ∫ 0 2 π p ( θ , ϕ ) d ϕ = sin ⁡ θ p ( ϕ ∣ θ ) = p ( θ , ϕ ) p ( θ ) = 1 2 π \begin{aligned} p(\theta) & = \int_0^{2\pi}p(\theta, \phi)d\phi=\sin\theta\\ p(\phi | \theta) & = \frac{p(\theta, \phi)}{p(\theta)} = \frac{1}{2\pi} \end{aligned}

P ( θ ) = ∫ 0 θ sin ⁡ θ ′ d θ ′ = 1 − cos ⁡ θ P ( ϕ ) = ∫ 0 ϕ 1 2 π d ϕ ′ = ϕ 2 π \begin{aligned} P(\theta) & = \int_0^\theta\sin\theta'd\theta' = 1 - \cos\theta\\ P(\phi) & = \int_0^\phi\frac{1}{2\pi}d\phi' = \frac{\phi}{2\pi} \end{aligned}

θ = arccos ⁡ ( 1 − ξ 1 ) ϕ = 2 π ξ 2 \begin{aligned} \theta & = \arccos(1-\xi_1) \\ \phi & = 2\pi\xi_2 \end{aligned}

p ( ω ) = 1 4 π p ( θ , ϕ ) = p ( ω ) sin ⁡ θ = sin ⁡ θ 4 π p ( θ ) = ∫ 0 2 π p ( θ , ϕ ) d ϕ = sin ⁡ θ 2 P ( θ ) = 1 − cos ⁡ θ 2 θ = arccos ⁡ ( 1 − 2 ξ 1 ) \begin{aligned} p(\omega) & =\frac{1}{4\pi} \\ p(\theta, \phi) & = p(\omega)\sin\theta=\frac{\sin\theta}{4\pi} \\ p(\theta) & = \int_0^{2\pi}p(\theta, \phi)d\phi=\frac{\sin\theta}{2} \\ P(\theta) & = \frac{1 - \cos\theta}{2}\\ \theta & = \arccos(1-2\xi_1) \end{aligned}

## 单位半球面余弦采样

∫ p ( ω ) = 1 ∫ 0 2 π ∫ 0 π 2 c cos ⁡ θ sin ⁡ θ d θ d ϕ = 1 c = 1 π p ( θ , ϕ ) = 1 π cos ⁡ θ sin ⁡ θ \begin{aligned} \int p(\omega) & = 1 \\ \int_0^{2\pi}\int_0^\frac{\pi}{2} c \cos\theta \sin\theta d\theta d\phi &= 1 \\ c & = \frac{1}{\pi} \\ p(\theta, \phi) & = \frac{1}{\pi}\cos\theta\sin\theta \end{aligned}

p ( θ ) = ∫ 0 2 π p ( θ , ϕ ) d ϕ = 2 cos ⁡ θ sin ⁡ θ = sin ⁡ 2 θ p ( ϕ ∣ θ ) = p ( θ , ϕ ) p ( θ ) = 1 2 π \begin{aligned} p(\theta) & = \int_0^{2\pi}p(\theta, \phi)d\phi= 2\cos\theta\sin\theta = \sin 2\theta \\ p(\phi | \theta) & = \frac{p(\theta, \phi)}{p(\theta)} = \frac{1}{2\pi} \end{aligned}

P ( θ ) = ∫ 0 θ 2 cos ⁡ θ ′ sin ⁡ θ ′ d θ ′ = 1 − cos ⁡ 2 θ 2 P ( ϕ ) = ∫ 0 ϕ 1 2 π d ϕ ′ = ϕ 2 π \begin{aligned} P(\theta) & = \int_0^\theta 2\cos\theta'\sin\theta'd\theta' = \frac{1-\cos 2\theta}{2} \\ P(\phi) & = \int_0^\phi\frac{1}{2\pi}d\phi' = \frac{\phi}{2\pi} \end{aligned}

θ = arccos ⁡ ( 1 − ξ 1 ) ϕ = 2 π ξ 2 \begin{aligned} \theta & = \arccos(\sqrt{1-\xi_1}) \\ \phi & = 2\pi\xi_2 \end{aligned}

r = ξ 1 r = \sqrt{\xi_1}

## 球体均匀采样

p ( x , y , z ) = c p(x,y,z) = c

p ( x , y , z ) = 3 4 π R 3 p(x,y,z) = \frac{3}{4\pi R^3}

p ( r , θ , ϕ ) = ∣ J T ∣ p ( x , y , z ) = r 2 sin ⁡ θ ⋅ 3 4 π R 3 = 3 sin ⁡ θ r 2 4 π R 3 \begin{aligned} p(r,\theta, \phi) = |J_T| p(x,y,z) & = r^2\sin\theta \cdot \frac{3}{4\pi R^3}\\ & = \frac{3\sin\theta r^2}{4\pi R^3} \end{aligned}

p ( r ) = ∫ 0 2 π ∫ 0 π p ( r , θ , ϕ ) d θ d ϕ = 3 r 2 R 3 p ( θ ∣ r ) = ∫ 0 2 π p ( r , θ , ϕ ) d ϕ p ( r ) = sin ⁡ θ 2 p ( ϕ ∣ r , θ ) = p ( r , θ , ϕ ) p ( θ ∣ r ) p ( r ) = 1 2 π \begin{aligned} p(r) & = \int_0^{2\pi}\int_0^{\pi}p(r,\theta,\phi)d\theta d\phi = \frac{3 r^2}{R^3} \\ p(\theta|r) & = \frac{\int_0^{2\pi}p(r,\theta,\phi)d\phi}{p(r)} = \frac{\sin\theta}{2} \\ p(\phi | r, \theta) & = \frac{p(r,\theta, \phi)}{p(\theta|r) p(r)} = \frac{1}{2\pi} \end{aligned}

P ( r ) = r 3 R 3 P ( θ ) = 1 − cos ⁡ θ 2 P ( ϕ ) = ϕ 2 π \begin{aligned} P(r) & = \frac{r^3}{R^3}\\ P(\theta) & = \frac{1-\cos\theta}{2} \\ P(\phi) & = \frac{\phi}{2\pi} \end{aligned}

r = R ⋅ ξ 1 3 θ = arccos ⁡ ( 1 − 2 ξ 2 ) ϕ = 2 π ξ 3 \begin{aligned} r & = R\cdot\sqrt[3]{\xi_1} \\ \theta & = \arccos(1-2\xi_2) \\ \phi & = 2\pi\xi_3 \end{aligned}

## 三角形均匀采样

1. 需要构建一个凸包，这个操作对平面三角形还不麻烦，但是对三维空间的三角形就相对繁琐；
2. 需要对一半的点做映射；

( x , y ) = u A B → + v A C → x = u ∣ ∣ A B cos ⁡ A ∣ ∣ + v ∣ ∣ A C ∣ ∣ y = u ∣ ∣ A B sin ⁡ A ∣ ∣ \begin{aligned} (x,y) & = u\overrightarrow{AB} + v\overrightarrow{AC} \\ x & = u||AB\cos A|| + v||AC|| \\ y & = u||AB\sin A|| \end{aligned}

J T = ∂ ( x , y ) ∂ ( u , v ) = ( ∣ ∣ A B cos ⁡ A ∣ ∣ ∣ ∣ A C ∣ ∣ ∣ ∣ A B sin ⁡ A ∣ ∣ 0 ) ∣ J T ∣ = ∣ ∣ A B ⋅ A C sin ⁡ A ∣ ∣ \begin{aligned} J_T & = \frac{\partial(x,y)}{\partial(u,v)} = \begin{pmatrix} ||AB\cos A|| & ||AC|| \\ ||AB\sin A|| & 0 \\ \end{pmatrix} \\ |J_T| & = ||AB \cdot AC\sin A|| \\ \end{aligned}

p ( x , y ) = 1 S = 2 ∣ ∣ A B ⋅ A C sin ⁡ A ∣ ∣ p(x,y) = \frac{1}{S} = \frac{2}{||AB \cdot AC\sin A||}

p ( u , v ) = p ( x , y ) ∗ ∣ J T ∣ = 2 \begin{aligned} p(u,v) & = p(x,y) * |J_T| = 2 \end{aligned}

p ( u ) = ∫ 0 1 − u p ( u , v ) d v = 2 ( 1 − u ) p ( v ∣ u ) = p ( u , v ) p ( u ) = 1 1 − u \begin{aligned} p(u) & = \int_0^{1-u}p(u,v)dv = 2(1-u) p(v|u) & = \frac{p(u,v)}{p(u)} = \frac{1}{1-u} \end{aligned}

P ( u ) = ∫ 0 u p ( u ′ ) d u ′ = 2 u − u 2 P ( v ) = ∫ 0 v p ( v ′ ∣ u ) d v ′ = v 1 − u \begin{aligned} P(u) & =\int_0^up(u')du'=2u-u^2 \\ P(v) & =\int_0^vp(v'|u)dv'=\frac{v}{1-u} \end{aligned}

u = 1 − ξ 1 v = ξ 2 ξ 1 \begin{aligned} u & = 1-\sqrt\xi_1 \\ v & = \xi_2\sqrt\xi_1 \end{aligned}

P = ( 1 − ξ 1 ) A + ( ξ 2 ξ 1 ) B + ( ξ 1 ( 1 − ξ 2 ) ) C P = (1-\sqrt\xi_1)A + (\xi_2\sqrt\xi_1)B + (\sqrt\xi_1(1-\xi_2))C

# 参考资料

1. 立体角(Solid Angle)详解
2. Physically based rendering, 3rd edition.
3. StackExchange上对这个问题的讨论：q18686，但是这个讨论里面的答案都是从特例证明这个结论的正确性，个人觉得证明不够完善。

04-18 3307

09-20 2万+
12-28 8368
01-16 3884
04-18 104
04-20 754
05-24 2625
07-16 248
07-23 12万+
07-11 755
04-08 662
12-22 1万+
04-19 4883
03-21 3万+
07-19 1791
07-03 1573
12-19 1261
01-02 1万+