实际上是纹理映射的知识,所以本文只讨论球体局部直角坐标系
转为球面坐标系
球面坐标系中,P点为单位球上一点,描述P需要2个参数 ( ϕ , θ ) (\phi,\theta) (ϕ,θ)
\qquad 如果我们定义 ∠ θ ∠θ ∠θ 为天顶角,即OP与线段OB之间的夹角, ∠ ϕ ∠\phi ∠ϕ 为方位角,即线段OP在 x O z xOz xOz平面的投影与y轴正向的夹角,这个夹角不同地方定义的不太一样,但是推导方式没任何区别。在这种定义方式下则他们的取值范围是:
ϕ ∈ ( 0 , 2 π ) θ ∈ ( − π / 2 , π / 2 ) \phi∈(0,2π)\qquadθ∈(-\pi/2,\pi/2) ϕ∈(0,2π)θ∈(−π/2,π/2)
根据三角函数公式很简单就能推出直角坐标系与球面坐标系的关系(注:半径 r = 1
)
x
=
∣
B
D
∣
=
O
B
⋅
s
i
n
ϕ
,
O
B
=
1
⋅
c
o
s
θ
,
∴
x
=
s
i
n
ϕ
⋅
c
o
s
θ
x = |BD|=OB·sin\phi, OB=1·cosθ ,∴x=sin\phi·cosθ
x=∣BD∣=OB⋅sinϕ,OB=1⋅cosθ,∴x=sinϕ⋅cosθ
y
=
∣
O
D
∣
=
O
B
⋅
c
o
s
ϕ
,
O
B
=
1
⋅
c
o
s
θ
,
∴
y
=
c
o
s
φ
⋅
c
o
s
θ
y = |OD|=OB·cos\phi ,OB = 1·cosθ,∴y=cosφ· cosθ
y=∣OD∣=OB⋅cosϕ,OB=1⋅cosθ,∴y=cosφ⋅cosθ
z
=
s
i
n
θ
z = sinθ
z=sinθ
即:
x
=
s
i
n
ϕ
⋅
c
o
s
θ
y
=
c
o
s
ϕ
⋅
c
o
s
θ
z
=
s
i
n
θ
\large\color{red} x=sin\phi·cosθ\\ y=cos\phi· cosθ\\ z = sinθ
x=sinϕ⋅cosθy=cosϕ⋅cosθz=sinθ
从直角坐标系
转到球面坐标系
即为上面过程的逆
- 由 x = s i n ϕ ⋅ c o s θ , y = c o s ϕ ⋅ c o s θ x=sin\phi·cosθ,y=cos\phi· cosθ x=sinϕ⋅cosθ,y=cosϕ⋅cosθ,可知 x y = t a n ( ϕ ) \displaystyle\frac{x}{y}=tan(\phi) yx=tan(ϕ)
- ϕ = a r c t a n ( x y ) \displaystyle\color{red}\phi = arctan(\frac{x}{y}) ϕ=arctan(yx)
- θ = a r c s i n ( z ) \color{red}\theta=arcsin(z) θ=arcsin(z)
如果要用球面坐标映射一张图像
(1)球面空间
映射到纹理空间
- 球面坐标系目前的范围是 ϕ ∈ ( 0 , 2 π ) , θ ∈ ( − π / 2 , π / 2 ) \phi∈(0,2π),θ∈(-\pi/2,\pi/2) ϕ∈(0,2π),θ∈(−π/2,π/2),
- 对于球面某个点
(
ϕ
,
θ
)
(\phi,θ)
(ϕ,θ)转换到纹理空间的uv坐标为
u = ϕ / 2 π v = ( θ + π 2 ) π \displaystyle \color{red}\mathbf {\large u =\phi/2\pi} \qquad \large\mathbf{v = \frac{(θ+\frac{\pi}{2})}{\pi}} u=ϕ/2πv=π(θ+2π)
(2)纹理空间
映射到图像空间
- 第一步中对于从球面空间映射到纹理空间的一个点 ( u , v ) (u,v) (u,v)
- 这个点应该映射到图像空间的某个像素
(
i
,
j
)
(i,j)
(i,j)上
i = u ∗ ( w i d t h − 1 ) j = v ∗ ( h e i g h t − 1 ) \large\color{red} \mathbf{i = u * (width - 1)}\\ \mathbf{j=v * (height - 1)} i=u∗(width−1)j=v∗(height−1)