1. 三维坐标系变换
同二维坐标系变换类似,这里直接给出结论
1.1 平移变换
- T 表示平移变换矩阵,
(
t
x
,
t
y
,
t
z
)
(tx,ty,tz)
(tx,ty,tz)为平移分量。
[ x ′ y ′ z ′ 1 ] = [ x + t x y + t y z + t z 1 ] = [ 1 0 0 t x 0 1 0 t y 0 0 1 t z 0 0 0 1 ] [ x y z 1 ] = T ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{c} x+t x \\ y+t y \\ z+t z \\ 1 \end{array}\right]=\left[\begin{array}{cccc} 1 & 0 & 0 & t x \\ 0 & 1 & 0 & t y \\ 0 & 0 & 1 & t z \\ 0 & 0 & 0 & 1 \end{array}\right]\left[\begin{array}{c} x \\ y \\ z \\ 1 \end{array}\right] = T\cdot P x′y′z′1 = x+txy+tyz+tz1 = 100001000010txtytz1 xyz1 =T⋅P
1.2 缩放变换
- T 表示缩放变换矩阵,
(
s
x
,
s
y
,
s
z
)
(sx,sy,sz)
(sx,sy,sz)为缩放系数分量。
[ x ′ y ′ z ′ 1 ] = [ x ⋅ s x y ⋅ s y z ⋅ s z 1 ] = [ s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 ] [ x y z 1 ] = S ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{c} x \cdot s x \\ y \cdot s y \\ z \cdot s z \\ 1 \end{array}\right]=\left[\begin{array}{cccc} s x & 0 & 0 & 0 \\ 0 & s y & 0 & 0 \\ 0 & 0 & s z & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]\left[\begin{array}{c} x \\ y \\ z \\ 1 \end{array}\right] = S \cdot P x′y′z′1 = x⋅sxy⋅syz⋅sz1 = sx0000sy0000sz00001 xyz1 =S⋅P
1.3 旋转变换(旋转方向以右手系为标准)
(1)绕x轴旋转
θ
\theta
θ
[
x
′
y
′
z
′
1
]
=
[
x
y
cos
θ
−
z
sin
θ
y
sin
θ
+
z
cos
θ
1
]
=
[
1
0
0
0
0
cos
θ
−
sin
θ
0
0
sin
θ
cos
θ
0
0
0
0
1
]
[
x
y
z
1
]
=
R
x
⋅
P
\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{c} x \\ y \cos \theta-z \sin \theta \\ y \sin \theta+z \cos \theta \\ 1 \end{array}\right]=\left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta & 0 \\ 0 & \sin \theta & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] =R_x \cdot P
x′y′z′1
=
xycosθ−zsinθysinθ+zcosθ1
=
10000cosθsinθ00−sinθcosθ00001
xyz1
=Rx⋅P
(2)绕y轴旋转
θ
\theta
θ
[
x
′
y
′
z
′
1
]
=
[
z
sin
θ
+
x
cos
θ
y
z
cos
θ
−
x
sin
θ
1
]
=
[
cos
θ
0
sin
θ
0
0
1
0
0
−
sin
θ
0
cos
θ
0
0
0
0
1
]
[
x
y
z
1
]
=
R
y
⋅
P
\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{c} z \sin \theta+x \cos \theta \\ y \\ z \cos \theta-x \sin \theta \\ 1 \end{array}\right]=\left[\begin{array}{cccc} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ -\sin \theta & 0 & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] =R_y \cdot P
x′y′z′1
=
zsinθ+xcosθyzcosθ−xsinθ1
=
cosθ0−sinθ00100sinθ0cosθ00001
xyz1
=Ry⋅P
(3)绕z轴旋转
θ
\theta
θ
[
x
′
y
′
z
′
1
]
=
[
x
cos
θ
−
y
sin
θ
x
sin
θ
+
y
sin
θ
z
1
]
=
[
cos
θ
−
sin
θ
0
0
−
sin
θ
cos
θ
0
0
0
0
1
0
0
0
0
1
]
[
x
y
z
1
]
=
R
z
⋅
P
\left[ \begin{array}{l} {{x}^{\prime }} \\ {{y}^{\prime }} \\ {{z}^{\prime }} \\ 1 \\ \end{array} \right]=\left[ \begin{array}{c} x\cos \theta -y\sin \theta \\ x\sin \theta +y\sin \theta \\ z \\ 1 \\ \end{array} \right]=\left[ \begin{array}{cccc} \cos \theta & -\sin \theta & 0 & 0 \\ -\sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{array} \right]\left[ \begin{array}{l} x \\ y \\ z \\ 1 \\ \end{array}\right]=R_z \cdot P
x′y′z′1
=
xcosθ−ysinθxsinθ+ysinθz1
=
cosθ−sinθ00−sinθcosθ0000100001
xyz1
=Rz⋅P
(4)
P
(
x
,
y
,
z
)
P(x,y,z)
P(x,y,z)绕空间任意轴线
l
1
:
n
l_1:n
l1:n 旋转
θ
\theta
θ得到
P
′
(
x
′
,
y
′
,
z
′
)
P'(x',y',z')
P′(x′,y′,z′)。
思路
- (a)先将直线 l 1 l_1 l1上一点 P 1 P_1 P1移动至原点,同时移动P点。
- (b,c)然后分别绕x轴、y轴旋转使得A、B方向与z轴重合。
- (d)最后让P点绕z轴旋转 θ \theta θ。
- (e)做(b)(a)步骤的逆变换。得到最后的结果
P
′
(
x
′
,
y
′
,
z
′
)
P'(x',y',z')
P′(x′,y′,z′)。
变换矩阵
(a)设 P 0 ( x 0 , y 0 , z 0 ) P_0(x_0,y_0,z_0) P0(x0,y0,z0)是直线 l 1 : 方向数 n → = ( A , B , C ) l_1:方向数\overrightarrow{n}=(A,B,C) l1:方向数n=(A,B,C)上一点,将其平移至坐标原点,平移矩阵为:
T 1 = [ 1 0 0 − x 0 0 1 0 − y 0 0 0 1 − z 0 0 0 0 1 ] T_1=\left[ \begin{array}{} 1 & 0 & 0 & -x_0\\ 0 & 1 & 0 & -y_0\\ 0 & 0 & 1 & -z_0\\ 0 & 0 & 0 & 1\\ \end{array}\right] T1= 100001000010−x0−y0−z01
(b) 绕x轴旋转,使得直线 l 1 l_1 l1在 x O y xOy xOy平面上,旋转角为 l 1 l_1 l1在 y O z yOz yOz平面上的投影与z轴的夹角 β , c o s β = C B 2 + C 2 , s i n β = B B 2 + C 2 \beta, cos\beta=\frac{C}{ \sqrt{{{\text{B}}^{2}}+{{C}^{2}}}},sin\beta=\frac{B}{ \sqrt{{{\text{B}}^{2}}+{{C}^{2}}}} β,cosβ=B2+C2C,sinβ=B2+C2B。旋转矩阵为:
T 2 = [ 1 0 0 − x 0 0 c o s β − s i n β 0 0 s i n β c o s β 0 0 0 0 1 ] T_2=\left[ \begin{array}{} 1 & 0 & 0 & -x_0\\ 0 & cos\beta & -sin\beta & 0\\ 0 & sin\beta & cos\beta & 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] T2= 10000cosβsinβ00−sinβcosβ0−x0001
(c) 绕y轴旋转,使得直线 l 1 l_1 l1与z轴重合,旋转角为 l 1 l_1 l1与z轴的夹角 γ , c o s γ = B 2 + C 2 A 2 + B 2 + C 2 , s i n γ = − A A 2 + B 2 + C 2 \gamma , cos\gamma =\frac{\sqrt{B^{2}+C^{2}}}{ \sqrt{A^{2}+B^{2}+C^{2}}},sin\gamma =-\frac{A}{ \sqrt{A^{2}+B^{2}+C^{2}}} γ,cosγ=A2+B2+C2B2+C2,sinγ=−A2+B2+C2A。旋转矩阵为:
T 3 = [ c o s γ 0 s i n γ 0 0 1 0 0 − s i n γ 0 c o s γ 0 0 0 0 1 ] T_3=\left[ \begin{array}{} cos\gamma & 0 & sin\gamma & 0\\ 0 & 1 & 0 & 0\\ -sin\gamma & 0 & cos\gamma & 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] T3= cosγ0−sinγ00100sinγ0cosγ00001
(d) P点绕直线(即z轴旋转 θ \theta θ),旋转矩阵为:
T 4 = [ c o s θ c o s θ 0 0 s i n θ c o s β 0 0 0 0 1 0 0 0 0 1 ] T_4=\left[ \begin{array}{} cos\theta & cos\theta & 0 & 0\\ sin\theta & cos\beta & 0 & 0\\ 0 & 0 & 1& 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] T4= cosθsinθ00cosθcosβ0000100001
(e)依次做(c),(b),(a)的逆变换,分别记为 T 5 , T 6 , T 7 T_5,T_6,T_7 T5,T6,T7,所以总的变换矩阵为: T = T 7 ⋅ T 6 ⋅ T 5 ⋅ T 4 ⋅ T 3 ⋅ T 2 ⋅ T 1 T=T_7 \cdot T_6\cdot T_5\cdot T_4\cdot T_3\cdot T_2\cdot T_1 T=T7⋅T6⋅T5⋅T4⋅T3⋅T2⋅T1。
1.4 对称变换
- 关于
x
O
y
xOy
xOy平面对称变换矩阵,x,y不变,z变为相反数:
T x O y = [ 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] T_{xOy} = \left[ \begin{array}{} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & -1& 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] TxOy= 1000010000−100001 - 同理可写出关于
x
O
z
,
z
O
y
xOz,zOy
xOz,zOy的变换矩阵:
T x O z = [ 1 0 0 0 0 − 1 0 0 0 0 1 0 0 0 0 1 ] , T z O y = [ − 1 0 0 0 0 1 0 0 0 0 − 1 0 0 0 0 1 ] T_{xOz} = \left[ \begin{array}{} 1 & 0 & 0 & 0\\ 0 & -1 & 0 & 0\\ 0 & 0 & 1& 0\\ 0 & 0 & 0 & 1\\ \end{array}\right],T_{zOy} = \left[ \begin{array}{} -1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & -1& 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] TxOz= 10000−10000100001 ,TzOy= −1000010000−100001
2. 三维坐标系之间的转换
- 将原坐标系 x y z xyz xyz下的坐标 ( x , y , z ) (x,y,z) (x,y,z)转换为新坐标系 u v n uvn uvn下的坐标 ( x ′ , y ′ , z ′ ) (x',y',z') (x′,y′,z′)。
- 坐标系变换矩阵的R与rotation R 互为 inverse matrix.
思路:1.平移坐标系原点和新坐标系的原点重合 2.利用单位坐标向量构造坐标旋转矩阵。
(1)平移:
T = [ 1 0 0 − u 0 0 1 0 − v 0 0 0 1 − n 0 0 0 0 1 ] T = \left[ \begin{array}{} 1 & 0 & 0 & -u_0\\ 0 & 1 & 0 & -v_0\\ 0 & 0 & 1& -n_0\\ 0 & 0 & 0 & 1\\ \end{array}\right] T= 100001000010−u0−v0−n01
(2) 坐标旋转矩阵( ( u x , u y , u z ) (u_x,u_y,u_z) (ux,uy,uz) is a norm vector for the global CSYS.)
R = [ u x u y u z 0 v x v y v z 0 n x n y n z 0 0 0 0 1 ] R = \left[ \begin{array}{} u_x & u_y & u_z & 0\\ v_x & v_y & v_z & 0\\ n_x & n_y & n_z & 0\\ 0 & 0 & 0 & 1\\ \end{array}\right] R= uxvxnx0uyvyny0uzvznz00001 - 所以坐标变换公式为:
[ u ′ v ′ n ′ 1 ] = R ⋅ T ⋅ [ x y z 1 ] \left[ \begin{array}{} u' \\ v' \\ n' \\ 1\\ \end{array}\right]=R\cdot T\cdot \left[ \begin{array}{} x \\ y \\ z \\ 1\\ \end{array}\right] u′v′n′1 =R⋅T⋅ xyz1
R ⋅ T = [ u x u y u z u x ( − u 0 ) + u y ( − v 0 ) + u z ( − n 0 ) v x v y v z v x ( − u 0 ) + v y ( − v 0 ) + v z ( − n 0 ) n x n y n z n x ( − u 0 ) + n y ( − v 0 ) + n z ( − n 0 ) 0 0 0 1 ] R\cdot T= \left[ \begin{array}{} u_x & u_y & u_z & u_{x} (-u_0)+ u_{y} (-v_0) + u_{z} (-n_0)\\ v_x & v_y & v_z & v_{x} (-u_0)+ v_{y} (-v_0) + v_{z} (-n_0)\\ n_x & n_y & n_z & n_{x} (-u_0)+ n_{y} (-v_0) + n_{z} (-n_0)\\ 0 & 0 & 0 & 1\\ \end{array}\right] R⋅T= uxvxnx0uyvyny0uzvznz0ux(−u0)+uy(−v0)+uz(−n0)vx(−u0)+vy(−v0)+vz(−n0)nx(−u0)+ny(−v0)+nz(−n0)1