摘要:四元数插值四个方法Slerp、Squad、Spicv和Sping既复杂又很重要,为了详细阐述,故每个方法独立成一篇博文讲解。没有插值的四元数是没有灵魂的,插值的重要性不言而喻。Slerp是经典的两点间一阶连续可导插值方法,Squad方法在Slerp的基础上实现多点间的一阶连续可导,Spicv是多点间连续解析解插值方法,而Sping则是多点间离散数值解插值方法,更适合复杂曲线,此博文也是国内首篇介绍Spicv和Sping的中文资料。
由《四元数多点连续解析解插值方法:Spicv》可知:虽然连续解析解过程推导严密,但遗憾的是,我们不能给出最优插值曲线的解析表达式。因此,我们将尝试提出一个用数值方法来解决问题的离散数值解版本。
首先我们把这个问题写成等价的离散形式,然后尝试梯度下降解决这个新版本的问题。由于插值算法使用数值解并用到梯度,所以命名为Sping(Spherical Interpolation using Nmerical Gradient descent)。
注释:原论文将此算法命名为Spring,但这个名字太普遍,容易混淆,所以笔者将其精简为Sping,更容易记忆,也减少重名。
现在回顾一下曲率平方的积分 K ( γ ) K(\gamma) K(γ)的概念:给定控制点 Q 1 , . . . , Q k ∈ H 1 Q_{1},...,Q_{k}\in H_{1} Q1,...,Qk∈H1,求 γ ( t ) ∈ C 2 ( I , H 1 ) \gamma(t)\in C^{2}(I,H_{1}) γ(t)∈C2(I,H1),使存在 t 1 , . . . , t k ∈ ( I ) t_{1},...,t_{k}\in (I) t1,...,tk∈(I),满足 γ ( t i ) = Q i \gamma(t_{i})=Q_{i} γ(ti)=Qi,并使下列表达式最小化: K ( γ ) = ∫ t 1 t N ∥ κ ( γ , t ) ∥ 2 d t (1.1) K(\gamma)=\int_{t_{1}}^{t_{N}}\left \| \kappa (\gamma,t) \right \|^{2}dt\tag{1.1} K(γ)=∫t1tN∥κ(γ,t)∥2dt(1.1)据此在离散版本中进行改写,我们将尝试解决以下问题:
给定控制点 Q 1 , . . . , Q k ∈ H 1 Q_{1},...,Q_{k}\in H_{1} Q1,...,Qk∈H1,寻找 q 1 , . . . , q N ∈ H 1 ( N ≥ k ) q_{1},...,q_{N}\in H_{1}(N\geq k) q1,...,qN∈H1(N≥k),对于 t = 1 , . . . , k t=1,...,k t=1,...,k有 q i t = Q t q_{i_{t}}=Q_{t} qit=Qt,并使下列表达式最小化: E = ∑ i = 1 N l ( q i ) ∥ κ ~ ( q i ) ∥ 2 (1.2) E=\sum_{i=1}^{N}l(q_{i})\left \| \tilde{\kappa}(q_{i}) \right \|^{2}\tag{1.2} E=i=1∑Nl(qi)∥κ~(qi)∥2(1.2)可见积分被求和代替了,我们积分区间的参数宽度称为 l ( q i ) l(q_{i}) l(qi),它可以表示为第 i i i个四元数前后间隔内参数宽度的中值: l ( q i ) = ∥ q i − q i − 1 ∥ + ∥ q i − q i + 1 ∥ 2 (1.3) l(q_{i})=\frac{\left \| q_{i}-q_{i-1} \right \|+\left \| q_{i}-q_{i+1} \right \|}{2}\tag{1.3} l(qi)=2∥qi−qi−1∥+∥qi−qi+1∥(1.3)在 l ( q i ) l(q_{i}) l(qi)的近似中, q i q_{i} qi和 q i − 1 q_{i-1} qi−1之间的参数化距离的另一种度量方法是角度 θ i \theta _{i} θi,它须满足 cos θ i = q i ⋅ q i + 1 \cos \theta _{i}=q_{i}\cdot q_{i+1} cosθi=qi⋅qi+1。
方程 ( 1.2 ) (1.2) (1.2)中另一个参数 κ ~ \tilde{\kappa} κ~,它表示局部曲率的离散版: k ~ ( q i ) = q i ′ ′ − q i ′ ′ ⋅ q i q i ⋅ q i q i (1.4) \tilde{k}(q_{i})=q_{i}^{''}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}q_{i}\tag{1.4} k~(qi)=qi′′−qi⋅qiqi′′⋅qiqi(1.4)请注意,在定义局部曲率时,分母 q i ⋅ q i q_{i}\cdot q_{i} qi⋅qi没有被忽略(如上篇中方程 ( 3.1 ) (3.1) (3.1))。这是因为插值的四元数不一定为单位四元数,此部分请参考第2.1节。因此分母的值一般不等于1,所以它不能被省略。
在方程 ( 1.4 ) (1.4) (1.4)中,使用的是插值曲线的离散近似的二阶导数。二阶导数的一个很好的中心近似是1: q i ′ ′ = q i − 1 − 2 q i + q i + 1 l ( q i ) 2 (1.5) q_{i}^{''}=\frac{q_{i-1}-2q_{i}+q_{i+1}}{l(q_{i})^{2}}\tag{1.5} qi′′=l(qi)2qi−1−2qi+qi+1(1.5)
本节尝试求解方程 ( 1.2 ) (1.2) (1.2),它可以用梯度下降法最小化。一般来说,梯度下降法可以描述如下:将被最小化的函数图像(通常称为能量函数)视为有坡度的丘陵,其中的函数值是每组坐标上的丘陵高度,函数在某点的梯度表示它最陡的上坡方向。梯度下降是基于对解的初始估计,从最初的估计开始计算梯度,并在梯度的相反方向上迈出一小步(即下山),从而产生一个新的点。这个过程在新的点上不断重复,直到函数值不再通过走一步变得更小,在这个过程中,梯度下降法产生一个近似的局部最小值。梯度下降理论的思想大致如此,不再做详细解释,但是我们将对推导方法进行足够详细的描述,以便那些在该领域没有前置知识的读者仍然能理解其推导过程。
当使用如梯度下降法的数值近似方法时,通常需要对解空间的进行限制;相反,如果解位于期望解空间之外,则会添加一个使解付出更大代价的附加项。据此我们寻找一个函数,它可以确定离散版本的插值曲线是否在 H 1 H_{1} H1中,因此此函数是由单位四元数组成的,可通过下式实现: g ( q ) = q ⋅ q − 1 (1.6) g(q)=q\cdot q-1\tag{1.6} g(q)=q⋅q−1(1.6)其中: H 1 = { q ∈ H ∣ g ( q ) = 0 } H_{1}= \{ q\in H|g(q)=0 \} H1={q∈H∣g(q)=0},即当 g ( q ) = 0 g(q)=0 g(q)=0时, q q q是单位四元数。确定四元数是否为单位四元数的方法,可以与能量函数 E E E结合成新的能量函数 F F F: F = ∑ i = 1 N l ( q i ) ∥ κ ( q i ) ~ ∥ 2 + c g ( q i ) 2 (1.7) F=\sum_{i=1}^{N}l(q_{i})\left \| \tilde{\kappa(q_{i})} \right \|^{2}+cg(q_{i})^{2}\tag{1.7} F=i=1∑Nl(qi)∥∥∥κ(qi)~∥∥∥2+cg(qi)2(1.7)假设 c ∈ R c\in \mathbb{R} c∈R为相匹配的实数,当 E E E在某处取最小值时,能量函数 F F F也近似有一个最小值,在这里所有的 q i q_{i} qi为近似单位四元数。
我们想用梯度下降法找到方程 ( 1.7 ) (1.7) (1.7)中 F F F的最小值,因此我们必须求出梯度。下面,我们将 q i , x q_{i,x} qi,x记为离散插值曲线第 i i i个四元数中的第 x x x坐标,其中 x ∈ 1 , 2 , 3 , 4 x\in{1,2,3,4} x∈1,2,3,4,将四元数视为四维向量,因此梯度是 4 N 4N 4N维的。 F F F关于每个坐标的偏导可以写成: ∂ F ∂ q i , x = ∂ ∂ q i , x ( ∑ j = 1 N l ( q j ) ∥ κ ~ ( q j ) ∥ 2 + c g ( q j ) 2 ) \frac{\partial F}{\partial q_{i,x}}=\frac{\partial }{\partial q_{i,x}}\left ( \sum_{j=1}^{N} l(q_{j}) \left \| \tilde{\kappa}(q_{j}) \right \|^{2} + cg(q_{j})^{2} \right ) ∂qi,x∂F=∂qi,x∂(j=1∑Nl(qj)∥κ~(qj)∥2+cg(qj)2)在方程 ( 1.3 ) , ( 1.4 ) , ( 1.5 ) (1.3),(1.4),(1.5) (1.3),(1.4),(1.5)中, q i q_{i} qi存在于算法中的 l ( q i − 1 ) , l ( q i ) , l ( q i + 1 ) , κ ~ ( q i − 1 ) , κ ~ ( q i ) , κ ~ ( q i + 1 ) l(q_{i-1}),l(q_{i}),l(q_{i+1}),\tilde{\kappa}(q_{i-1}),\tilde{\kappa}(q_{i}),\tilde{\kappa}(q_{i+1}) l(qi−1),l(qi),l(qi+1),κ~(qi−1),κ~(qi),κ~(qi+1),因此相应的项必然出现在偏导中,因此有: ∂ F ∂ q i , x = ∂ ∂ q i , x ( l ( q i − 1 ) ∥ κ ~ ( q i − 1 ) ∥ 2 + l ( q i ) ∥ κ ~ ( q i ) ∥ 2 + l ( q i + 1 ) ∥ κ ~ ( q i + 1 ) ∥ 2 + c g ( q i ) 2 ) = ∂ ∂ q i , x ( l ( q i − 1 ) κ ~ ( q i − 1 ) ⋅ κ ~ ( q i − 1 ) + l ( q i ) κ ~ ( q i ) ⋅ κ ~ ( q i ) + l ( q i + 1 ) κ ~ ( q i + 1 ) ⋅ κ ~ ( q i + 1 ) + c g ( q i ) 2 ) = ∂ l ( q i − 1 ) ∂ q i , x κ ~ ( q i − 1 ) ⋅ κ ~ ( q i − 1 ) + ∂ l ( q i ) ∂ q i , x κ ~ ( q i ) ⋅ κ ~ ( q i ) + ∂ l ( q i + 1 ) ∂ q i , x κ ~ ( q i + 1 ) ⋅ κ ~ ( q i + 1 ) + 2 l ( q i − 1 ) κ ~ ( q i − 1 ) ∂ κ ~ ( q i − 1 ) ∂ q i , x + 2 l ( q i ) κ ~ ( q i ) ∂ κ ~ ( q i ) ∂ q i , x + 2 l ( q i + 1 ) κ ~ ( q i + 1 ) ∂ κ ~ ( q i + 1 ) ∂ q i , x + 2 c g ( q i ) ∂ g ( q i ) ∂ q i , x (1.8) \begin{aligned} \frac{\partial F}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\left ( l(q_{i-1})\left \| \tilde{\kappa}(q_{i-1}) \right \|^{2} + l(q_{i})\left \| \tilde{\kappa}(q_{i}) \right \|^{2} + l(q_{i+1})\left \| \tilde{\kappa}(q_{i+1}) \right \|^{2} + cg(q_{i})^{2} \right ) \\ &= \frac{\partial }{\partial q_{i,x}}\left ( l(q_{i-1})\tilde{\kappa}(q_{i-1})\cdot \tilde{\kappa}(q_{i-1}) + l(q_{i})\tilde{\kappa}(q_{i})\cdot \tilde{\kappa}(q_{i}) + l(q_{i+1})\tilde{\kappa}(q_{i+1})\cdot \tilde{\kappa}(q_{i+1}) + cg(q_{i})^{2} \right ) \\ &= \frac{\partial l(q_{i-1})}{\partial q_{i,x}}\tilde{\kappa}(q_{i-1})\cdot \tilde{\kappa}(q_{i-1}) + \frac{\partial l(q_{i})}{\partial q_{i,x}}\tilde{\kappa}(q_{i})\cdot \tilde{\kappa}(q_{i}) + \frac{\partial l(q_{i+1})}{\partial q_{i,x}}\tilde{\kappa}(q_{i+1})\cdot \tilde{\kappa}(q_{i+1}) + \\& \quad \quad 2l(q_{i-1})\tilde{\kappa}(q_{i-1})\frac{\partial \tilde{\kappa}(q_{i-1})}{\partial q_{i,x}} + 2l(q_{i})\tilde{\kappa}(q_{i})\frac{\partial \tilde{\kappa}(q_{i})}{\partial q_{i,x}} + 2l(q_{i+1})\tilde{\kappa}(q_{i+1})\frac{\partial \tilde{\kappa}(q_{i+1})}{\partial q_{i,x}} + \\ & \quad \quad 2c g(q_{i})\frac{\partial g(q_{i})}{\partial q_{i,x}} \end{aligned}\tag{1.8} ∂qi,x∂F=∂qi,x∂(l(qi−1)∥κ~(qi−1)∥2+l(qi)∥κ~(qi)∥2+l(qi+1)∥κ~(qi+1)∥2+cg(qi)2)=∂qi,x∂(l(qi−1)κ~(qi−1)⋅κ~(qi−1)+l(qi)κ~(qi)⋅κ~(qi)+l(qi+1)κ~(qi+1)⋅κ~(qi+1)+cg(qi)2)=∂qi,x∂l(qi−1)κ~(qi−1)⋅κ~(qi−1)+∂qi,x∂l(qi)κ~(qi)⋅κ~(qi)+∂qi,x∂l(qi+1)κ~(qi+1)⋅κ~(qi+1)+2l(qi−1)κ~(qi−1)∂qi,x∂κ~(qi−1)+2l(qi)κ~(qi)∂qi,x∂κ~(qi)+2l(qi+1)κ~(qi+1)∂qi,x∂κ~(qi+1)+2cg(qi)∂qi,x∂g(qi)(1.8)下面我们将推导方程 ( 1.8 ) (1.8) (1.8)中子表达式的偏导数。
我们引入符号: 1 x 1_{x} 1x,它表示某个向量在第 x x x坐标是1,在其他坐标是0。现在我们可以求出 g ( q i ) , l ( q i − 1 ) , l ( q i ) , l ( q i + 1 ) , q i − 1 ′ ′ , q i ′ ′ , q i + 1 ′ ′ g(q_{i}),l(q_{i-1}),l(q_{i}),l(q_{i+1}),q_{i-1}^{''},q_{i}^{''},q_{i+1}^{''} g(qi),l(qi−1),l(qi),l(qi+1),qi−1′′,qi′′,qi+1′′以及 κ ~ ( q i − 1 ) , κ ~ ( q i ) , κ ~ ( q i + 1 ) \tilde{\kappa}(q_{i-1}),\tilde{\kappa}(q_{i}),\tilde{\kappa}(q_{i+1}) κ~(qi−1),κ~(qi),κ~(qi+1)的偏导了: ∂ g ( q i ) ∂ q i , x = ∂ ∂ q i , x ( q i ⋅ q i − 1 ) = 2 q i ⋅ ∂ q i ∂ q i , x = 2 q i , x (1.9) \begin{aligned} \frac{\partial g(q_{i})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}(q_{i}\cdot q_{i}-1) \\&= 2q_{i}\cdot \frac{\partial q_{i}}{\partial q_{i,x}} = 2q_{i,x} \end{aligned}\tag{1.9} ∂qi,x∂g(qi)=∂qi,x∂(qi⋅qi−1)=2qi⋅∂qi,x∂qi=2qi,x(1.9) ∂ l ( q i − 1 ) ∂ q i , x = ∂ ∂ q i , x ∥ q i − 1 − q i − 2 ∥ + ∥ q i − 1 − q i ∥ 2 = 1 2 ∂ ∂ q i , x ( ( q i − 1 − q i − 2 ) ⋅ ( q i − 1 − q i − 2 ) + ( q i − 1 − q i ) ⋅ ( q i − 1 − q i ) ) = 1 2 ( − 1 x ⋅ ( q i − 1 − q i ) ( q i − 1 − q i ) ⋅ ( q i − 1 − q i ) ) = 1 x ⋅ ( q i − q i − 1 ) 2 ∥ q i − 1 − q i ∥ (1.10) \begin{aligned} \frac{\partial l(q_{i-1})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{\left \| q_{i-1}-q_{i-2} \right \|+\left \| q_{i-1}-q_{i} \right \|}{2} \\&= \frac{1}{2}\frac{\partial }{\partial q_{i,x}}\left ( \sqrt{(q_{i-1}-q_{i-2})\cdot (q_{i-1}-q_{i-2})} + \sqrt{(q_{i-1}-q_{i})\cdot(q_{i-1}-q_{i})} \right ) \\&= \frac{1}{2}\left ( -\frac{1_{x}\cdot(q_{i-1}-q_{i})}{\sqrt{(q_{i-1}-q_{i})\cdot(q_{i-1}-q_{i})}} \right ) \\&= \frac{1_{x}\cdot(q_{i}-q_{i-1})}{2\left \| q_{i-1}-q_{i} \right \|} \end{aligned}\tag{1.10} ∂qi,x∂l(qi−1)=∂qi,x∂2∥qi−1−qi−2∥+∥qi−1−qi∥=21∂qi,x∂((qi−1−qi−2)⋅(qi−1−qi−2)+(qi−1−qi)⋅(qi−1−qi))=21(−(qi−1−qi)⋅(qi−1−qi)1x⋅(qi−1−qi))=2∥qi−1−qi∥1x⋅(qi−qi−1)(1.10) ∂ l ( q i ) ∂ q i , x = ∂ ∂ q i , x ∥ q i − q i − 1 ∥ + ∥ q i − q i + 1 ∥ 2 = 1 2 ∂ ∂ q i , x ( ( q i − q i − 1 ) ⋅ ( q i − q i − 1 ) + ( q i − q i + 1 ) ⋅ ( q i − q i + 1 ) ) = 1 2 ( 1 x ⋅ ( q i − q i − 1 ) ( q i − q i − 1 ) ⋅ ( q i − q i − 1 ) + 1 x ⋅ ( q i − q i + 1 ) ( q i − q i + 1 ) ⋅ ( q i − q i + 1 ) ) = 1 x ⋅ ( q i − q i − 1 ) 2 ∥ q i − q i − 1 ∥ + 1 x ⋅ ( q i − q i + 1 ) 2 ∥ q i + 1 − q i ∥ (1.11) \begin{aligned} \frac{\partial l(q_{i})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{\left \| q_{i}-q_{i-1} \right \|+\left \| q_{i}-q_{i+1} \right \|}{2} \\&= \frac{1}{2}\frac{\partial }{\partial q_{i,x}}\left ( \sqrt{(q_{i}-q_{i-1})\cdot (q_{i}-q_{i-1})} + \sqrt{(q_{i}-q_{i+1})\cdot(q_{i}-q_{i+1})} \right ) \\&= \frac{1}{2}\left ( \frac{1_{x}\cdot(q_{i}-q_{i-1})}{\sqrt{(q_{i}-q_{i-1})\cdot(q_{i}-q_{i-1})}} + \frac{1_{x}\cdot(q_{i}-q_{i+1})}{\sqrt{(q_{i}-q_{i+1})\cdot(q_{i}-q_{i+1})}} \right ) \\&= \frac{1_{x}\cdot(q_{i}-q_{i-1})}{2\left \| q_{i}-q_{i-1} \right \|} + \frac{1_{x}\cdot(q_{i}-q_{i+1})}{2\left \| q_{i+1}-q_{i} \right \|} \end{aligned}\tag{1.11} ∂qi,x∂l(qi)=∂qi,x∂2∥qi−qi−1∥+∥qi−qi+1∥=21∂qi,x∂((qi−qi−1)⋅(qi−qi−1)+(qi−qi+1)⋅(qi−qi+1))=21((qi−qi−1)⋅(qi−qi−1)1x⋅(qi−qi−1)+(qi−qi+1)⋅(qi−qi+1)1x⋅(qi−qi+1))=2∥qi−qi−1∥1x⋅(qi−qi−1)+2∥qi+1−qi∥1x⋅(qi−qi+1)(1.11) ∂ l ( q i + 1 ) ∂ q i , x = ∂ ∂ q i , x ∥ q i + 1 − q i ∥ + ∥ q i + 1 − q i + 2 ∥ 2 = 1 2 ∂ ∂ q i , x ( ( q i + 1 − q i ) ⋅ ( q i + 1 − q i ) + ( q i + 1 − q i + 2 ) ⋅ ( q i + 1 − q i + 2 ) ) = 1 2 ( − 1 x ⋅ ( q i + 1 − q i ) ( q i + 1 − q i ) ⋅ ( q i + 1 − q i ) ) = 1 x ⋅ ( q i − q i + 1 ) 2 ∥ q i + 1 − q i ∥ (1.12) \begin{aligned} \frac{\partial l(q_{i+1})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{\left \| q_{i+1}-q_{i} \right \|+\left \| q_{i+1}-q_{i+2} \right \|}{2} \\&= \frac{1}{2}\frac{\partial }{\partial q_{i,x}}\left ( \sqrt{(q_{i+1}-q_{i})\cdot (q_{i+1}-q_{i})} + \sqrt{(q_{i+1}-q_{i+2})\cdot(q_{i+1}-q_{i+2})} \right ) \\&= \frac{1}{2}\left ( -\frac{1_{x}\cdot(q_{i+1}-q_{i})}{\sqrt{(q_{i+1}-q_{i})\cdot(q_{i+1}-q_{i})}} \right ) \\&= \frac{1_{x}\cdot(q_{i}-q_{i+1})}{2\left \| q_{i+1}-q_{i} \right \|} \end{aligned}\tag{1.12} ∂qi,x∂l(qi+1)=∂qi,x∂2∥qi+1−qi∥+∥qi+1−qi+2∥=21∂qi,x∂((qi+1−qi)⋅(qi+1−qi)+(qi+1−qi+2)⋅(qi+1−qi+2))=21(−(qi+1−qi)⋅(qi+1−qi)1x⋅(qi+1−qi))=2∥qi+1−qi∥1x⋅(qi−qi+1)(1.12) ∂ q i − 1 ′ ′ ∂ q i , x = ∂ ∂ q i , x q i − 2 − 2 q i − 1 + q i l ( q i − 1 ) 2 = l ( q i − 1 ) 2 ∂ ∂ q i , x ( q i − 2 − 2 q i − 1 + q i ) − ( q i − 2 − 2 q i − 1 + q i ) ∂ ∂ q i , x l ( q i − 1 ) 2 l ( q i − 1 ) 4 = l ( q i − 1 ) 2 ∂ ∂ q i , x q i − ( q i − 2 − 2 q i − 1 + q i ) 2 l ( q i − 1 ) ∂ ∂ q i , x l ( q i − 1 ) l ( q i − 1 ) 4 = l ( q i − 1 ) 2 1 x − 2 ( q i − 2 − 2 q i − 1 + q i ) l ( q i − 1 ) ∂ ∂ q i , x l ( q i − 1 ) l ( q i − 1 ) 4 (1.13) \begin{aligned} \frac{\partial q_{i-1}^{''}}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{q_{i-2}-2q_{i-1}+q_{i}}{l(q_{i-1})^{2}} \\&= \frac{l(q_{i-1})^{2}\frac{\partial }{\partial q_{i,x}}(q_{i-2}-2q_{i-1}+q_{i})-(q_{i-2}-2q_{i-1}+q_{i})\frac{\partial }{\partial q_{i,x}}l(q_{i-1})^{2}}{l(q_{i-1})^{4}} \\&= \frac{l(q_{i-1})^{2}\frac{\partial }{\partial q_{i,x}}q_{i}-(q_{i-2}-2q_{i-1}+q_{i})2l(q_{i-1})\frac{\partial }{\partial q_{i,x}}l(q_{i-1})}{l(q_{i-1})^{4}} \\&= \frac{l(q_{i-1})^{2}1_{x}-2(q_{i-2}-2q_{i-1}+q_{i})l(q_{i-1})\frac{\partial }{\partial q_{i,x}}l(q_{i-1})}{l(q_{i-1})^{4}} \end{aligned}\tag{1.13} ∂qi,x∂qi−1′′=∂qi,x∂l(qi−1)2qi−2−2qi−1+qi=l(qi−1)4l(qi−1)2∂qi,x∂(qi−2−2qi−1+qi)−(qi−2−2qi−1+qi)∂qi,x∂l(qi−1)2=l(qi−1)4l(qi−1)2∂qi,x∂qi−(qi−2−2qi−1+qi)2l(qi−1)∂qi,x∂l(qi−1)=l(qi−1)4l(qi−1)21x−2(qi−2−2qi−1+qi)l(qi−1)∂qi,x∂l(qi−1)(1.13) ∂ q i ′ ′ ∂ q i , x = ∂ ∂ q i , x q i − 1 − 2 q i + q i + 1 l ( q i ) 2 = l ( q i ) 2 ∂ ∂ q i , x ( q i − 1 − 2 q i + q i + 1 ) − ( q i − 1 − 2 q i + q i + 1 ) ∂ ∂ q i , x l ( q i ) 2 l ( q i ) 4 = l ( q i ) 2 ∂ ∂ q i , x ( − 2 q i ) − ( q i − 1 − 2 q i + q i + 1 ) 2 l ( q i ) ∂ ∂ q i , x l ( q i ) l ( q i ) 4 = − 2 l ( q i ) 2 1 x + 2 ( q i − 1 − 2 q i + q i + 1 ) l ( q i ) ∂ ∂ q i , x l ( q i ) l ( q i ) 4 (1.14) \begin{aligned} \frac{\partial q_{i}^{''}}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{q_{i-1}-2q_{i}+q_{i+1}}{l(q_{i})^{2}} \\&= \frac{l(q_{i})^{2}\frac{\partial }{\partial q_{i,x}}(q_{i-1}-2q_{i}+q_{i+1})-(q_{i-1}-2q_{i}+q_{i+1})\frac{\partial }{\partial q_{i,x}}l(q_{i})^{2}}{l(q_{i})^{4}} \\&= \frac{l(q_{i})^{2}\frac{\partial }{\partial q_{i,x}}(-2q_{i})-(q_{i-1}-2q_{i}+q_{i+1})2l(q_{i})\frac{\partial }{\partial q_{i,x}}l(q_{i})}{l(q_{i})^{4}} \\&= -\frac{2l(q_{i})^{2}1_{x}+2(q_{i-1}-2q_{i}+q_{i+1})l(q_{i})\frac{\partial }{\partial q_{i,x}}l(q_{i})}{l(q_{i})^{4}} \end{aligned}\tag{1.14} ∂qi,x∂qi′′=∂qi,x∂l(qi)2qi−1−2qi+qi+1=l(qi)4l(qi)2∂qi,x∂(qi−1−2qi+qi+1)−(qi−1−2qi+qi+1)∂qi,x∂l(qi)2=l(qi)4l(qi)2∂qi,x∂(−2qi)−(qi−1−2qi+qi+1)2l(qi)∂qi,x∂l(qi)=−l(qi)42l(qi)21x+2(qi−1−2qi+qi+1)l(qi)∂qi,x∂l(qi)(1.14) ∂ q i + 1 ′ ′ ∂ q i , x = ∂ ∂ q i , x q i − 2 q i + 1 + q i + 2 l ( q i + 1 ) 2 = l ( q i + 1 ) 2 ∂ ∂ q i , x ( q i − 2 q i + 1 + q i + 2 ) − ( q i − 2 q i + 1 + q i + 2 ) ∂ ∂ q i , x l ( q i + 1 ) 2 l ( q i + 1 ) 4 = l ( q i + 1 ) 2 ∂ ∂ q i , x q i − ( q i − 2 q i + 1 + q i + 2 ) 2 l ( q i + 1 ) ∂ ∂ q i , x l ( q i + 1 ) l ( q i + 1 ) 4 = 2 l ( q i + 1 ) 2 1 x − 2 ( q i − 2 q i + 1 + q i + 2 ) l ( q i + 1 ) ∂ ∂ q i , x l ( q i + 1 ) l ( q i + 1 ) 4 (1.15) \begin{aligned} \frac{\partial q_{i+1}^{''}}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}}\frac{q_{i}-2q_{i+1}+q_{i+2}}{l(q_{i+1})^{2}} \\&= \frac{l(q_{i+1})^{2}\frac{\partial }{\partial q_{i,x}}(q_{i}-2q_{i+1}+q_{i+2})-(q_{i}-2q_{i+1}+q_{i+2})\frac{\partial }{\partial q_{i,x}}l(q_{i+1})^{2}}{l(q_{i+1})^{4}} \\&= \frac{l(q_{i+1})^{2}\frac{\partial }{\partial q_{i,x}}q_{i}-(q_{i}-2q_{i+1}+q_{i+2})2l(q_{i+1})\frac{\partial }{\partial q_{i,x}}l(q_{i+1})}{l(q_{i+1})^{4}} \\&= \frac{2l(q_{i+1})^{2}1_{x} - 2(q_{i}-2q_{i+1}+q_{i+2})l(q_{i+1})\frac{\partial }{\partial q_{i,x}}l(q_{i+1})}{l(q_{i+1})^{4}} \end{aligned}\tag{1.15} ∂qi,x∂qi+1′′=∂qi,x∂l(qi+1)2qi−2qi+1+qi+2=l(qi+1)4l(qi+1)2∂qi,x∂(qi−2qi+1+qi+2)−(qi−2qi+1+qi+2)∂qi,x∂l(qi+1)2=l(qi+1)4l(qi+1)2∂qi,x∂qi−(qi−2qi+1+qi+2)2l(qi+1)∂qi,x∂l(qi+1)=l(qi+1)42l(qi+1)21x−2(qi−2qi+1+qi+2)l(qi+1)∂qi,x∂l(qi+1)(1.15) ∂ κ ~ ( q i − 1 ) ∂ q i , x = ∂ ∂ q i , x ( q i − 1 ′ ′ − q i − 1 ′ ′ ⋅ q i − 1 q i − 1 ⋅ q i − 1 q i − 1 ) = ∂ q i − 1 ′ ′ ∂ q i , x − ∂ q i − 1 ′ ′ ∂ q i , x q i − 1 q i − 1 ⋅ q i − 1 q i − 1 (1.16) \begin{aligned} \frac{\partial \tilde{\kappa}(q_{i-1})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}} \left ( q_{i-1}^{''}-\frac{q_{i-1}^{''}\cdot q_{i-1}}{q_{i-1}\cdot q_{i-1}}q_{i-1} \right ) \\&= \frac{\partial q_{i-1}^{''}}{\partial q_{i,x}}-\frac{\frac{\partial q_{i-1}^{''}}{\partial q_{i,x}}q_{i-1}}{q_{i-1}\cdot q_{i-1}}q_{i-1} \end{aligned}\tag{1.16} ∂qi,x∂κ~(qi−1)=∂qi,x∂(qi−1′′−qi−1⋅qi−1qi−1′′⋅qi−1qi−1)=∂qi,x∂qi−1′′−qi−1⋅qi−1∂qi,x∂qi−1′′qi−1qi−1(1.16) ∂ κ ~ ( q i ) ∂ q i , x = ∂ ∂ q i , x ( q i ′ ′ − q i ′ ′ ⋅ q i q i ⋅ q i q i ) = ∂ q i ′ ′ ∂ q i , x − q i ′ ′ ⋅ q i q i ⋅ q i ∂ q i ∂ q i , x − ∂ ∂ q i , x ( q i ′ ′ ⋅ q i q i ⋅ q i ) q i = ∂ q i ′ ′ ∂ q i , x − q i ′ ′ ⋅ q i q i ⋅ q i 1 x − ∂ ∂ q i , x ( q i ′ ′ ⋅ q i q i ⋅ q i ) q i = ∂ q i ′ ′ ∂ q i , x − q i ′ ′ ⋅ q i q i ⋅ q i 1 x − ( ∂ q i ′ ′ ⋅ q i ∂ q i , x q i ⋅ q i − ∂ q i ⋅ q i ∂ q i , x q i ′ ′ ⋅ q i ( q i ⋅ q i ) 2 ) q i = ∂ q i ′ ′ ∂ q i , x − q i ′ ′ ⋅ q i q i ⋅ q i 1 x − ( ( ∂ q i ′ ′ ∂ q i , x ⋅ q i + q i ′ ′ ⋅ ∂ q i ∂ q i , x ) q i ⋅ q i − 2 ( q i ⋅ ∂ q i ∂ q i , x ) q i ′ ′ ⋅ q i ( q i ⋅ q i ) 2 ) q i = ∂ q i ′ ′ ∂ q i , x − q i ′ ′ ⋅ q i q i ⋅ q i 1 x − ( ( ∂ q i ′ ′ ∂ q i , x ⋅ q i + q i ′ ′ ⋅ 1 x ) q i ⋅ q i − 2 ( q i ⋅ 1 x ) q i ′ ′ ⋅ q i ( q i ⋅ q i ) 2 ) q i (1.17) \begin{aligned} \frac{\partial \tilde{\kappa}(q_{i})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}} \left ( q_{i}^{''}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}q_{i} \right ) \\&= \frac{\partial q_{i}^{''}}{\partial q_{i,x}}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}\frac{\partial q_{i}}{\partial q_{i,x}}-\frac{\partial }{\partial q_{i,x}}\left ( \frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}} \right )q_{i} \\&= \frac{\partial q_{i}^{''}}{\partial q_{i,x}}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}1_{x}-\frac{\partial }{\partial q_{i,x}}\left ( \frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}} \right )q_{i} \\&= \frac{\partial q_{i}^{''}}{\partial q_{i,x}}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}1_{x}-\left ( \frac{\frac{\partial q_{i}^{''}\cdot q_{i}}{\partial q_{i,x}}q_{i}\cdot q_{i}-\frac{\partial q_{i}\cdot q_{i}}{\partial q_{i,x}}q_{i}^{''}\cdot q_{i}}{(q_{i}\cdot q_{i})^{2}} \right )q_{i} \\&= \frac{\partial q_{i}^{''}}{\partial q_{i,x}}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}1_{x}-\left ( \frac{\left ( \frac{ \partial q_{i}^{''}}{\partial q_{i,x}}\cdot q_{i}+q_{i}^{''}\cdot \frac{\partial q_{i}}{\partial q_{i,x}} \right )q_{i}\cdot q_{i} - 2\left ( q_{i}\cdot\frac{\partial q_{i}}{\partial q_{i,x}} \right )q_{i}^{''}\cdot q_{i}}{(q_{i}\cdot q_{i})^{2}} \right )q_{i} \\&= \frac{\partial q_{i}^{''}}{\partial q_{i,x}}-\frac{q_{i}^{''}\cdot q_{i}}{q_{i}\cdot q_{i}}1_{x}-\left ( \frac{\left ( \frac{ \partial q_{i}^{''}}{\partial q_{i,x}}\cdot q_{i}+q_{i}^{''}\cdot 1_{x} \right )q_{i}\cdot q_{i} - 2\left ( q_{i}\cdot 1_{x}\right )q_{i}^{''}\cdot q_{i}}{(q_{i}\cdot q_{i})^{2}} \right )q_{i} \end{aligned}\tag{1.17} ∂qi,x∂κ~(qi)=∂qi,x∂(qi′′−qi⋅qiqi′′⋅qiqi)=∂qi,x∂qi′′−qi⋅qiqi′′⋅qi∂qi,x∂qi−∂qi,x∂(qi⋅qiqi′′⋅qi)qi=∂qi,x∂qi′′−qi⋅qiqi′′⋅qi1x−∂qi,x∂(qi⋅qiqi′′⋅qi)qi=∂qi,x∂qi′′−qi⋅qiqi′′⋅qi1x−⎝⎛(qi⋅qi)2∂qi,x∂qi′′⋅qiqi⋅qi−∂qi,x∂qi⋅qiqi′′⋅qi⎠⎞qi=∂qi,x∂qi′′−qi⋅qiqi′′⋅qi1x−⎝⎜⎜⎛(qi⋅qi)2(∂qi,x∂qi′′⋅qi+qi′′⋅∂qi,x∂qi)qi⋅qi−2(qi⋅∂qi,x∂qi)qi′′⋅qi⎠⎟⎟⎞qi=∂qi,x∂qi′′−qi⋅qiqi′′⋅qi1x−⎝⎜⎜⎛(qi⋅qi)2(∂qi,x∂qi′′⋅qi+qi′′⋅1x)qi⋅qi−2(qi⋅1x)qi′′⋅qi⎠⎟⎟⎞qi(1.17) ∂ κ ~ ( q i + 1 ) ∂ q i , x = ∂ ∂ q i , x ( q i + 1 ′ ′ − q i + 1 ′ ′ ⋅ q i + 1 q i + 1 ⋅ q i + 1 q i + 1 ) = ∂ q i + 1 ′ ′ ∂ q i , x − ∂ q i + 1 ′ ′ ∂ q i , x q i + 1 q i + 1 ⋅ q i + 1 q i + 1 (1.18) \begin{aligned} \frac{\partial \tilde{\kappa}(q_{i+1})}{\partial q_{i,x}} &= \frac{\partial }{\partial q_{i,x}} \left ( q_{i+1}^{''}-\frac{q_{i+1}^{''}\cdot q_{i+1}}{q_{i+1}\cdot q_{i+1}}q_{i+1} \right ) \\&= \frac{\partial q_{i+1}^{''}}{\partial q_{i,x}}-\frac{\frac{\partial q_{i+1}^{''}}{\partial q_{i,x}}q_{i+1}}{q_{i+1}\cdot q_{i+1}}q_{i+1} \end{aligned}\tag{1.18} ∂qi,x∂κ~(qi+1)=∂qi,x∂(qi+1′′−qi+1⋅qi+1qi+1′′⋅qi+1qi+1)=∂qi,x∂qi+1′′−qi+1⋅qi+1∂qi,x∂qi+1′′qi+1qi+1(1.18)
现在我们对梯度中的所有项都有了简单且长的表达式。我们回到梯度方程 ( 1.8 ) (1.8) (1.8),可看到其所有组成项均已导出,将方程 ( 1.4 ) (1.4) (1.4)中 κ ~ ( q i − 1 ) , κ ~ ( q i ) , κ ~ ( q i + 1 ) \tilde{\kappa}(q_{i-1}),\tilde{\kappa}(q_{i}),\tilde{\kappa}(q_{i+1}) κ~(qi−1),κ~(qi),κ~(qi+1)的导出项和偏导数方程 ( 1.16 ) , ( 1.17 ) , ( 1.18 ) (1.16),(1.17),(1.18) (1.16),(1.17),(1.18)中 ∂ κ ~ ( q i − 1 ) ∂ q i , x , ∂ κ ~ ( q i ) ∂ q i , x , ∂ κ ~ ( q i + 1 ) ∂ q i , x \frac{\partial \tilde{\kappa}(q_{i-1})}{\partial q_{i,x}},\frac{\partial \tilde{\kappa}(q_{i})}{\partial q_{i,x}},\frac{\partial \tilde{\kappa}(q_{i+1})}{\partial q_{i,x}} ∂qi,x∂κ~(qi−1),∂qi,x∂κ~(qi),∂qi,x∂κ~(qi+1)的方程代入梯度方程 ( 1.8 ) (1.8) (1.8),即可显式计算出梯度。
下面我们看算法的具体步骤。
上面我们推导出了Sping算法中梯度的显式离散表达式,现在我们可以根据梯度下降法给出Sping算法的详细步骤:
这就是算法的基本步骤,下面我们看一下算法中对范数的改进及算法的扩展。
如上所述,我们希望插值曲线位于单位四元数的 H 1 H_{1} H1空间,这是通过使用方程 ( 1.7 ) (1.7) (1.7)中的惩罚函数 g ( q i ) g(q_{i}) g(qi)做到的。但是很难确定方程 ( 1.7 ) (1.7) (1.7)中惩罚函数的权重因子 c ∈ R c\in \mathbb{R} c∈R 多大才能与 E E E“相匹配”。理论上, c c c必须是无穷大,才能保证 q i ∈ H 1 q_{i}\in H_{1} qi∈H1,有几种方法可以从不同角度解决这个问题,下面分别介绍:
从理论上看,我们认为对生成的四元数进行归一化是“作弊”行为,但也不是不可用。在上述表示中,极坐标将确保插值曲线停留在单位四元数的 H 1 H_{1} H1空间中;使用拉格朗日算子将确保一个更鲁棒和更快的收敛算法。为了使算法尽可能简单,我们不会再进一步探索上述可能性,即我们将不再进一步讨论这三种替代方法中的任何一种。
一般认为,梯度下降法是一种很容易推广的方法。但是对于插值曲线的预期性质,必须可以简单地描述为某些函数的零交叉或恒定状态。例如,我们可能想要确保整个插值曲线的角速度是恒定的,这可以使用另一个惩罚函数得到: w ( q i ) = ∥ q i − 1 − q i ∥ − ∥ q i − q i + 1 ∥ (2.1) w(q_{i}) =\left \| q_{i-1}-q_{i} \right \| - \left \| q_{i}-q_{i+1} \right \|\tag{2.1} w(qi)=∥qi−1−qi∥−∥qi−qi+1∥(2.1)可以看到,惩罚函数 w ( q i ) w(q_{i}) w(qi)随上步长 q i − 1 q_{i-1} qi−1与下步长 q i + 1 q_{i+1} qi+1之差而增加。该惩罚项可以简单地引入到算法中,比如将其引入到方程 ( 1.7 ) (1.7) (1.7)的原始能量函数中: F = ∑ i = 1 N l ( q i ) ∥ κ ( q i ) ~ ∥ 2 + c g g ( q i ) 2 + c w w ( q i ) 2 (2.2)