3D变换函数求导


前言

矩阵求导


一、3D变换函数求导

1欧拉角旋转完整版本

3D变换函数表示为:

T E ( p 6 , x ) = R x R y R z x + t T_E(\mathbf{p}_6, \mathbf{x}) = R_x R_y R_z \mathbf{x} + \mathbf{t} TE(p6,x)=RxRyRzx+t

其中 p 6 = [ t x , t y , t z , ϕ x , ϕ y , ϕ z ] T \mathbf{p}_6 = [t_x, t_y, t_z, \phi_x, \phi_y, \phi_z]^T p6=[tx,ty,tz,ϕx,ϕy,ϕz]T t = [ t x , t y , t z ] T \mathbf{t} = [t_x, t_y, t_z]^T t=[tx,ty,tz]T 是平移向量, R x R_x Rx R y R_y Ry R z R_z Rz 是旋转矩阵。
(1)   x \ x  x轴的旋转矩阵 R x R_x Rx
R x = [ 1 0 0 0 cos ⁡ ϕ x − sin ⁡ ϕ x 0 sin ⁡ ϕ x cos ⁡ ϕ x ] R_x = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \phi_x & -\sin \phi_x \\ 0 & \sin \phi_x & \cos \phi_x \end{bmatrix} Rx= 1000cosϕxsinϕx0sinϕxcosϕx

(2)   y \ y  y 轴的旋转矩阵 R y R_y Ry
R y = [ cos ⁡ ϕ y 0 sin ⁡ ϕ y 0 1 0 − sin ⁡ ϕ y 0 cos ⁡ ϕ y ] R_y = \begin{bmatrix} \cos \phi_y & 0 & \sin \phi_y \\ 0 & 1 & 0 \\ -\sin \phi_y & 0 & \cos \phi_y \end{bmatrix} Ry= cosϕy0sinϕy010sinϕy0cosϕy

(3)   z \ z  z轴的旋转矩阵 R z R_z Rz
R z = [ cos ⁡ ϕ z − sin ⁡ ϕ z 0 sin ⁡ ϕ z cos ⁡ ϕ z 0 0 0 1 ] R_z = \begin{bmatrix} \cos \phi_z & -\sin \phi_z & 0 \\ \sin \phi_z & \cos \phi_z & 0 \\ 0 & 0 & 1 \end{bmatrix} Rz= cosϕzsinϕz0sinϕzcosϕz0001

结合这些旋转矩阵,3D变换函数的表达式为:

T E ( p 6 , x ) = R x R y R z x + t T_E(\mathbf{p}_6, \mathbf{x}) = R_x R_y R_z \mathbf{x} + \mathbf{t} TE(p6,x)=RxRyRzx+t

雅可比矩阵 J E J_E JE

雅可比矩阵的每个元素是变换函数对每个参数的偏导数。

平移部分

对于平移参数 t x , t y , t z t_x, t_y, t_z tx,ty,tz

∂ T E ∂ t x = [ 1 0 0 ] , ∂ T E ∂ t y = [ 0 1 0 ] , ∂ T E ∂ t z = [ 0 0 1 ] \frac{\partial T_E}{\partial t_x} = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \quad \frac{\partial T_E}{\partial t_y} = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \quad \frac{\partial T_E}{\partial t_z} = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} txTE= 100 ,tyTE= 010 ,tzTE= 001

旋转部分

对于旋转角度 ϕ x , ϕ y , ϕ z \phi_x, \phi_y, \phi_z ϕx,ϕy,ϕz

根据文中给出的公式,雅可比矩阵的形式为:

J E = [ 1 0 0 0 c f 0 1 0 a d g 0 0 1 b e h ] J_E = \begin{bmatrix} 1 & 0 & 0 & 0 & c & f \\ 0 & 1 & 0 & a & d & g \\ 0 & 0 & 1 & b & e & h \end{bmatrix} JE= 1000100010abcdefgh

