均值坐标–Mean Value Coordinates(MVC) 是一种重要的插值技术,广泛应用于参数化、网格变形等几何处理方向。本文主要讲解Floater等人2003年发表在CAGD上的论文Mean value coordinates,主要探讨2D多边形中均值坐标的计算方法。
1. 重心坐标
对于三角形 △ v 1 v 2 v 3 \triangle v_1v_2v_3 △v1v2v3 中任一点 p p p 表示为三角形三个顶点的凸组合, 即满足如下的等式:
p = λ 1 v 1 + λ 2 v 2 + λ 3 v 3 a n d λ 1 + λ 2 + λ 3 = 1 (1) p = \lambda_1v_1 + \lambda_2v_2 + \lambda_3v_3 \ \ \ and\ \ \ \lambda_1 + \lambda_2 + \lambda_3 = 1\tag1 p=λ1v1+λ2v2+λ3v3 and λ1+λ2+λ3=1(1)
对于三角形来讲,如下图所示,权重很好计算(三角形面积之比):
{
λ
1
=
S
△
p
v
2
v
3
/
S
△
v
1
v
2
v
3
λ
2
=
S
△
p
v
1
v
3
/
S
△
v
1
v
2
v
3
λ
3
=
S
△
p
v
1
v
2
/
S
△
v
1
v
2
v
3
(2)
\left\{ \begin{aligned} \lambda_1 = S\triangle pv_2v_3 / S\triangle v_1v_2v_3\\ \lambda_2 =S\triangle pv_1v_3 / S\triangle v_1v_2v_3 \\ \lambda_3 = S\triangle pv_1v_2 / S\triangle v_1v_2v_3 \end{aligned} \tag2 \right.
⎩⎪⎨⎪⎧λ1=S△pv2v3/S△v1v2v3λ2=S△pv1v3/S△v1v2v3λ3=S△pv1v2/S△v1v2v3(2)
为什么叫重心坐标呢? 以下内容摘自知乎:重心坐标(Barycentric coordinates)
等式(1)可以转化为:
λ
1
(
v
1
−
p
)
+
λ
2
(
v
2
−
p
)
+
λ
3
(
v
3
−
p
)
=
0
\lambda_1(v_1-p) +\lambda_2(v_2-p) +\lambda_3(v_3-p) = 0
λ1(v1−p)+λ2(v2−p)+λ3(v3−p)=0
进一步可以改写为:
λ 1 p v 1 → + λ 2 p v 2 → + λ 3 p v 3 → = 0 \lambda_1\overrightarrow{pv_1} + \lambda_2\overrightarrow{pv_2} +\lambda_3\overrightarrow{pv_3} = 0 λ1pv1+λ2pv2+λ3pv3=0
相当于我们在三角形的三个顶点 v 1 v_1 v1处挂重量为 λ 1 \lambda_1 λ1, v 2 v_2 v2处挂重量为 λ 2 \lambda_2 λ2, v 3 v_3 v3处挂重量为 λ 3 \lambda_3 λ3的重物时,如果把 p p p 点放避雷针上,能保持平衡,则这种情况下 p p p 是重心。
2. 广义重心坐标
如上所述,对于三角形的重心坐标是比较容易计算的,但我们不满足于此。我们希望求解多边形内部顶点的广义重心坐标, 即将多边形内部的顶点表示为多边形顶点的凸组合:
p = ∑ i = 1 n λ i v i a n d ∑ i = 1 n λ i = 1 (3) p = \sum^{n}_{i=1}\lambda_iv_i \ \ \ and \ \ \sum^{n}_{i=1}\lambda_i = 1 \tag3 p=i=1∑nλivi and i=1∑nλi=1(3)
广义重心坐标有很多求法比如:均值坐标(MVC),格林坐标(GC),调和坐标(HC)等,这里我们介绍一下广泛使用的均值坐标(Mean Value coordinates)的计算方法。
3. 2D 均值坐标
对于一般的2D的多边形,Floater (Floater M S . Mean value coordinates[M]. Elsevier Science Publishers B. V. 2003.) 给出的均值坐标为:
p
=
∑
i
=
1
n
λ
i
v
i
a
n
d
λ
i
=
w
i
/
∑
j
=
1
n
w
j
(4)
p = \sum^{n}_{i=1}\lambda_iv_i \ \ \ and \ \ \ \lambda_i = w_i / \sum^{n}_{j=1}w_j\tag4
p=i=1∑nλivi and λi=wi/j=1∑nwj(4)
w
i
=
[
t
a
n
(
α
i
−
1
/
2
)
+
t
a
n
(
α
i
/
2
)
]
/
∣
∣
v
i
−
p
∣
∣
(5)
w_i = [tan(\alpha_{i-1}/2)+tan(\alpha_i/2)] / ||v_i-p||\tag5
wi=[tan(αi−1/2)+tan(αi/2)]/∣∣vi−p∣∣(5)
可以看出这种形式表示的坐标始终为正,下面我把这个证明过程简单搬运一下,
我们的目标是将多边形内部的点
p
p
p 表示为多边形顶点的凸组合:
p
=
∑
i
=
1
n
λ
i
v
i
a
n
d
λ
i
=
w
i
/
∑
j
=
1
n
w
j
p = \sum^{n}_{i=1}\lambda_iv_i \ \ and \ \ \lambda_i = w_i / \sum^{n}_{j=1}w_j
p=i=1∑nλivi and λi=wi/j=1∑nwj
等价于: ∑ i = 1 n ( w i / ∑ j = 1 n w j ) ( v i − p ) = 0 \sum^{n}_{i=1} (w_i / \sum^{n}_{j=1}w_j )(v_i-p) = 0 ∑i=1n(wi/∑j=1nwj)(vi−p)=0, 左右两边分别乘以 ∑ j = 1 n w j \sum^{n}_{j=1}w_j ∑j=1nwj:
∑ i = 1 n w i ( v i − p ) = 0 (6) \sum^{n}_{i=1}w_i(v_i-p) = 0\tag6 i=1∑nwi(vi−p)=0(6)
接下来,使用
p
p
p 处的极坐标表示
v
i
v_i
vi:
v
i
=
p
+
∣
∣
v
i
−
p
∣
∣
(
c
o
s
θ
i
,
s
i
n
θ
i
)
v_i = p + ||v_i-p||(cos\theta_i, sin\theta_i)
vi=p+∣∣vi−p∣∣(cosθi,sinθi)
那么有:
(
v
i
−
p
)
/
∣
∣
v
i
−
p
∣
∣
=
(
c
o
s
θ
i
,
s
i
n
θ
i
)
(7)
(v_i-p) / ||v_i-p|| = (cos\theta_i, sin\theta_i) \tag7
(vi−p)/∣∣vi−p∣∣=(cosθi,sinθi)(7)
将(5)代入(6):
∑ i = 1 n [ t a n ( α i − 1 / 2 ) + t a n ( α i / 2 ) ] ⋅ ( v i − p ) / ∣ ∣ v i − p ∣ ∣ = 0 (8) \sum^{n}_{i=1}[tan(\alpha_{i-1}/2)+tan(\alpha_i/2)]\cdot (v_i-p) / ||v_i-p|| = 0\tag8 i=1∑n[tan(αi−1/2)+tan(αi/2)]⋅(vi−p)/∣∣vi−p∣∣=0(8)
并将(7)代入(8):
∑ i = 1 n [ t a n ( α i − 1 / 2 ) + t a n ( α i / 2 ) ] ( c o s θ i , s i n θ i ) = 0 (9) \sum^{n}_{i=1}[tan(\alpha_{i-1}/2)+tan(\alpha_i/2)](cos\theta_i, sin\theta_i) = 0\tag9 i=1∑n[tan(αi−1/2)+tan(αi/2)](cosθi,sinθi)=0(9)
上式进一步等效于(注意类似于: ∑ i = 2 n = 1 \sum^{n=1}_{i=2} ∑i=2n=1表示2,3,4,…n, 0):
∑ i = 2 n = 1 t a n ( α i / 2 ) [ ( c o s θ i , s i n θ i ) + ( c o s θ i + 1 , s i n θ i + 1 ) ] = 0 (10) \sum^{n=1}_{i=2}tan(\alpha_i/2)[(cos\theta_i, sin\theta_i) + (cos\theta_{i+1}, sin\theta_{i+1})] = 0\tag{10} i=2∑n=1tan(αi/2)[(cosθi,sinθi)+(cosθi+1,sinθi+1)]=0(10)
如果能证明等式(10)成立,则多边形内部的顶点就可以用等式(5)所示的坐标表示(插值)。
首先,我们知道,从圆心指向圆周的所有单位向量之和为 0 向量,因为任意一个向量都能找出一个与之大小相等方向相反的向量。
0 = ∫ 0 2 π ( c o s θ , s i n θ ) = ∑ i = 1 k ∫ θ i θ i + 1 ( c o s θ , s i n θ ) = ∑ i = 1 k ∫ θ i θ i + 1 s i n ( θ i + 1 − θ ) s i n α i ( c o s θ i , s i n θ i ) + s i n ( θ − θ i ) s i n α i ( c o s θ i + 1 , s i n θ i + 1 ) \mathbf{0} = \int^{2\pi}_0 (cos\theta,sin\theta)= \sum^k_{i=1}\int^{\theta_{i+1}}_{\theta_i}(cos\theta,sin\theta)=\sum^k_{i=1}\int^{\theta_{i+1}}_{\theta_i}\frac{sin(\theta_{i+1}-\theta)}{sin\alpha_i}(cos\theta_i,sin\theta_i) + \frac{sin(\theta-\theta_i)}{sin\alpha_i}(cos\theta_{i+1},sin\theta_{i+1}) 0=∫02π(cosθ,sinθ)=i=1∑k∫θiθi+1(cosθ,sinθ)=i=1∑k∫θiθi+1sinαisin(θi+1−θ)(cosθi,sinθi)+sinαisin(θ−θi)(cosθi+1,sinθi+1)
这里的等式构造非常巧妙。对上式积分等于:
∑ i = 1 k ( c o s θ i , s i n θ i ) s i n α i ∫ θ i θ i + 1 s i n ( θ i + 1 − θ ) d θ + ( c o s θ i + 1 , s i n θ i + 1 ) s i n α i ∫ θ i θ i + 1 s i n ( θ − θ i + 1 ) d θ (11) \sum^k_{i=1}\frac{(cos\theta_i,sin\theta_i)}{{sin\alpha_i}}\int^{\theta_{i+1}}_{\theta_i} sin(\theta_{i+1}-\theta) d\theta + \frac{(cos\theta_{i+1},sin\theta_{i+1})}{{sin\alpha_i}}\int^{\theta_{i+1}}_{\theta_i} sin(\theta -\theta_{i+1}) d\theta \tag{11} i=1∑ksinαi(cosθi,sinθi)∫θiθi+1sin(θi+1−θ)dθ+sinαi(cosθi+1,sinθi+1)∫θiθi+1sin(θ−θi+1)dθ(11)
而 ∫ θ i θ i + 1 s i n ( θ i + 1 − θ ) d θ = ∫ θ i θ i + 1 s i n ( θ − θ i + 1 ) d θ = 1 − c o s α i \int^{\theta_{i+1}}_{\theta_i} sin(\theta_{i+1}-\theta) d\theta = \int^{\theta_{i+1}}_{\theta_i} sin(\theta -\theta_{i+1}) d\theta = 1 - cos\alpha_i ∫θiθi+1sin(θi+1−θ)dθ=∫θiθi+1sin(θ−θi+1)dθ=1−cosαi, 因此(11)计算结果为:
∑
i
=
1
k
(
1
−
c
o
s
α
i
)
(
c
o
s
θ
i
,
s
i
n
θ
i
)
s
i
n
α
i
+
(
1
−
c
o
s
α
i
)
(
c
o
s
θ
i
+
1
,
s
i
n
θ
i
+
1
)
s
i
n
α
i
(12)
\sum^k_{i=1}\frac{(1-cos\alpha_i)(cos\theta_i,sin\theta_i)}{{sin\alpha_i}} + \frac{(1-cos\alpha_i)(cos\theta_{i+1},sin\theta_{i+1})}{{sin\alpha_i}}\tag{12}
i=1∑ksinαi(1−cosαi)(cosθi,sinθi)+sinαi(1−cosαi)(cosθi+1,sinθi+1)(12)
因为:
1
−
c
o
s
α
i
s
i
n
α
i
=
t
a
n
(
α
i
/
2
)
\frac{1-cos\alpha_i}{sin\alpha_i} = tan(\alpha_i/2)
sinαi1−cosαi=tan(αi/2), 所以(12)等价于:
∑ i = 1 k t a n ( α i / 2 ) [ ( c o s θ i , s i n θ i ) + ( c o s θ i + 1 , s i n θ i + 1 ) ] (13) \sum^k_{i=1}tan(\alpha_i/2)[(cos\theta_i,sin\theta_i) + (cos\theta_{i+1},sin\theta_{i+1})] \tag{13} i=1∑ktan(αi/2)[(cosθi,sinθi)+(cosθi+1,sinθi+1)](13)
因此,等式(10)得证。