数学基础—矩阵
1. 代数计算
1.1线性方程
1.1.1 定义
线性方程也称为一次方程,因为在笛卡尔坐标系上任何一个一次方程的表示都是一条直线。组成一次方程的每个项必须是常数或者是一个常数和一个变量的乘积。且方程中必须包含一个变量,因为如果没有变量只有常数的式子是算数式而非方程式。
如果一个一次方程中只包含一个变量(x),那么该方程就是一元一次方程。如果包含两个变量(x和y),那么就是一个二元一次方程,以此类推。
1.1.2 性质
1.可加性
f
(
x
1
+
x
2
)
=
f
(
x
1
)
+
f
(
x
2
)
例:
3
x
+
4
y
=
1
;
f(x_1 + x_2)=f(x_1) + f(x_2) \\ \ \\ 例:3x + 4y = 1;
f(x1+x2)=f(x1)+f(x2) 例:3x+4y=1;
2.比例性
f
(
k
x
)
=
k
f
(
x
)
例:
x
+
y
=
1
;
2
x
+
2
y
=
2
;
f(kx) = kf(x) \\ \ \\ 例:x+y = 1;\\ \ \ \ \ 2x + 2y = 2;
f(kx)=kf(x) 例:x+y=1; 2x+2y=2;
1.1.3 线性空间
直线变换后依然是直线 并且等比坐标原点保持不变。
1.1.4 非线性空间
空间扭曲,不是等距,坐标原点有位移。
1.1.5 矩阵方式解线性方程组
解线性方程组
{
2
x
+
3
y
=
1
x
+
y
=
2
\begin{cases} 2x + 3y = 1 \\ x + y = 2 \end{cases}
{2x+3y=1x+y=2
将x,y隐藏,并将等号右边的数字一起提交出来,成为增广矩阵
[
2
3
1
1
1
2
]
\begin{bmatrix} 2 & 3 & 1 \\ 1 & 1 & 2 \end{bmatrix}
[213112]
和代数解方程一样,每一行可以单独乘以系数或者每行相加减
[
2
3
1
1
1
2
]
⟹
r
2
′
=
r
1
−
2
r
2
[
2
3
1
0
1
−
3
]
⟹
r
1
′
=
1
2
(
r
1
−
3
r
2
)
[
1
0
5
0
1
−
3
]
\begin{bmatrix} 2 & 3 & 1 \\ 1 & 1 & 2 \end{bmatrix} \overset{r_2' = r_1 - 2r_2}{\implies} \begin{bmatrix} 2 & 3 & 1 \\ 0 & 1 & -3 \end{bmatrix} \overset{r_1' = \frac{1}{2}( r_1 - 3r_2)}{\implies} \begin{bmatrix} 1 & 0 & 5 \\ 0 & 1 & -3 \end{bmatrix}
[213112]⟹r2′=r1−2r2[20311−3]⟹r1′=21(r1−3r2)[10015−3]
等同于
{
x
+
0
×
y
=
5
0
×
x
+
y
=
−
3
解得
x
=
5
,
y
=
−
3
\begin{cases} x + 0 \times y = 5 \\ 0 \times x + y = -3 \end{cases} \ \ 解得\ x=5,y=-3
{x+0×y=50×x+y=−3 解得 x=5,y=−3
1.1.5 线性方程组和矩阵的关系
可以通过列空间(向量)从矩阵变换的角度去理解
{
2
x
+
3
y
=
1
x
+
y
=
2
⟶
{
x
+
0
y
=
5
0
x
+
y
=
−
3
\begin{cases} 2x + 3 y = 1 \\ x + y = 2 \end{cases} \longrightarrow \begin{cases} x + 0y = 5 \\ 0 x + y = -3 \end{cases}
{2x+3y=1x+y=2⟶{x+0y=50x+y=−3
[ 2 3 1 1 1 2 ] i ′ → j ′ → 新坐标系下的顶点 ⟶ [ 1 0 5 0 1 − 3 ] i → j → 标准坐标系下的顶点 \overset{\overrightarrow{i'}\ \overrightarrow{j'} 新坐标系下的顶点}{\begin{bmatrix} 2 & 3 & 1 \\ 1 & 1 & 2 \end{bmatrix}} \longrightarrow \overset{\overrightarrow{i}\ \overrightarrow{j} 标准坐标系下的顶点}{\begin{bmatrix} 1 & 0 & 5 \\ 0 & 1 & -3 \end{bmatrix}} [213112]i′ j′新坐标系下的顶点⟶[10015−3]i j标准坐标系下的顶点
2. 矩阵基本
2.1 矩阵的定义
由
m
×
n
个数
a
i
j
排成的
m
行
n
列的数表称为
m
行
n
列的矩阵,简称
m
×
n
矩阵。记作:
A
=
[
a
11
a
12
.
.
.
a
1
n
a
21
a
22
.
.
.
a
2
n
.
.
.
.
.
.
.
.
.
.
.
.
a
m
1
a
m
2
.
.
.
a
m
n
]
数
a
i
j
位于矩阵
A
的第
i
行第
j
列,称为矩阵
A
的
(
i
,
j
)
元,以数
a
i
j
为
(
i
,
j
)
元的矩阵可记为
(
a
i
j
)
或
(
a
i
j
)
,
m
×
n
矩阵
A
也记作
A
m
n
由 m × n 个数a_{ij}排成的m行n列的数表称为m行n列的矩阵,简称m × n矩阵。记作:\\ \ \\ A=\begin{bmatrix} a_{11} & a_{12} & ... & a_{1n} \\ a_{21} & a_{22} & ... & a_{2n}\\ ... & ... &... &...\\ a_{m1} & a_{m2} & ... & a_{mn} \end{bmatrix} \\ \ \\ 数a_{ij}位于矩阵A的第i行第j列,称为矩阵A的(i,j)元,以数 a_{ij}为(i,j)元的矩阵可记为\\ \ \\ (a_{ij})或(a_{ij}), m×n矩阵A也记作 A_{mn}
由m×n个数aij排成的m行n列的数表称为m行n列的矩阵,简称m×n矩阵。记作: A=
a11a21...am1a12a22...am2............a1na2n...amn
数aij位于矩阵A的第i行第j列,称为矩阵A的(i,j)元,以数aij为(i,j)元的矩阵可记为 (aij)或(aij),m×n矩阵A也记作Amn
元素是实数的矩阵称为实矩阵,元素是复数的矩阵称为复矩阵。而行数与列数都等于n的矩阵称为n阶矩阵或n阶方阵。
2.2 特殊矩阵
方阵
行数列数都相等,且都等于 n 的矩阵成为 n 阶矩阵或 n 阶方阵。
例:
2
阶方阵
[
3
5
1
2
]
3
阶方阵
[
2
1
9
3
1
5
4
6
8
]
2阶方阵 \ \ \begin{bmatrix} 3 & 5\\ 1 & 2 \end{bmatrix} \\ \ \\ 3阶方阵 \ \ \begin{bmatrix} 2 & 1 & 9\\ 3 & 1 & 5\\ 4 & 6 & 8 \end{bmatrix}
2阶方阵 [3152] 3阶方阵
234116958
单位矩阵 I
n x n矩阵,从左到右的对角线上的元素是1,其余元素都是0。
例:
2
阶单位矩阵
[
1
0
0
1
]
3
阶单位矩阵
[
1
0
0
0
1
0
0
0
1
]
2阶单位矩阵 \ \ \begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix} \\ \ \\ 3阶单位矩阵 \ \ \begin{bmatrix} 1 &0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1 \end{bmatrix}
2阶单位矩阵 [1001] 3阶单位矩阵
100010001
零矩阵 O
元素都是零的矩阵。
例:
2
阶零矩阵
[
0
0
0
0
]
3
阶零矩阵
[
0
0
0
0
0
0
0
0
0
]
2阶零矩阵 \ \ \begin{bmatrix} 0& 0\\ 0 & 0 \end{bmatrix} \\ \ \\ 3阶零矩阵 \ \ \begin{bmatrix} 0 &0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0 \end{bmatrix}
2阶零矩阵 [0000] 3阶零矩阵
000000000
正交矩阵
如果一个方阵 A 和 它的转置矩阵的乘积是单位矩阵的话,我们就说这个矩阵是正交的
A
A
T
=
A
T
A
=
I
AA^T = A^TA=I
AAT=ATA=I
矩阵 M 是正交的等价于:
A
T
=
A
−
1
A^T = A^{-1}
AT=A−1
2.3 矩阵的运算
矩阵的加减法
两个矩阵的行数相等、列数也相等,就称它们是同阵型矩阵。
例:
[
3
5
0
0
2
0
4
0
1
]
[
2
5
5
2
3
4
4
0
1
]
\begin{bmatrix} 3 &5 & 0\\ 0 & 2 & 0\\ 4 & 0 & 1 \end{bmatrix} \ \ \ \ \begin{bmatrix} 2 &5 & 5 \\ 2 & 3 & 4\\ 4 & 0 & 1 \end{bmatrix}
304520001
224530541
矩阵的加法即对应位置相加,只有同型矩阵才能相加
[
3
5
1
2
]
+
[
1
3
0
4
]
=
[
3
+
1
5
+
3
1
+
0
2
+
4
]
=
[
4
8
1
6
]
\begin{bmatrix} 3 &5\\ 1 & 2 \end{bmatrix} + \begin{bmatrix} 1 & 3\\ 0 & 4 \end{bmatrix} = \begin{bmatrix} 3 + 1 & 5 + 3\\ 1 + 0 & 2 + 4 \end{bmatrix} = \begin{bmatrix} 4 & 8\\ 1 & 6 \end{bmatrix}
[3152]+[1034]=[3+11+05+32+4]=[4186]
矩阵的加法满足交换律和结合律
交换律:A + B = B + A
结合律:(A + B) + C = A + (B + C)
矩阵的减法
A - B = A + (-B)
矩阵的数乘
将数k与矩阵A的乘既记做kA
k
A
=
A
k
=
[
k
a
11
k
a
12
.
.
.
k
a
1
n
k
a
21
k
a
22
.
.
.
k
a
2
n
.
.
.
.
.
.
.
.
.
.
.
.
k
a
m
1
k
a
m
2
.
.
.
k
a
m
n
]
kA = Ak = \begin{bmatrix} ka_{11} &k a_{12} & ... & ka_{1n} \\ ka_{21} & ka_{22} & ... & ka_{2n}\\ ... & ... &... &...\\ ka_{m1} & ka_{m2} & ... & ka_{mn} \end{bmatrix}
kA=Ak=
ka11ka21...kam1ka12ka22...kam2............ka1nka2n...kamn
k与矩阵A的每个数进行相乘
例:
3
×
[
1
3
0
4
]
=
[
3
∗
1
3
∗
3
3
∗
0
3
∗
4
]
=
[
3
9
0
12
]
3 \times \begin{bmatrix} 1 & 3 \\ 0 & 4 \end{bmatrix} = \begin{bmatrix} 3 * 1 & 3 *3\\ 3* 0 & 3* 4 \end{bmatrix} = \begin{bmatrix} 3 & 9\\ 0 & 12 \end{bmatrix}
3×[1034]=[3∗13∗03∗33∗4]=[30912]
矩阵的乘法
矩阵的乘法是两个矩阵进行相乘,需要满足一定的合法性
m
×
n
的矩阵只能和
n
×
p
矩阵相乘
相乘后的矩阵大小为
m
×
p
m \times n的矩阵只能和n \times p矩阵相乘\\ 相乘后的矩阵大小为m \times p
m×n的矩阵只能和n×p矩阵相乘相乘后的矩阵大小为m×p
规则:上一个矩阵的行向量乘下一个矩阵的列向量。
矩阵乘法举例
[
2
1
0
3
5
4
]
×
[
7
6
8
9
]
=
[
2
∗
7
+
1
∗
8
2
∗
6
+
1
∗
9
0
∗
7
+
3
∗
8
0
∗
6
+
3
∗
9
5
∗
7
+
4
∗
8
5
∗
6
+
4
∗
9
]
\begin{bmatrix} 2 & 1\\ 0 & 3\\ 5 & 4 \end{bmatrix} \times \begin{bmatrix} 7 & 6\\ 8 & 9\\ \end{bmatrix} = \begin{bmatrix} 2*7+1*8 & 2*6 + 1*9\\ 0*7 + 3*8 & 0*6+3*9\\ 5*7 + 4*8 & 5*6 + 4*9 \end{bmatrix}
205134
×[7869]=
2∗7+1∗80∗7+3∗85∗7+4∗82∗6+1∗90∗6+3∗95∗6+4∗9
矩阵的乘法并不是所有都满足乘法运算规律运算
交换律:
矩阵的数乘满足交换律 k(AB) =A(kB);
矩阵之间的乘法不一定满足,特殊矩阵满足,如单位矩阵相乘
满足结合律: (AB)C = A(BC)
满足分配律:A(B+C) = AB + AC
矩阵的转置
把矩阵
A
的行和列互相交换所产生的矩阵称为
A
的转置矩阵
A
T
,这一过程称为矩阵的转置。
把矩阵A的行和列互相交换所产生的矩阵称为A的转置矩阵A^T ,这一过程称为矩阵的转置。\\
把矩阵A的行和列互相交换所产生的矩阵称为A的转置矩阵AT,这一过程称为矩阵的转置。
矩阵的转置满足以下运算律:
(
A
T
)
T
=
A
(
λ
B
)
T
=
λ
A
T
(
A
B
)
T
=
B
T
A
T
(A^T)^T = A \\ \ \\ (\lambda B)^T = \lambda A^T\\ \ \\ (AB)^T = B^TA^T
(AT)T=A (λB)T=λAT (AB)T=BTAT
3.矩阵变换
3.1 2D矩阵变换
1.缩放(Scale Transform)
1.1均匀缩放
在直角坐标系下,将图缩放s倍,可得新的图片坐标:
x
′
=
s
x
y
′
=
s
y
x' = sx \\ y' = sy
x′=sxy′=sy
写成矩阵的形式为
[
x
′
y
′
]
=
[
s
0
0
s
]
[
x
y
]
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} s & 0\\ 0 & s \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}
[x′y′]=[s00s][xy]
1.2非均匀缩放
在直角坐标系下,将图的x轴缩放
s
x
s_x
sx倍,y轴缩放
s
y
s_y
sy倍可得新的图片坐标:
x
′
=
s
x
x
y
′
=
s
y
y
x' = s_xx \\ y' = s_yy
x′=sxxy′=syy
写成矩阵的形式为
[
x
′
y
′
]
=
[
s
x
0
0
s
y
]
[
x
y
]
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} s_x & 0\\ 0 & s_y \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}
[x′y′]=[sx00sy][xy]
2.反射(reflect)
水平反射:
x
′
=
−
x
y
′
=
y
x' = -x \\ y' = y
x′=−xy′=y
矩阵形式:
[
x
′
y
′
]
=
[
−
1
0
0
1
]
[
x
y
]
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} -1 & 0\\ 0 & 1 \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}
[x′y′]=[−1001][xy]
3.切变(Shear)
水平方向的变换在 y=0 的位置为0,在 y=1 的位置为a,也就是x为原来x的位置加ay
竖直方向的变换总是为0,也就是y不变,则有
x
′
=
x
+
a
y
y
′
=
y
x' = x + ay \\ y' = y
x′=x+ayy′=y
对应的矩阵为
[
x
′
y
′
]
=
[
1
a
0
1
]
[
x
y
]
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} 1 & a\\ 0 & 1 \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}
[x′y′]=[10a1][xy]
4.旋转
默认是绕原点进行旋转,该图原点在左下角
从
P
1
P_1
P1变换到
P
1
′
P_1'
P1′
:
:
:
(
x
,
y
)
⟹
(
x
′
,
y
′
)
.
.
.
.
.
1
◯
(x,y)\Longrightarrow(x',y').....\text{\textcircled {\small 1} }
(x,y)⟹(x′,y′).....1◯
则变换应满足
[
x
′
y
′
]
=
[
A
B
C
D
]
[
x
y
]
⟹
[
A
B
C
D
]
[
x
y
]
.
.
.
.
.
.
.
.
2
◯
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}\Longrightarrow \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}........\text{\textcircled {\small 2}}
[x′y′]=[ACBD][xy]⟹[ACBD][xy]........2◯
由
1
◯
\text{\textcircled {\small 1}}
1◯式,可得
( x , y ) ⟹ ( x ′ , y ′ ) ⟶ ( 1 , 0 ) ⟹ ( cos θ , sin θ ) (x,y)\Longrightarrow(x',y')\longrightarrow (1,0)\Longrightarrow(\cos\theta,\sin\theta) (x,y)⟹(x′,y′)⟶(1,0)⟹(cosθ,sinθ)
由
2
◯
\text{\textcircled {\small 2}}
2◯式,写成矩阵形式
[
cos
θ
sin
θ
]
=
[
A
B
C
D
]
[
1
0
]
\begin{bmatrix} \cos\theta \\ \sin\theta \end {bmatrix}= \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} 1\\0 \end {bmatrix}
[cosθsinθ]=[ACBD][10]
可得,
cos
θ
=
A
⋅
1
+
B
⋅
0
=
A
sin
θ
=
C
⋅
1
+
D
⋅
0
=
C
\cos\theta = A \cdot 1 + B \cdot 0 = A \\ \sin\theta = C \cdot 1 + D \cdot 0 = C
cosθ=A⋅1+B⋅0=Asinθ=C⋅1+D⋅0=C
从
P
2
P_2
P2变换到
P
2
′
P_2'
P2′
:
:
:
(
x
,
y
)
⟹
(
x
′
,
y
′
)
.
.
.
.
.
1
◯
(x,y)\Longrightarrow(x',y').....\text{\textcircled {\small 1} }
(x,y)⟹(x′,y′).....1◯
则变换应满足
[
x
′
y
′
]
=
[
A
B
C
D
]
[
x
y
]
⟹
[
A
B
C
D
]
[
x
y
]
.
.
.
.
.
.
.
.
3
◯
\begin{bmatrix} x'\\y' \end {bmatrix}= \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}\Longrightarrow \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} x\\y \end {bmatrix}........\text{\textcircled {\small 3}}
[x′y′]=[ACBD][xy]⟹[ACBD][xy]........3◯
由
1
◯
\text{\textcircled {\small 1}}
1◯式,可得
( x , y ) ⟹ ( x ′ , y ′ ) ⟶ ( 0 , 1 ) ⟹ ( − sin θ , cos θ ) (x,y)\Longrightarrow(x',y')\longrightarrow (0,1)\Longrightarrow(-\sin\theta\ ,\cos \theta) (x,y)⟹(x′,y′)⟶(0,1)⟹(−sinθ ,cosθ)
由
2
◯
\text{\textcircled {\small 2}}
2◯式,写成矩阵形式
[
−
sin
θ
cos
θ
]
=
[
A
B
C
D
]
[
0
1
]
\begin{bmatrix} -\sin\theta \\ \cos\theta \end {bmatrix}= \begin{bmatrix} A & B\\ C & D \end {bmatrix} \begin{bmatrix} 0\\1 \end {bmatrix}
[−sinθcosθ]=[ACBD][01]
可得,
−
sin
θ
=
A
⋅
0
+
B
⋅
1
=
B
cos
θ
=
C
⋅
0
+
D
⋅
1
=
D
-\sin\theta = A \cdot 0 + B \cdot 1 = B \\ \cos\theta = C \cdot 0 + D \cdot 1 = D
−sinθ=A⋅0+B⋅1=Bcosθ=C⋅0+D⋅1=D
由
2
◯
\text{\textcircled {\small 2}}
2◯式
结合解出的A、B、C、D的值,可得旋转矩阵
R θ = [ cos θ − sin θ sin θ cos θ ] R_\theta= \begin{bmatrix} \cos\theta & -\sin\theta\\ \sin\theta & \cos\theta \end {bmatrix} Rθ=[cosθsinθ−sinθcosθ]
同理,若要旋转-
θ
\theta
θ角,有
R
−
θ
=
[
cos
θ
sin
θ
−
sin
θ
cos
θ
]
=
R
θ
T
=
R
θ
−
1
R_{-\theta} = \begin{bmatrix} \cos\theta & \sin\theta\\ -\sin\theta & \cos\theta \end {bmatrix} =R_\theta^T =R_\theta^{-1}
R−θ=[cosθ−sinθsinθcosθ]=RθT=Rθ−1
矩阵的转置等于矩阵的逆,所以旋转矩阵属于正交矩阵。
LinearTransforms(线性变换) = Matrices(of the same dimension)(相同维度的矩阵)
由上几种变换总结得出
x
′
=
a
x
+
b
y
y
′
=
c
x
+
d
y
[
x
′
y
′
]
=
[
a
b
c
d
]
[
x
y
]
x
′
=
M
x
x' = ax + by\\ y' = cx+dy \\ \ \\ \begin{bmatrix} x' \\ y' \end {bmatrix}= \begin{bmatrix} a & b\\ c & d \end {bmatrix} \begin{bmatrix} x \\ y \end {bmatrix} \\ \ \\ x' = Mx
x′=ax+byy′=cx+dy [x′y′]=[acbd][xy] x′=Mx
5.平移变换
x
′
=
x
+
t
x
y
′
=
y
+
t
y
x' = x + t_x \\ y' = y + t_y
x′=x+txy′=y+ty
为什么要引入其次坐标?
平移变换不能用前面几种变换的矩阵形式表示出来,而是用如下形式的矩阵表示出来
[
x
′
y
′
]
=
[
a
b
c
d
]
[
x
y
]
+
[
t
x
t
y
]
\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b\\ c & d \end{bmatrix} \begin{bmatrix} x\\ y \end{bmatrix} + \begin{bmatrix} t_x\\ t_y \end{bmatrix}
[x′y′]=[acbd][xy]+[txty]
由上可知,平移操作并不属于线性变换
但是我们不希望把平移变换当特殊矩阵去考虑
有没有办法能够把所有的变换,用一个最简单的方法去表示?(并且代价是什么?)
解决:齐次坐标
添加第三个坐标(记为w坐标)
⋅
2
D
p
o
i
n
t
=
(
x
,
y
,
\cdot 2D\ point = (x,y,
⋅2D point=(x,y,1
)
T
)^T
)T
⋅
2
D
v
e
c
t
o
r
=
(
x
,
y
,
\cdot 2D\ vector = (x,y,
⋅2D vector=(x,y,0
)
T
)^T
)T
矩阵的平移变换表达式
[
x
′
y
′
w
′
]
=
[
1
0
t
x
0
1
t
y
0
0
1
]
[
x
y
1
]
=
[
x
+
t
x
y
+
t
y
1
]
\begin{bmatrix} x'\\ y'\\ w' \end{bmatrix} = \begin{bmatrix} 1 & 0 & t_x\\ 0 & 1 & t_y\\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x\\ y\\ 1 \end{bmatrix}= \begin{bmatrix} x + t_x\\ y + t_y\\ 1 \end{bmatrix}
x′y′w′
=
100010txty1
xy1
=
x+txy+ty1
如果w坐标的运算结果是1或者0是有意义的
⋅
v
e
c
t
o
r
+
v
e
c
t
o
r
=
v
e
c
t
o
r
\cdot vector + vector = vector
⋅vector+vector=vector
⋅
p
o
i
n
t
−
p
o
i
n
t
=
v
e
c
t
o
r
\cdot point - point = vector
⋅point−point=vector
⋅
p
o
i
n
t
+
v
e
c
t
o
r
=
p
o
i
n
t
\cdot point + vector = point
⋅point+vector=point
⋅
p
o
i
n
t
+
p
o
i
n
t
=
?
?
\cdot point + point = ??
⋅point+point=??
扩充point + point = ??的定义
在齐次坐标中,
(
x
y
w
)
i
s
t
h
e
2
D
p
o
i
n
t
(
x
/
w
y
/
w
1
)
,
w
≠
0
\begin{pmatrix} x\\ y\\ w \end{pmatrix} is \ the \ 2D \ point \begin{pmatrix} x/w\\ y/w\\ 1 \end{pmatrix},w \not= 0
xyw
is the 2D point
x/wy/w1
,w=0
则可以得到,一个点加上另一个点之后,其实就是这两个点的中点。
证明:
设
p
o
i
n
t
=
(
x
,
y
,
1
)
T
point = (x,y,1)^T
point=(x,y,1)T
则
p
o
i
n
t
1
+
p
o
i
n
t
2
=
(
x
1
y
1
1
)
+
(
x
2
y
2
1
)
=
(
x
1
+
x
2
y
1
+
y
2
2
)
=
(
(
x
1
+
x
2
)
/
2
(
y
1
+
y
2
)
/
2
1
)
point_1 + point_2= \begin{pmatrix} x_1\\ y_1\\ 1 \end{pmatrix} + \begin{pmatrix} x_2\\ y_2\\ 1 \end{pmatrix} = \begin{pmatrix} x_1 + x_2\\ y_1 + y_2\\ 2 \end{pmatrix} =\begin{pmatrix} (x_1 + x_2)/2\\ (y_1+y_2)/2 \\ 1 \end{pmatrix}
point1+point2=
x1y11
+
x2y21
=
x1+x2y1+y22
=
(x1+x2)/2(y1+y2)/21
6.仿射变换(Affine Transformations)
A
f
f
i
n
e
m
a
p
=
l
i
n
e
a
r
m
a
p
+
t
r
a
n
s
l
a
t
i
o
n
Af fine \ map = linear \ map + translation
Affine map=linear map+translation
(
x
′
y
′
)
=
(
a
b
c
d
)
⋅
(
x
y
)
+
(
t
x
t
y
)
\begin{pmatrix} x'\\ y' \end{pmatrix}= \begin{pmatrix} a & b \\ c & d \end{pmatrix}\cdot \begin{pmatrix} x\\y \end{pmatrix} + \begin{pmatrix} t_x\\ t_y \end{pmatrix}
(x′y′)=(acbd)⋅(xy)+(txty)
使用齐次坐标:
(
x
′
y
′
1
)
=
(
a
b
t
x
c
d
t
y
0
0
1
)
⋅
(
x
y
1
)
\begin{pmatrix} x'\\ y'\\ 1 \end{pmatrix}= \begin{pmatrix} a & b & t_x\\ c & d & t_y\\ 0 & 0 & 1 \end{pmatrix}\cdot \begin{pmatrix} x\\y\\1 \end{pmatrix}
x′y′1
=
ac0bd0txty1
⋅
xy1
由此推出2D变换
1.缩放
S
(
s
x
,
s
y
)
=
(
s
x
0
0
0
s
y
0
0
0
1
)
S(s_x,s_y) = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{pmatrix}
S(sx,sy)=
sx000sy0001
2.旋转
R
(
α
)
=
(
cos
α
−
sin
α
0
sin
α
cos
α
0
0
0
1
)
R(\alpha) = \begin{pmatrix} \cos \alpha & -\sin \alpha & 0 \\ \sin \alpha & \cos \alpha & 0 \\ 0 & 0 & 1 \end{pmatrix}
R(α)=
cosαsinα0−sinαcosα0001
3.平移
T
(
t
x
,
t
y
)
=
(
1
0
t
x
0
1
t
y
0
0
1
)
T(t_x,t_y)= \begin{pmatrix} 1 & 0 & t_x \\ 0 &1& t_y \\ 0 & 0 & 1 \end{pmatrix}
T(tx,ty)=
100010txty1
7.逆变换(Inverse Transform)
M
−
1
M^{-1}
M−1
M
−
1
M^{-1}
M−1是
M
M
M的逆变换
在矩阵和几何中,一张图平移旋转后相当于乘一个变换矩阵,然后想把它变回到原来的样子相当于乘这个变换矩阵的逆矩阵。
8.组合变换(Composite Transform)
首先考虑左边这幅图怎么变换得到右边这幅图
如果是先平移后旋转
因为默认都是绕着原点旋转,然后发现不对,变换之后不一样。
然后再考虑先旋转后平移
这样变换之后就变的一样了。从这里可以得到两个结论:
1.复杂矩阵的变换,可以通过简单矩阵的变换得到
2.变换的顺序是非常重要的,由上可知,变换的顺序不同,变换后的结果也不同。
变换所遵循的关系
矩阵不满足交换律。
R
45
⋅
T
(
1
,
0
)
≠
T
(
1
,
0
)
⋅
R
45
R_{45} \cdot T_{(1,0)} \not = T_{(1,0)}\cdot R_{45}
R45⋅T(1,0)=T(1,0)⋅R45
注意矩阵应用到变换是从右到左
T
(
1
,
0
)
⋅
R
45
[
x
y
1
]
=
[
1
0
1
0
1
0
0
0
1
]
[
cos
45
°
−
sin
45
°
0
sin
45
°
cos
45
°
0
0
0
1
]
[
x
y
1
]
T_{(1,0)}\cdot R_{45}\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}=\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} \cos 45\degree & -\sin 45\degree & 0 \\ \sin 45\degree & \cos 45\degree & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
T(1,0)⋅R45
xy1
=
100010101
cos45°sin45°0−sin45°cos45°0001
xy1
所以有一个点我们给他连续不同的变换
A
1
、
A
2
、
A
3
.
.
.
A
n
A_1、A_2、A_3...A_n
A1、A2、A3...An
通过矩阵相乘组合
A
n
(
.
.
.
A
2
(
A
1
(
x
)
)
)
=
A
n
⋅
⋅
⋅
A
2
⋅
A
1
⋅
(
x
y
1
)
=
A
′
⋅
(
x
y
1
)
A_n(...A_2(A_1(x))) = A_n \cdot \cdot \ \cdot A_2 \cdot A_1 \cdot \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}=A'\cdot \begin{pmatrix} x \\ y \\ 1 \end{pmatrix}
An(...A2(A1(x)))=An⋅⋅ ⋅A2⋅A1⋅
xy1
=A′⋅
xy1
从上式我们可以发现,由于矩阵满足结合律吧,我们可以把
A
1
、
A
2
.
.
.
A
n
A_1、A_2...A_n
A1、A2...An先乘起来,在乘后面这个点的坐标,值不变。而
A
1
、
A
2
.
.
.
A
n
A_1、A_2...A_n
A1、A2...An都是同阶矩阵,相乘之后就变成了一个矩阵,它也和前面那些矩阵同阶,相当于我们可以把一个非常复杂的变换用一个矩阵去表示,所以可以看出,这个表达式非常的厉害。
9.分解复杂变换(Decomping Complex Transform)
如何绕着点c进行旋转?
1.先平移到原点
2.再旋转
3.再平移回去
矩阵表达式:
T
(
c
)
⋅
R
(
α
)
⋅
T
(
−
c
)
T_{(c)} \cdot R_{(\alpha)} \cdot T(-c)
T(c)⋅R(α)⋅T(−c)
3.1 3D矩阵变换
再次使用齐次坐标:
⋅
3
D
p
o
i
n
t
=
(
x
,
y
,
z
,
1
)
T
\cdot 3D \ point = (x,y,z,1)^T
⋅3D point=(x,y,z,1)T
⋅
3
D
v
e
c
t
o
r
=
(
x
,
y
,
z
,
0
)
T
\cdot 3D \ vector = (x,y,z,0)^T
⋅3D vector=(x,y,z,0)T
通常情况下,(x,y,z,w)(w != 0) 3D点为:
(
x
/
w
,
y
/
w
,
z
/
w
)
(x/w,y/w,z/w)
(x/w,y/w,z/w)
使用
4
×
4
4 \times 4
4×4的仿射变换矩阵
(
x
′
y
′
z
′
1
)
=
(
a
b
c
t
x
d
e
f
t
y
g
h
i
t
z
0
0
0
1
)
⋅
(
x
y
z
1
)
\begin{pmatrix} x'\\ y'\\ z'\\ 1 \end{pmatrix}= \begin{pmatrix} a & b & c & t_x\\ d & e & f & t_y\\ g & h & i & t_z\\ 0 & 0 & 0 & 1 \end{pmatrix}\cdot \begin{pmatrix} x\\ y\\ z\\ 1 \end{pmatrix}
x′y′z′1
=
adg0beh0cfi0txtytz1
⋅
xyz1
1.缩放
S
(
s
x
,
s
y
,
s
z
)
=
(
s
x
0
0
0
0
s
y
0
0
0
0
s
z
0
0
0
0
1
)
S_{(s_x,s_y,s_z)}=\begin{pmatrix} s_x & 0 & 0 & 0\\ 0 & s_y & 0 & 0\\ 0 & 0 & s_z & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}
S(sx,sy,sz)=
sx0000sy0000sz00001
2.平移
T
(
s
x
,
s
y
,
s
z
)
=
(
1
0
0
t
x
0
1
0
t
y
0
0
1
t
z
0
0
0
1
)
T_{(s_x,s_y,s_z)}=\begin{pmatrix} 1 & 0 & 0 & t_x\\ 0 & 1 & 0 & t_y\\ 0 & 0 & 1 & t_z\\ 0 & 0 & 0 & 1 \end{pmatrix}
T(sx,sy,sz)=
100001000010txtytz1
3.旋转
采用左手坐标系:以左手大拇指为X轴正方向,食指为Y轴正方向,此时大拇指和食指成一个八字形,然后加入中指,这个时候三个手指互相垂直,中指指的方向为Z轴正方向。
推导
定义一个三维空间中的一个点P(x,y,z),以P点作平面XOY、XOZ、YOZ的垂线,分别交平面XOY、
XOZ、YOZ于M(x,y,0)、N(x,0,z)、Q(0,y,z);
绕z轴旋转
点P(X,Y,Z)在XOY平面上的投影,绕z轴旋转,以顺时针为正方向旋转后如下图所示。
如图已知 O M ′ = O M , z ′ = z OM' = OM,z'=z OM′=OM,z′=z
当点P(x,y,z)移动到点P’(x’,y’,z’)时,点M(x,y)移到点M’(x’,y’),对应的旋转公式为
x
=
O
M
cos
φ
y
=
O
M
sin
φ
x
′
=
O
M
′
cos
(
φ
+
θ
)
y
′
=
O
M
′
sin
(
φ
+
θ
)
x = OM \cos\varphi\\ y = OM \sin\varphi\\ \ \\ x' = OM' \cos (\varphi+\theta)\\ y' = OM' \sin(\varphi+\theta)\\
x=OMcosφy=OMsinφ x′=OM′cos(φ+θ)y′=OM′sin(φ+θ)
∵
O
M
′
=
O
M
,
z
′
=
z
\because OM' = OM,z'=z
∵OM′=OM,z′=z,则有
x
′
=
O
M
(
cos
φ
cos
θ
−
sin
φ
sin
θ
)
=
x
cos
θ
−
y
sin
θ
y
′
=
O
M
(
sin
φ
sin
θ
+
cos
φ
cos
θ
)
=
y
cos
θ
+
x
sin
θ
x' = OM(\cos \varphi \cos\theta - \sin\varphi \sin \theta)=x\cos \theta - y\sin \theta \\ y' = OM(\sin \varphi \sin\theta + \cos\varphi \cos \theta)=y\cos \theta + x\sin \theta
x′=OM(cosφcosθ−sinφsinθ)=xcosθ−ysinθy′=OM(sinφsinθ+cosφcosθ)=ycosθ+xsinθ
∴
\therefore
∴
[
x
′
y
′
z
′
]
=
R
z
(
θ
)
[
x
y
z
]
\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix}= Rz(\theta) \begin{bmatrix} x\\ y\\ z \end{bmatrix}
x′y′z′
=Rz(θ)
xyz
∴
\therefore
∴
R
z
(
θ
)
=
[
cos
θ
−
sin
θ
0
sin
θ
cos
θ
0
0
0
1
]
Rz(\theta)= \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix}
Rz(θ)=
cosθsinθ0−sinθcosθ0001
绕y轴旋转
点P(X,Y,Z)在XOZ平面上的投影,绕y轴旋转,以顺时针为正方向旋转后如下图所示。
如图已知 O N ′ = O N , y ′ = y ON' = ON,y'=y ON′=ON,y′=y
当点P(x,y,z)移动到点P’(x’,y’,z’)时,点N(x,z)移N’(x’,z’),对应的旋转公式为
x
=
O
N
cos
φ
z
=
O
N
sin
φ
x
′
=
O
N
′
cos
(
φ
−
θ
)
z
′
=
O
N
′
sin
(
φ
−
θ
)
x = ON \cos\varphi\\ z = ON \sin\varphi\\ \ \\ x' = ON' \cos (\varphi-\theta)\\ z' = ON' \sin(\varphi-\theta)\\
x=ONcosφz=ONsinφ x′=ON′cos(φ−θ)z′=ON′sin(φ−θ)
∵
O
N
′
=
O
N
,
y
′
=
y
\because ON' = ON,y'=y
∵ON′=ON,y′=y,则有
x
′
=
O
N
(
cos
φ
cos
θ
+
sin
φ
sin
θ
)
=
x
cos
θ
+
z
sin
θ
z
′
=
O
N
(
sin
φ
sin
θ
−
cos
φ
cos
θ
)
=
z
cos
θ
−
x
sin
θ
x' = ON(\cos \varphi \cos\theta + \sin\varphi \sin \theta) =x\cos \theta + z\sin \theta \\ z' = ON(\sin \varphi \sin\theta - \cos\varphi \cos \theta) =z\cos \theta - x\sin \theta
x′=ON(cosφcosθ+sinφsinθ)=xcosθ+zsinθz′=ON(sinφsinθ−cosφcosθ)=zcosθ−xsinθ
∴
\therefore
∴
[
x
′
y
′
z
′
]
=
R
y
(
θ
)
[
x
y
z
]
\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix}= Ry(\theta) \begin{bmatrix} x\\ y\\ z \end{bmatrix}
x′y′z′
=Ry(θ)
xyz
∴
\therefore
∴
R
y
(
θ
)
=
[
cos
θ
0
sin
θ
0
1
0
−
sin
θ
0
cos
θ
]
Ry(\theta)= \begin{bmatrix} \cos \theta & 0 & \sin \theta\\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix}
Ry(θ)=
cosθ0−sinθ010sinθ0cosθ
绕z轴旋转
点P(X,Y,Z)在YOZ平面上的投影,绕x轴旋转,以顺时针为正方向旋转后如下图所示。
如图已知
O
Q
′
=
O
Q
,
x
′
=
x
OQ' = OQ,x'=x
OQ′=OQ,x′=x
当点P(x,y,z)移动到点P’(x’,y’,z’)时,点Q(z,y)移到点Q’(z’,y’),对应的旋转公式为
z
=
O
Q
cos
φ
y
=
O
Q
sin
φ
z
′
=
O
Q
′
cos
(
φ
+
θ
)
y
′
=
O
Q
′
sin
(
φ
+
θ
)
z = OQ \cos\varphi\\ y = OQ \sin\varphi\\ \ \\ z' = OQ' \cos (\varphi+\theta)\\ y' = OQ' \sin(\varphi+\theta)\\
z=OQcosφy=OQsinφ z′=OQ′cos(φ+θ)y′=OQ′sin(φ+θ)
∵
O
Q
′
=
O
Q
,
x
′
=
x
\because OQ' = OQ,x'=x
∵OQ′=OQ,x′=x,则有
z
′
=
O
M
(
cos
φ
cos
θ
−
sin
φ
sin
θ
)
=
z
cos
θ
−
y
sin
θ
y
′
=
O
M
(
sin
φ
sin
θ
+
cos
φ
cos
θ
)
=
y
cos
θ
+
z
sin
θ
z' = OM(\cos \varphi \cos\theta - \sin\varphi \sin \theta)=z\cos \theta - y\sin \theta \\ y' = OM(\sin \varphi \sin\theta + \cos\varphi \cos \theta)=y\cos \theta + z\sin \theta
z′=OM(cosφcosθ−sinφsinθ)=zcosθ−ysinθy′=OM(sinφsinθ+cosφcosθ)=ycosθ+zsinθ
∴
\therefore
∴
[
x
′
y
′
z
′
]
=
R
x
(
θ
)
[
x
y
z
]
\begin{bmatrix} x'\\ y'\\ z' \end{bmatrix}= Rx(\theta) \begin{bmatrix} x\\ y\\ z \end{bmatrix}
x′y′z′
=Rx(θ)
xyz
∴
\therefore
∴
R
x
(
θ
)
=
[
0
0
1
0
cos
θ
−
sin
θ
0
sin
θ
cos
θ
]
Rx(\theta)= \begin{bmatrix} 0 & 0 & 1\\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \\ \end{bmatrix}
Rx(θ)=
0000cosθsinθ1−sinθcosθ
注:根据左手系还是右手系,以及正向旋转是顺时针还是逆时针,旋转矩阵也会有所不同,这里做的事根据左手系进行推导。
绕任意N轴旋转
首先思考:如果要让某个物体绕某个轴进行旋转,需要些什么条件呢?
1.旋转轴的方向(n)。
2.初始方向(v)。
如下图所示从初始方向v,绕旋转轴方向n旋转之后,方向变为v’。
如图可知,v从变化到v’,相当于v乘某个旋转矩阵后得到v’,则有
v
′
=
R
(
n
,
θ
)
v' = R_(n,\theta)
v′=R(n,θ)
然后将
v
′
v'
v′分解为相对n水平方向上
v
∥
v_{\parallel}
v∥和垂直方向的
v
⊥
v_{\perp}
v⊥,有
v
′
=
v
∥
+
v
⊥
v'= v_{\parallel} + v_{\perp}
v′=v∥+v⊥
如图所示
v
⊥
′
=
cos
θ
v
⊥
+
sin
θ
w
v
∥
=
(
v
⋅
n
)
n
v
⊥
=
v
−
v
∥
=
v
−
(
v
⋅
n
)
n
w
=
n
×
v
⊥
=
n
×
(
v
−
v
∥
)
=
n
×
v
−
n
×
v
∥
=
n
×
−
0
=
n
×
v
v
⊥
′
=
cos
θ
v
⊥
+
sin
θ
w
=
cos
θ
(
v
−
(
v
⋅
n
)
n
)
+
sin
θ
(
n
×
v
)
v'_\perp = \cos \theta v_\perp + \sin \theta w \\ v_{\parallel} = (v \cdot n)n \\ v_{\perp} = v - v_{\parallel}\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ = v-(v \cdot n)n \\ w = n \times v_{\perp} \\ \ \ \ \ \ \ \ \ \ \ \ \ \ = n \times (v - v_{\parallel}) \\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ =n \times v - n \times v_{\parallel} \\ \ \ \ =n \times - 0 \\ = n \times v \\ v'_\perp = \cos \theta v_{\perp}+ \sin \theta w \\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ = \cos \theta (v-(v \cdot n)n)+ \sin \theta ( n \times v)
v⊥′=cosθv⊥+sinθwv∥=(v⋅n)nv⊥=v−v∥ =v−(v⋅n)nw=n×v⊥ =n×(v−v∥) =n×v−n×v∥ =n×−0=n×vv⊥′=cosθv⊥+sinθw =cosθ(v−(v⋅n)n)+sinθ(n×v)
将
v
⊥
′
和
v
∥
v'_\perp和 v_{\parallel}
v⊥′和v∥代入
v
′
v'
v′中有:
v
′
=
v
⊥
′
+
v
∥
=
cos
θ
(
v
−
(
v
⋅
n
)
n
)
+
sin
θ
(
n
×
v
)
+
(
v
⋅
n
)
n
v' = v'_\perp + v_{\parallel}\\ =\cos \theta (v-(v \cdot n)n)+ \sin \theta ( n \times v) + (v \cdot n)n
v′=v⊥′+v∥=cosθ(v−(v⋅n)n)+sinθ(n×v)+(v⋅n)n
由此可知任意方向v绕旋转轴方向n旋转表达式,如果要求旋转矩阵只需要求出x,y,z轴单位向量(p,q,r)绕旋转轴方向n后所得的向量(p’,q’r’)即可。
x方向上:
p
=
(
1
,
0
,
0
)
T
p = (1,0 ,0)^T
p=(1,0,0)T
p
′
=
cos
θ
(
p
−
(
p
⋅
n
)
n
)
+
sin
θ
(
n
×
p
)
+
(
p
⋅
n
)
n
p' = \cos \theta(p -(p \cdot n)n) + \sin \theta(n \times p) + (p \cdot n)n
p′=cosθ(p−(p⋅n)n)+sinθ(n×p)+(p⋅n)n
= cos θ ( [ 1 0 0 ] − ( [ 1 0 0 ] ⋅ [ n x n y n z ] ) [ n x n y n z ] ) + sin θ ( [ n x n y n z ] × [ 1 0 0 ] ) + ( [ 1 0 0 ] ⋅ [ n x n y n z ] ) [ n x n y n z ] =\cos \theta \begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix}- \begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0 \end{bmatrix} \cdot \begin{bmatrix}n_x \\ n_y \\ n_z \end{bmatrix} \end{pmatrix} \begin{bmatrix}n_x \\ n_y \\ n_z \end{bmatrix} \end{pmatrix}+ \sin \theta \begin{pmatrix} \begin{bmatrix}n_x \\ n_y \\ n_z\end{bmatrix} \times \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} \end{pmatrix} + \begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} \cdot \begin{bmatrix} n_x \\ n_y \\ n_z \end{bmatrix} \end{pmatrix} \begin{bmatrix} n_x \\ n_y \\ n_z \end{bmatrix} =cosθ 100 − 100 ⋅ nxnynz nxnynz +sinθ nxnynz × 100 + 100 ⋅ nxnynz nxnynz
= ( [ 1 0 0 ] − n x [ n x n y n z ] ) + sin θ [ 0 n z − n y ] + n x [ n x n y n z ] = \begin{pmatrix} \begin{bmatrix}1 \\ 0 \\ 0\end{bmatrix} - n_x\begin{bmatrix}n_x \\ n_y \\ n_z\end{bmatrix} \end{pmatrix} + \sin \theta \begin{bmatrix}0 \\ n_z \\ -n_y\end{bmatrix} + n_x\begin{bmatrix}n_x \\ n_y \\ n_z\end{bmatrix} = 100 −nx nxnynz +sinθ 0nz−ny +nx nxnynz
= cos θ [ 1 − n x 2 − n x n y − n x n z ] + sin θ [ 0 n z − n y ] + [ n x 2 n x n y n x n z ] =\cos \theta \begin{bmatrix} 1 - n_x^2 \\ -n_xn_y \\-n_x n_z \end{bmatrix} + \sin \theta \begin{bmatrix}0 \\ n_z \\ -n_y\end{bmatrix}+ \begin{bmatrix}n_x^2 \\ n_xn_y \\ n_xn_z\end{bmatrix} =cosθ 1−nx2−nxny−nxnz +sinθ 0nz−ny + nx2nxnynxnz
= [ cos θ − n x 2 cos θ − n x n y cos θ − n x n z cos θ ] + [ 0 n z sin θ − n y sin θ ] + [ n x 2 n x n y n x n z ] =\begin{bmatrix} \cos \theta - n_x^2\cos \theta \\ -n_xn_y \cos \theta \\-n_x n_z\cos \theta \end{bmatrix} + \begin{bmatrix}0 \\ n_z \sin \theta \\ -n_y \sin \theta\end{bmatrix}+ \begin{bmatrix}n_x^2 \\ n_xn_y \\ n_xn_z\end{bmatrix} = cosθ−nx2cosθ−nxnycosθ−nxnzcosθ + 0nzsinθ−nysinθ + nx2nxnynxnz
= [ cos θ − n x 2 cos θ + n x 2 − n x n y cos θ + n z sin θ + n x n y − n x n z cos θ − n y sin θ + n x n z ] =\begin{bmatrix} \cos \theta - n_x^2\cos \theta + n_x^2 \\ -n_xn_y \cos \theta + n_z \sin \theta + n_xn_y \\-n_x n_z\cos \theta -n_y \sin \theta + n_xn_z \end{bmatrix} = cosθ−nx2cosθ+nx2−nxnycosθ+nzsinθ+nxny−nxnzcosθ−nysinθ+nxnz
= [ n x 2 ( 1 − cos θ ) + cos θ n x n y ( 1 − cos θ ) + n z sin θ n x n z ( 1 − cos θ ) − n y sin θ ] =\begin{bmatrix} n_x^2(1 - \cos \theta) + \cos \theta \\ n_xn_y (1 - \cos \theta) + n_z \sin \theta \\n_x n_z(1 -\cos \theta) - n_y \sin \theta \end{bmatrix} = nx2(1−cosθ)+cosθnxny(1−cosθ)+nzsinθnxnz(1−cosθ)−nysinθ
同理在y轴上
q
=
(
0
,
1
,
0
)
T
q = (0,1,0)^T
q=(0,1,0)T
q
′
=
cos
θ
(
q
−
(
q
⋅
n
)
n
)
+
sin
θ
(
n
×
q
)
+
(
q
⋅
n
)
n
q' = \cos \theta(q -(q \cdot n)n) + \sin \theta(n \times q) + (q \cdot n)n
q′=cosθ(q−(q⋅n)n)+sinθ(n×q)+(q⋅n)n
=
[
n
x
n
y
(
1
−
cos
θ
)
−
n
z
sin
θ
n
y
2
(
1
−
cos
θ
)
+
cos
θ
n
y
n
z
(
1
−
cos
θ
)
+
n
x
sin
θ
]
=\begin{bmatrix} n_xn_y (1 - \cos \theta) - n_z \sin \theta\\ n_y^2(1 - \cos \theta) + \cos \theta \\n_y n_z(1 -\cos \theta) + n_x \sin \theta \end{bmatrix}
=
nxny(1−cosθ)−nzsinθny2(1−cosθ)+cosθnynz(1−cosθ)+nxsinθ
同理在z轴上
r
=
(
0
,
0
,
1
)
T
r = (0,0,1)^T
r=(0,0,1)T
r
′
=
cos
θ
(
r
−
(
r
⋅
n
)
n
)
+
sin
θ
(
n
×
r
)
+
(
r
⋅
n
)
n
r' = \cos \theta(r -(r \cdot n)n) + \sin \theta(n \times r) + (r \cdot n)n
r′=cosθ(r−(r⋅n)n)+sinθ(n×r)+(r⋅n)n
=
[
n
x
n
z
(
1
−
cos
θ
)
+
n
y
sin
θ
n
y
n
z
(
1
−
cos
θ
)
−
n
x
sin
θ
n
z
2
(
1
−
cos
θ
)
+
cos
θ
]
=\begin{bmatrix} n_xn_z (1 - \cos \theta) + n_y \sin \theta\\ n_y n_z(1 -\cos \theta) - n_x \sin \theta \\ n_z^2(1 - \cos \theta) + \cos \theta \end{bmatrix}
=
nxnz(1−cosθ)+nysinθnynz(1−cosθ)−nxsinθnz2(1−cosθ)+cosθ
综上可得变换矩阵:
T
=
[
p
′
q
′
r
′
]
T = \begin{bmatrix}p' & q' & r'\end{bmatrix}
T=[p′q′r′]
=
[
n
x
2
(
1
−
cos
θ
)
+
cos
θ
n
x
n
y
(
1
−
cos
θ
)
−
n
z
sin
θ
n
x
n
z
(
1
−
cos
θ
)
+
n
y
sin
θ
n
x
n
y
(
1
−
cos
θ
)
+
n
z
sin
θ
n
y
2
(
1
−
cos
θ
)
+
cos
θ
n
y
n
z
(
1
−
cos
θ
)
−
n
x
sin
θ
n
x
n
z
(
1
−
cos
θ
)
−
n
y
sin
θ
n
y
n
z
(
1
−
cos
θ
)
+
n
x
sin
θ
n
z
2
(
1
−
cos
θ
)
+
cos
θ
]
=\begin{bmatrix}n_x^2(1 - \cos \theta) + \cos \theta & n_xn_y (1 - \cos \theta) - n_z \sin \theta & n_xn_z (1 - \cos \theta) + n_y \sin \theta\\ n_xn_y (1 - \cos \theta) + n_z \sin \theta & n_y^2(1 - \cos \theta) + \cos \theta & n_y n_z(1 -\cos \theta) - n_x \sin \theta \\ n_x n_z(1 -\cos \theta) - n_y \sin \theta & n_y n_z(1 -\cos \theta) + n_x \sin \theta & n_z^2(1 - \cos \theta) + \cos \theta \end{bmatrix}
=
nx2(1−cosθ)+cosθnxny(1−cosθ)+nzsinθnxnz(1−cosθ)−nysinθnxny(1−cosθ)−nzsinθny2(1−cosθ)+cosθnynz(1−cosθ)+nxsinθnxnz(1−cosθ)+nysinθnynz(1−cosθ)−nxsinθnz2(1−cosθ)+cosθ
再根据仿射矩阵可得绕着x-,y-,z-,or n-axis旋转矩阵
R
x
(
θ
)
=
(
1
0
0
0
0
cos
θ
−
sin
θ
0
0
sin
θ
cos
θ
0
0
0
0
1
)
R_x(\theta) =\begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \cos\theta & -\sin\theta& 0\\ 0 & \sin\theta & \cos\theta& 0\\ 0 & 0 & 0 & 1 \end{pmatrix}
Rx(θ)=
10000cosθsinθ00−sinθcosθ00001
R y ( θ ) = ( cos θ 0 sin θ 0 0 1 0 0 − sin θ 0 cos θ 0 0 0 0 1 ) R_y(\theta) =\begin{pmatrix} \cos\theta & 0 & \sin\theta & 0\\ 0 & 1 & 0 & 0\\ -\sin\theta & 0 & \cos\theta & 0\\ 0 & 0 & 0 & 1 \end{pmatrix} Ry(θ)= cosθ0−sinθ00100sinθ0cosθ00001
R z ( θ ) = ( cos θ − sin θ 0 0 sin θ cos θ 0 0 0 0 1 0 0 0 0 1 ) R_z(\theta) =\begin{pmatrix} \cos\theta & -\sin\theta & 0 & 0\\ \sin\theta & \cos\theta & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix} Rz(θ)= cosθsinθ00−sinθcosθ0000100001
R ( n , θ ) = [ n x 2 ( 1 − cos θ ) + cos θ n x n y ( 1 − cos θ ) − n z sin θ n x n z ( 1 − cos θ ) + n y sin θ 0 n x n y ( 1 − cos θ ) + n z sin θ n y 2 ( 1 − cos θ ) + cos θ n y n z ( 1 − cos θ ) − n x sin θ 0 n x n z ( 1 − cos θ ) − n y sin θ n y n z ( 1 − cos θ ) + n x sin θ n z 2 ( 1 − cos θ ) + cos θ 0 0 0 0 1 ] R_{(n,\theta)} = \begin{bmatrix}n_x^2(1 - \cos \theta) + \cos \theta & n_xn_y (1 - \cos \theta) - n_z \sin \theta & n_xn_z (1 - \cos \theta) + n_y \sin \theta &0\\ n_xn_y (1 - \cos \theta) + n_z \sin \theta & n_y^2(1 - \cos \theta) + \cos \theta & n_y n_z(1 -\cos \theta) - n_x \sin \theta & 0\\ n_x n_z(1 -\cos \theta) - n_y \sin \theta & n_y n_z(1 -\cos \theta) + n_x \sin \theta & n_z^2(1 - \cos \theta) + \cos \theta & 0\\ 0 & 0 & 0 & 1 \end{bmatrix} R(n,θ)= nx2(1−cosθ)+cosθnxny(1−cosθ)+nzsinθnxnz(1−cosθ)−nysinθ0nxny(1−cosθ)−nzsinθny2(1−cosθ)+cosθnynz(1−cosθ)+nxsinθ0nxnz(1−cosθ)+nysinθnynz(1−cosθ)−nxsinθnz2(1−cosθ)+cosθ00001