其中:

  • a = x 1 ( − s x s z + c x s y c z ) + x 2 ( − s x c z − c x s y s z ) + x 3 ( − c x c y ) a = x_1(-s_x s_z + c_x s_y c_z) + x_2(-s_x c_z - c_x s_y s_z) + x_3(-c_x c_y) a=x1(sxsz+cxsycz)+x2(sxczcxsysz)+x3(cxcy)
  • b = x 1 ( c x s z + s x s y c z ) + x 2 ( − s x s y s z + c x c z ) + x 3 ( − s x c y ) b = x_1(c_x s_z + s_x s_y c_z) + x_2(-s_x s_y s_z + c_x c_z) + x_3(-s_x c_y) b=x1(cxsz+sxsycz)+x2(sxsysz+cxcz)+x3(sxcy)
  • c = x 1 ( − s y c z ) + x 2 ( s y s z ) + x 3 ( c y ) c = x_1(-s_y c_z) + x_2(s_y s_z) + x_3(c_y) c=x1(sycz)+x2(sysz)+x3(cy)
  • d = x 1 ( s x c y c z ) + x 2 ( − s x c y s z ) + x 3 ( s x s y ) d = x_1(s_x c_y c_z) + x_2(-s_x c_y s_z) + x_3(s_x s_y) d=x1(sxcycz)+x2(sxcysz)+x3(sxsy)
  • e = x 1 ( − c x c y c z ) + x 2 ( c x c y s z ) + x 3 ( − c x s y ) e = x_1(-c_x c_y c_z) + x_2(c_x c_y s_z) + x_3(-c_x s_y) e=x1(cxcycz)+x2(cxcysz)+x3(cxsy)
  • f = x 1 ( − c y s z ) + x 2 ( − c y c z ) f = x_1(-c_y s_z) + x_2(-c_y c_z) f=x1(cysz)+x2(cycz)
  • g = x 1 ( c x c z − s x s y s z ) + x 2 ( − c x s z − s x s y c z ) g = x_1(c_x c_z - s_x s_y s_z) + x_2(-c_x s_z - s_x s_y c_z) g=x1(cxczsxsysz)+x2(cxszsxsycz)
  • h = x 1 ( s x c z + c x s y s z ) + x 2 ( c x s y c z − s x s z ) h = x_1(s_x c_z + c_x s_y s_z) + x_2(c_x s_y c_z - s_x s_z) h=x1(sxcz+cxsysz)+x2(cxsyczsxsz)

海森矩阵 H E H_E HE

海森矩阵的元素是雅可比矩阵的导数。根据文中的描述,海森矩阵的形式如下:

H E = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a b c 0 0 0 b d e 0 0 0 c e f ] H_E = \begin{bmatrix} \begin{array}{cccccc} \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} \\ \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} \\ \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{0} \\ \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{a} & \mathbf{b} & \mathbf{c} \\ \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{b} & \mathbf{d} & \mathbf{e} \\ \mathbf{0} & \mathbf{0} & \mathbf{0} & \mathbf{c} & \mathbf{e} & \mathbf{f} \end{array} \end{bmatrix} HE= 000000000000000000000abc000bde000cef

