此次讨论的是二维/三维/笛卡尔坐标系下的旋转和平移。且以下分析均是右手坐标系下。
1 要明确坐标系
只提旋转,而不提在哪个坐标系下都是耍流氓。旋转和平移都是相对某个坐标系而言,不能抛开坐标系谈数值,这也是为什么会存在内旋(静态坐标系),外旋(动态坐标系)矩阵相乘顺序不同,
Example:
如上图所示, C 0 C_0 C0-> C 1 C_1 C1和 C 0 C_0 C0-> C 2 C_2 C2的变换矩阵分别为 R 1 , R 2 R_1,R_2 R1,R2(这里先不考虑平移),这两个旋转矩阵均是相对于 C 0 C_0 C0坐标系而言的,那么如果要求 C 1 C_1 C1到 C 2 C_2 C2坐标系的旋转 △ R \triangle R △R,
如果上述
△
R
\triangle R
△R是对于
C
1
C_1
C1坐标系而言的:
△
R
∗
R
1
=
R
2
⇔
△
R
=
R
2
∗
R
1
−
1
\triangle R*R_1=R_2 \Leftrightarrow \triangle R=R_2*R_1^{-1}
△R∗R1=R2⇔△R=R2∗R1−1
如果是在
C
0
C_0
C0坐标系的变换:
R
1
∗
△
R
=
R
2
⇔
△
R
=
R
1
−
1
∗
R
2
R_1*\triangle R=R_2 \Leftrightarrow \triangle R=R_1^{-1}*R_2
R1∗△R=R2⇔△R=R1−1∗R2
2 先平移还是先旋转
先后顺序对应转换矩阵是有影响的,后一步操作都是在前一步操作产生的新坐标系下进行的;
-
先平移再旋转:
X ⃗ n e w = R ( X ⃗ o l d − t ) \vec{X}_{new}=R(\vec{X}_{old}-t) Xnew=R(Xold−t)
那么新坐标系原点在旧坐标系下的坐标即为 t t t -
先旋转再平移:
X ⃗ n e w = R X ⃗ o l d + t \vec{X}_{new}=R\vec{X}_{old}+t Xnew=RXold+t
那么旧坐标系原点在新坐标系下的坐标为 − t -t −t.
3 旋转坐标系还是旋转坐标系中的向量
坐标系的旋转和向量的旋转转过的角度大小和旋转方向相同的情况下,坐标系绕原点旋转的旋转矩阵与向量(坐标)绕原点旋转的旋转矩阵互为转置。
3.1旋转坐标系
如上图所示是坐标系旋转(
X
O
Y
XOY
XOY坐标系绕
Z
Z
Z轴转动了
θ
\theta
θ 角度变成了
X
′
O
Y
′
X'OY'
X′OY′),那么
P
P
P点在新坐标系下的坐标为:
x
2
=
x
1
∗
c
o
s
(
θ
)
+
y
1
∗
s
i
n
(
θ
)
y
2
=
y
1
∗
c
o
s
(
θ
)
−
x
1
∗
s
i
n
(
θ
)
x_2=x_1*cos(\theta)+y_1*sin(\theta) \\y_2=y_1*cos(\theta)-x_1*sin(\theta)
x2=x1∗cos(θ)+y1∗sin(θ)y2=y1∗cos(θ)−x1∗sin(θ)
有
[
x
2
y
2
]
=
[
c
o
s
(
θ
)
s
i
n
(
θ
)
−
s
i
n
(
θ
)
c
o
s
(
θ
)
]
∗
[
x
1
y
1
]
\left[ \begin{matrix} x_2\\y_2 \end{matrix} \right]= \left[ \begin{matrix} cos(\theta)&sin(\theta)\\-sin(\theta)&cos(\theta) \end{matrix} \right]* \left[ \begin{matrix} x_1\\y_1 \end{matrix} \right]
[x2y2]=[cos(θ)−sin(θ)sin(θ)cos(θ)]∗[x1y1]
那么旋转矩阵即为
R
=
[
c
o
s
(
θ
)
s
i
n
(
θ
)
−
s
i
n
(
θ
)
c
o
s
(
θ
)
]
R=\left[ \begin{matrix} cos(\theta)&sin(\theta)\\-sin(\theta)&cos(\theta) \end{matrix} \right]
R=[cos(θ)−sin(θ)sin(θ)cos(θ)]
3.2 旋转的是向量
可以从上图中直观的看出旋转矩阵和坐标系旋转互为转置(正交矩阵也是互逆),不信的话,一种推导方式如下:
假设
P
⃗
1
\vec{P}_1
P1角度为
α
\alpha
α, 转角为
θ
\theta
θ ,那么
P
⃗
2
\vec{P}_2
P2的夹角为
(
α
+
θ
)
(\alpha+\theta)
(α+θ), 在复数域下的坐标分别为:
P
⃗
1
=
[
c
o
s
(
α
)
s
i
n
(
α
)
]
,
P
⃗
2
=
[
c
o
s
(
α
+
θ
)
s
i
n
(
α
+
θ
)
]
\vec{P}_1=\left[ \begin{matrix} cos(\alpha)\\sin(\alpha) \end{matrix} \right], \vec{P}_2=\left[ \begin{matrix} cos(\alpha+\theta)\\sin(\alpha+\theta) \end{matrix} \right]
P1=[cos(α)sin(α)],P2=[cos(α+θ)sin(α+θ)]
由三角函数和差公式可得:
P
⃗
2
=
[
c
o
s
(
α
+
θ
)
s
i
n
(
α
+
θ
)
]
=
[
c
o
s
(
θ
)
−
s
i
n
(
θ
)
s
i
n
(
θ
)
c
o
s
(
θ
)
]
∗
P
⃗
1
\vec{P}_2=\left[ \begin{matrix} cos(\alpha+\theta)\\sin(\alpha+\theta) \end{matrix} \right]= \left[ \begin{matrix} cos(\theta)&-sin(\theta)\\sin(\theta)&cos(\theta) \end{matrix} \right]*\vec{P}_1
P2=[cos(α+θ)sin(α+θ)]=[cos(θ)sin(θ)−sin(θ)cos(θ)]∗P1
那么旋转矩阵为
R
=
[
c
o
s
(
θ
)
−
s
i
n
(
θ
)
s
i
n
(
θ
)
c
o
s
(
θ
)
]
R=\left[\begin{matrix}cos(\theta)&-sin(\theta)\\sin(\theta)&cos(\theta)\end{matrix}\right]
R=[cos(θ)sin(θ)−sin(θ)cos(θ)]
得证。