余弦定理公式
cos(α-β) = cosαcosβ+sinαsinβ
cos(α+β) = cosαcosβ-sinαsinβ
sin(α-β) = sinαcosβ-cosαsinβ
cos(α+β) = sinαcosβ+cosαsinβ
Z轴旋转矩阵证明
因为绕z轴的旋转并不会改变点的z坐标的变化,所以可以把所有绕z轴旋转的点直接放到x-y平面旋转。
假设x-y平面一点p(x,y)绕z轴旋转到p*(x*,y*),如下图所示:
P点与x轴夹角为α度,逆时针旋转β度到P*
设原点O到点P的距离为r
因为是绕Z轴旋转并不会改变点到原点的距离
所以:OP=OP*=r
根据三角形定则可得:
x=rcosα,y=rsinα
x*=rcos(α+β), y*=rsin(α+β)
又由余弦定理可得:
x*=rcosαcosβ-rsinαsinβ
y*=rsinαcosβ+rcosαsinβ
将x,y代入可得:
x*=xcosβ-ysinβ
y*=xsinβ+ycosβ
转换为矩阵可得:
行向量:
[
x
∗
,
y
∗
,
0
]
=
[
x
,
y
,
0
]
⋅
[
c
o
s
β
s
i
n
β
0
−
s
i
n
β
c
o
s
β
0
0
0
1
]
[x^*, y^*, 0] = [x, y, 0]·\begin{bmatrix} cosβ & sinβ & 0 \\ -sinβ & cosβ & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}
[x∗,y∗,0]=[x,y,0]⋅⎣⎡cosβ−sinβ0sinβcosβ0001⎦⎤
列向量:
[
x
∗
y
∗
0
]
=
[
c
o
s
β
s
i
n
β
0
−
s
i
n
β
c
o
s
β
0
0
0
1
]
⋅
[
x
y
0
]
\begin{bmatrix} x^*\\ y^*\\ 0\\ \end{bmatrix} = \begin{bmatrix} cosβ & sinβ & 0 \\ -sinβ & cosβ & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}·\begin{bmatrix} x\\ y\\ 0\\ \end{bmatrix}
⎣⎡x∗y∗0⎦⎤=⎣⎡cosβ−sinβ0sinβcosβ0001⎦⎤⋅⎣⎡xy0⎦⎤
X轴旋转矩阵证明
通过上面绕Z轴的证明,我们证明一下X轴的旋转矩阵
假设有一点P(X,Y,Z,1)绕X轴旋转β度到点P*(X*,Y*,Z*,1)
第一步将P点平移到Y-Z平面
P
y
−
z
=
(
x
,
y
,
z
,
1
)
⋅
[
1
0
0
0
0
1
0
0
0
0
1
0
−
X
0
0
1
]
P_y-z=(x,y,z,1)·\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ -X & 0 & 0 & 1\\ \end{bmatrix}
Py−z=(x,y,z,1)⋅⎣⎢⎢⎡100−X010000100001⎦⎥⎥⎤
由Z轴旋转证明过程同理可得:
Y
∗
=
Z
s
i
n
β
+
Y
c
o
s
β
Y^*=Zsinβ+Ycosβ
Y∗=Zsinβ+Ycosβ
Z
∗
=
Z
c
o
s
β
−
Y
s
i
n
β
Z^*=Zcosβ-Ysinβ
Z∗=Zcosβ−Ysinβ
转换为矩阵如下:
[
0
,
Y
∗
,
Z
∗
,
1
]
=
[
0
,
Y
,
Z
,
1
]
⋅
[
1
0
0
0
0
c
o
s
β
s
i
n
β
0
0
−
s
i
n
β
c
o
s
β
0
0
0
0
1
]
[0,Y^*,Z^*,1]=[0,Y,Z,1]·\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & cosβ & sinβ & 0\\ 0 & -sinβ & cosβ & 0\\ 0 & 0 & 0 & 1\\ \end{bmatrix}
[0,Y∗,Z∗,1]=[0,Y,Z,1]⋅⎣⎢⎢⎡10000cosβ−sinβ00sinβcosβ00001⎦⎥⎥⎤
还原X坐标:
[
X
∗
,
Y
∗
,
Z
∗
,
1
]
=
[
0
,
Y
∗
,
Z
∗
,
1
]
⋅
[
1
0
0
0
0
1
0
0
0
0
1
0
X
0
0
1
]
[X^*,Y^*,Z^*,1]=[0,Y^*,Z^*,1]· \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ X & 0 & 0 & 1\\ \end{bmatrix}
[X∗,Y∗,Z∗,1]=[0,Y∗,Z∗,1]⋅⎣⎢⎢⎡100X010000100001⎦⎥⎥⎤
所以:
[
X
∗
,
Y
∗
,
Z
∗
,
1
]
=
[
X
,
Y
,
Z
,
1
]
⋅
[
1
0
0
0
0
1
0
0
0
0
1
0
−
X
0
0
1
]
⋅
[
1
0
0
0
0
c
o
s
β
s
i
n
β
0
0
−
s
i
n
β
c
o
s
β
0
0
0
0
1
]
⋅
[
1
0
0
0
0
1
0
0
0
0
1
0
X
0
0
1
]
[X^*,Y^*,Z^*,1]=[X, Y, Z,1]· \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ -X & 0 & 0 & 1\\ \end{bmatrix}· \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & cosβ & sinβ & 0\\ 0 & -sinβ & cosβ & 0\\ 0 & 0 & 0 & 1\\ \end{bmatrix}· \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ X & 0 & 0 & 1\\ \end{bmatrix}
[X∗,Y∗,Z∗,1]=[X,Y,Z,1]⋅⎣⎢⎢⎡100−X010000100001⎦⎥⎥⎤⋅⎣⎢⎢⎡10000cosβ−sinβ00sinβcosβ00001⎦⎥⎥⎤⋅⎣⎢⎢⎡100X010000100001⎦⎥⎥⎤
[
X
∗
,
Y
∗
,
Z
∗
,
1
]
=
[
X
,
Y
,
Z
,
1
]
⋅
[
1
0
0
0
0
c
o
s
β
s
i
n
β
0
0
−
s
i
n
β
c
o
s
β
0
0
0
0
1
]
[X^*,Y^*,Z^*,1]= [X, Y, Z,1]·\begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & cosβ & sinβ & 0\\ 0 & -sinβ & cosβ & 0\\ 0 & 0 & 0 & 1\\ \end{bmatrix}
[X∗,Y∗,Z∗,1]=[X,Y,Z,1]⋅⎣⎢⎢⎡10000cosβ−sinβ00sinβcosβ00001⎦⎥⎥⎤