其中:

  • a = [ 0 x 1 ( − c x s z − s x s y c z ) + x 2 ( − c x c z + s x s y s z ) + x 3 ( s x c y ) x 1 ( − s x s z + c x s y c z ) + x 2 ( − s x s y s z − c x c z ) + x 3 ( − c x c y ) ] \mathbf{a} = \begin{bmatrix} 0 \\ x_1(-c_x s_z - s_x s_y c_z) + x_2(-c_x c_z + s_x s_y s_z) + x_3(s_x c_y) \\ x_1(-s_x s_z + c_x s_y c_z) + x_2(-s_x s_y s_z - c_x c_z) + x_3(-c_x c_y) \end{bmatrix} a= 0x1(cxszsxsycz)+x2(cxcz+sxsysz)+x3(sxcy)x1(sxsz+cxsycz)+x2(sxsyszcxcz)+x3(cxcy)

  • b = [ 0 x 1 ( c x c y c z ) + x 2 ( − c x c y s z ) + x 3 ( c x s y ) x 1 ( s x c y c z ) + x 2 ( − s x c y s z ) + x 3 ( s x s y ) ] \mathbf{b} = \begin{bmatrix} 0 \\ x_1(c_x c_y c_z) + x_2(-c_x c_y s_z) + x_3(c_x s_y) \\ x_1(s_x c_y c_z) + x_2(-s_x c_y s_z) + x_3(s_x s_y) \end{bmatrix} b= 0x1(cxcycz)+x2(cxcysz)+x3(cxsy)x1(sxcycz)+x2(sxcysz)+x3(sxsy)

  • c = [ 0 x 1 ( − s x c z − c x s y s z ) + x 2 ( − s x s z − s x s y c z ) x 1 ( c x c z − s x s y s z ) + x 2 ( − s x s y c z − s x s z ) ] \mathbf{c} = \begin{bmatrix} 0 \\ x_1(-s_x c_z - c_x s_y s_z) + x_2(-s_x s_z - s_x s_y c_z) \\ x_1(c_x c_z - s_x s_y s_z) + x_2(-s_x s_y c_z - s_x s_z) \end{bmatrix} c= 0x1(sxczcxsysz)+x2(sxszsxsycz)x1(cxczsxsysz)+x2(sxsyczsxsz)

  • d = [ x 1 ( − c y c z ) + x 2 ( c y s z ) + x 3 ( − s y ) x 1 ( − s x s y c z ) + x 2 ( s x s y s z ) + x 3 ( s x c y ) x 1 ( c x s y c z ) + x 2 ( − c x s y s z ) + x 3 ( − c x c y ) ] \mathbf{d} = \begin{bmatrix} x_1(-c_y c_z) + x_2(c_y s_z) + x_3(-s_y) \\ x_1(-s_x s_y c_z) + x_2(s_x s_y s_z) + x_3(s_x c_y) \\ x_1(c_x s_y c_z) + x_2(-c_x s_y s_z) + x_3(-c_x c_y) \end{bmatrix} d= x1(cycz)+x2(cysz)+x3(sy)x1(sxsycz)+x2(sxsysz)+x3(sxcy)x1(cxsycz)+x2(cxsysz)+x3(cxcy)

  • e = [ x 1 ( s y s z ) + x 2 ( s y c z ) x 1 ( − s x c y s z ) + x 2 ( − s x c y c z ) x 1 ( c x c y s z ) + x 2 ( c x c y c z ) ] \mathbf{e} = \begin{bmatrix} x_1(s_y s_z) + x_2(s_y c_z) \\ x_1(-s_x c_y s_z) + x_2(-s_x c_y c_z) \\ x_1(c_x c_y s_z) + x_2(c_x c_y c_z) \end{bmatrix} e= x1(sysz)+x2(sycz)x1(sxcysz)+x2(sxcycz)x1(cxcysz)+x2(cxcycz)

  • f = [ x 1 ( − c y c z ) + x 2 ( c y s z ) x 1 ( − c x s z − s x s y c z ) + x 2 ( − c x c z + s x s y s z ) x 1 ( − s x s z + c x s y c z ) + x 2 ( − c x s y s z − s x s z ) ] \mathbf{f} = \begin{bmatrix} x_1(-c_y c_z) + x_2(c_y s_z) \\ x_1(-c_x s_z - s_x s_y c_z) + x_2(-c_x c_z + s_x s_y s_z) \\ x_1(-s_x s_z + c_x s_y c_z) + x_2(-c_x s_y s_z - s_x s_z) \end{bmatrix} f= x1(cycz)+x2(cysz)x1(cxszsxsycz)+x2(cxcz+sxsysz)x1(sxsz+cxsycz)+x2(cxsyszsxsz)

2. 小角度近似的欧拉旋转

使用欧拉角序列   z − y − x \ z-y-x  zyx 和小角度近似,3D 变换   T E ( p 6 , x ) \ T_E(\mathbf{p}_6, \mathbf{x})  TE(p6,x) 可近似为:

T E ( p 6 , x ) = [ c y c z − c y s z s y c x s z + s x s y c z c x c z − s x s y s z − s x c y s x s z − c x s y c z s x s y s z + c x c z c x c y ] x + [ t x t y t z ] T_E(\mathbf{p}_6, \mathbf{x}) = \begin{bmatrix} c_y c_z & -c_y s_z & s_y \\ c_x s_z + s_x s_y c_z & c_x c_z - s_x s_y s_z & -s_x c_y \\ s_x s_z - c_x s_y c_z & s_x s_y s_z + c_x c_z & c_x c_y \end{bmatrix} \mathbf{x} + \begin{bmatrix} t_x \\ t_y \\ t_z \end{bmatrix} TE(p6,x)= cyczcxsz+sxsyczsxszcxsyczcyszcxczsxsyszsxsysz+cxczsysxcycxcy x+ txtytz

在小角度近似下,变换函数简化为:

T ~ E ( p 6 , x ) = [ 1 − ϕ z ϕ y ϕ z 1 − ϕ x − ϕ y ϕ x 1 ] x + [ t x t y t z ] \tilde{T}_E(\mathbf{p}_6, \mathbf{x}) = \begin{bmatrix} 1 & -\phi_z & \phi_y \\ \phi_z & 1 & -\phi_x \\ -\phi_y & \phi_x & 1 \end{bmatrix} \mathbf{x} + \begin{bmatrix} t_x \\ t_y \\ t_z \end{bmatrix} T~E(p6,x)= 1ϕzϕyϕz1ϕxϕyϕx1 x+ txtytz

解释:在小角度近似下,欧拉旋转的变换函数中,角度的正弦和余弦可以用角度本身代替,这简化了计算,更易于求导。

雅可比矩阵

J ~ E = [ 1 0 0 0 x 3 − x 2 0 1 0 − x 3 0 x 1 0 0 1 x 2 − x 1 0 ] \tilde{J}_E = \begin{bmatrix} 1 & 0 & 0 & 0 & x_3 & -x_2 \\ 0 & 1 & 0 & -x_3 & 0 & x_1 \\ 0 & 0 & 1 & x_2 & -x_1 & 0 \end{bmatrix} J~E= 1000100010x3x2x30x1x2x10

解释:雅可比矩阵的每一列对应于变换参数对输出的偏导数,表示输入参数对输出的影响。

二阶导数

∂ 2 x ′ ∂ p i ∂ p j = [ 0 0 0 ] \frac{\partial^2 \mathbf{x'}}{\partial p_i \partial p_j} = \begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} pipj2x= 000

解释:所有二阶偏导数均为零,表示在小角度近似下,变换的非线性影响被忽略。


3. 轴/角旋转

使用轴/角表示法会导致七维的优化问题:三个平移参数、三个旋转轴参数和一个旋转角度。变换函数为:

T A ( p 7 , x ) = [ t r 2 + c t r t y t r − s t z t r t z + s t y t r t y t r + s t z t r 2 + c − s t x t r t z − s t y t r t y + s t x t r 2 + c ] x + [ t x t y t z ] T_A(\mathbf{p}_7, \mathbf{x}) = \begin{bmatrix} t_r^2 + c & t_r t_y t_r - s t_z & t_r t_z + s t_y \\ t_r t_y t_r + s t_z & t_r^2 + c & -s t_x \\ t_r t_z - s t_y & t_r t_y + s t_x & t_r^2 + c \end{bmatrix} \mathbf{x} + \begin{bmatrix} t_x \\ t_y \\ t_z \end{bmatrix} TA(p7,x)= tr2+ctrtytr+stztrtzstytrtytrstztr2+ctrty+stxtrtz+stystxtr2+c x+ txtytz

其中   p 7 = [ t ∣ r ∣ ϕ ] T \ \mathbf{p}_7 = [\mathbf{t} | \mathbf{r} | \phi]^T  p7=[trϕ]T   t = [ t x , t y , t z ] T \ \mathbf{t} = [t_x, t_y, t_z]^T  t=[tx,ty,tz]T是平移,   r = [ r x , r y , r z ] T \ \mathbf{r} = [r_x, r_y, r_z]^T  r=[rx,ry,rz]T是旋转轴,   s = sin ⁡ ϕ \ s = \sin \phi  s=sinϕ   c = cos ⁡ ϕ \ c = \cos \phi  c=cosϕ   t = 1 − cos ⁡ ϕ \ t = 1 - \cos \phi  t=1cosϕ

解释:使用轴/角表示法,变换函数将平移和旋转结合在一起,形成一个复杂的变换矩阵。

雅可比矩阵

J A = [ 1 0 0 0 1 0 0 0 1 t ( 2 r x x 1 + r y x 2 + r z x 3 ) t r y x 1 − s x 3 t r z x 1 + s x 2 t r x x 2 + s x 3 t ( r x x 1 + 2 r y x 2 + r z x 3 ) t r z x 2 − s x 1 t r x x 3 − s x 2 t r y x 3 + s x 1 t ( r x x 1 + r y x 2 + 2 r z x 3 ) ] J_A = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ t(2r_x x_1 + r_y x_2 + r_z x_3) & t r_y x_1 - s x_3 & t r_z x_1 + s x_2 \\ t r_x x_2 + s x_3 & t(r_x x_1 + 2 r_y x_2 + r_z x_3) & t r_z x_2 - s x_1 \\ t r_x x_3 - s x_2 & t r_y x_3 + s x_1 & t(r_x x_1 + r_y x_2 + 2 r_z x_3) \end{bmatrix} JA= 100t(2rxx1+ryx2+rzx3)trxx2+sx3trxx3sx2010tryx1sx3t(rxx1+2ryx2+rzx3)tryx3+sx1001trzx1+sx2trzx2sx1t(rxx1+ryx2+2rzx3)

解释:雅可比矩阵用于计算变换参数对输出的影响,包含了平移和旋转的复杂关系。

海森矩阵

H A = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a b c d 0 0 0 b e f g 0 0 0 c f b i 0 0 0 d g j j ] H_A = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & \mathbf{a} & \mathbf{b} & \mathbf{c} & \mathbf{d} \\ 0 & 0 & 0 & \mathbf{b} & \mathbf{e} & \mathbf{f} & \mathbf{g} \\ 0 & 0 & 0 & \mathbf{c} & \mathbf{f} & \mathbf{b} & \mathbf{i} \\ 0 & 0 & 0 & \mathbf{d} & \mathbf{g} & \mathbf{j} & \mathbf{j} \end{bmatrix} HA= 000000000000000000000000abcd000befg000cfbj000dgij

海森矩阵元素

  1. 元素   a \ \mathbf{a}  a
    a = [ 2 t x x 1 0 0 ] \mathbf{a} = \begin{bmatrix} 2t_x x_1 \\ 0 \\ 0 \end{bmatrix} a= 2txx100

  2. 元素   b \ \mathbf{b}  b
    b = [ t x x 2 t x x 1 0 ] \mathbf{b} = \begin{bmatrix} t_x x_2 \\ t_x x_1 \\ 0 \end{bmatrix} b= txx2txx10

  3. 元素   c \ \mathbf{c}  c
    c = [ t x x 3 0 t x x 1 ] \mathbf{c} = \begin{bmatrix} t_x x_3 \\ 0 \\ t_x x_1 \end{bmatrix} c= txx30txx1

  4. 元素   d \ \mathbf{d}  d
    d = [ s ( 2 r x x 1 + r y x 2 + r z x 3 ) s r y x 1 − c x 3 s r z x 1 + c x 2 ] \mathbf{d} = \begin{bmatrix} s(2r_x x_1 + r_y x_2 + r_z x_3) \\ s r_y x_1 - c x_3 \\ s r_z x_1 + c x_2 \end{bmatrix} d= s(2rxx1+ryx2+rzx3)sryx1cx3srzx1+cx2

  5. 元素   e \ \mathbf{e}  e
    e = [ 0 2 t x x 2 0 ] \mathbf{e} = \begin{bmatrix} 0 \\ 2t_x x_2 \\ 0 \end{bmatrix} e= 02txx20

  6. 元素   f \ \mathbf{f}  f
    f = [ 0 t x x 3 t x x 2 ] \mathbf{f} = \begin{bmatrix} 0 \\ t_x x_3 \\ t_x x_2 \end{bmatrix} f= 0txx3txx2

  7. 元素   g \ \mathbf{g}  g
    g = [ s r x x 2 + c x 3 s ( r x x 1 + 2 r y x 2 + r z x 3 ) s r z x 2 − c x 1 ] \mathbf{g} = \begin{bmatrix} s r_x x_2 + c x_3 \\ s(r_x x_1 + 2 r_y x_2 + r_z x_3) \\ s r_z x_2 - c x_1 \end{bmatrix} g= srxx2+cx3s(rxx1+2ryx2+rzx3)srzx2cx1

  8. 元素   h \ \mathbf{h}  h
    h = [ 0 0 2 t x x 3 ] \mathbf{h} = \begin{bmatrix} 0 \\ 0 \\ 2t_x x_3 \end{bmatrix} h= 002txx3

  9. 元素   i \ \mathbf{i}  i
    i = [ s r x x 3 − c x 2 s r y x 3 + c x 1 s ( r x x 1 + r y x 2 + 2 r z x 3 ) ] \mathbf{i} = \begin{bmatrix} s r_x x_3 - c x_2 \\ s r_y x_3 + c x_1 \\ s(r_x x_1 + r_y x_2 + 2 r_z x_3) \end{bmatrix} i= srxx3cx2sryx3+cx1s(rxx1+ryx2+2rzx3)

  10. 元素   j \ \mathbf{j}  j
    j = [ c A + s B c C + s D c E + s F ] \mathbf{j} = \begin{bmatrix} c A + s B \\ c C + s D \\ c E + s F \end{bmatrix} j= cA+sBcC+sDcE+sF

解释:这些元素代表了海森矩阵的各个部分,描述了不同参数对变换的二阶影响,帮助优化算法更有效地收敛和调整。


猜你喜欢

转载自blog.csdn.net/weixin_41331879/article/details/142998211