第六章 图形变换
- 掌握矢量、矩阵以及它们的运算
- 掌握二维平移变换、放缩变换、旋转变换、错切变换及对称变换
- 了解变换的两种模式:固定坐标系模式与活动坐标系模式
- 掌握坐标系的概念:世界坐标系、用户坐标系、设备(屏幕)坐标系与局部坐标系
- 掌握什么是裁剪窗口与视区以及它们各自的作用
- 掌握齐次坐标的概念,二维(三维)变换在齐次坐标下的表示
- 了解二维图形的显示过程,掌握窗口到视区的变换
- 掌握三维平移变换、放缩变换、旋转变换
- 掌握坐标系之间的变换
矢量、矩阵以及它们的运算
数学基础不做介绍
二维基本变换
平移变换
点 P(x,y)
在 x 轴方向, y 轴方向分别平移距离 tx,ty
,得到点 P’(x’,y’)
, 有
[
x
′
y
′
]
=
[
x
y
]
+
[
Δ
x
Δ
y
]
\begin{bmatrix} x' \\ y' \end{bmatrix}= \begin{bmatrix} x \\ y \end{bmatrix}+ \begin{bmatrix} \Delta x \\ \Delta y \end{bmatrix}
[x′y′]=[xy]+[ΔxΔy]
旋转变换
点 P
绕坐标原点旋转角度 θ
(逆时针为正,顺时针为负),得到 P’(x’,y’)
, 有
[
x
′
y
′
]
=
[
c
o
s
θ
−
s
i
n
θ
s
i
n
θ
c
o
s
θ
]
⋅
[
x
y
]
\begin{bmatrix} x' \\ y' \end{bmatrix}= \begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta \end{bmatrix} \cdot \begin{bmatrix} x \\ y \end{bmatrix}
[x′y′]=[cosθsinθ−sinθcosθ]⋅[xy]
缩放变换
点 P
在 x,y
方向分别放缩 sx
和 sy
倍,得到点 P’(x’,y’)
, 有
[
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} \cdot \begin{bmatrix} x \\ y \end{bmatrix}
[x′y′]=[sx00sy]⋅[xy]
齐次坐标与二维变换的矩阵表示
经常要对图形对象做连续多个变换,希望这些多个变换可以合成为一个大的复合变换
-
旋转和缩放变换都是矩阵乘法,根据结合律,可以复合
- 例如:一个先旋转再缩放的复合
P’’=S·P’=S·(R·P)=(S·R)·P=A·P, 其中A=S·R
-
平移变换不能复合
齐次坐标
- 使各种转换的表示形式一致,使变换合成更加容易
齐次坐标定义
- 点
(x,y)
对应的齐次坐标为( x h , y h , h ) , 其中 x h = h x , y h = h y , h ≠ 0 (x_h,\ y_h,\ h), \text{其中 }x_h=hx,y_h=hy, h\neq 0 (xh, yh, h),其中 xh=hx,yh=hy,h=0
点
(x,y)
对应的齐次坐标为三维空间的一条直线为使运算简单,引入标准齐次坐标
(x,y,1)
二维齐次坐标变换的矩阵形式
[
a
b
c
d
e
f
g
h
i
]
\begin{bmatrix} a&b&c \\ d&e&f \\ g&h&i \end{bmatrix}
adgbehcfi
每一个元素都有其对应含义
a,b,d,e
可以对图形做 缩放 \ 旋转 \ 对称 \ 错切 等变换c,f
可以对图形做 平移 变换g,h
可以对图形做 投影 变换i
可以对图形整体做缩放变换
平移变换
[
x
′
y
′
1
]
=
[
1
0
t
x
0
1
t
y
0
0
1
]
⋅
[
x
y
1
]
=
T
(
t
x
,
t
y
)
[
x
y
1
]
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & t_x\\ 0 & 1 & t_y \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =T(t_x,t_y) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
x′y′1
=
100010txty1
⋅
xy1
=T(tx,ty)
xy1
旋转变换
[
x
′
y
′
1
]
=
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
⋅
[
x
y
1
]
=
R
(
θ
)
[
x
y
1
]
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =R(\theta) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
x′y′1
=
cosθsinθ0−sinθcosθ0001
⋅
xy1
=R(θ)
xy1
缩放变换
[
x
′
y
′
1
]
=
[
s
x
0
0
0
s
y
0
0
0
1
]
⋅
[
x
y
1
]
=
S
(
s
x
,
s
y
)
[
x
y
1
]
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} s_x & 0 & 0\\ 0 & s_y & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =S(s_x,s_y) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
x′y′1
=
sx000sy0001
⋅
xy1
=S(sx,sy)
xy1
对称变换
关于 x
轴的对称变换
[
x
′
y
′
1
]
=
[
−
1
0
0
0
1
0
0
0
1
]
⋅
[
x
y
1
]
=
S
Y
x
[
x
y
1
]
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} -1 & 0 & 0\\ 0 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SY_x \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
x′y′1
=
−100010001
⋅
xy1
=SYx
xy1
关于 y
轴的对称变换
[
x
′
y
′
1
]
=
[
1
0
0
0
−
1
0
0
0
1
]
⋅
[
x
y
1
]
=
S
Y
y
[
x
y
1
]
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0\\ 0 & -1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SY_y \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}
x′y′1
=
1000−10001
⋅
xy1
=SYy
xy1
错切变换
错切变换(Shear Transformation)是一种线性变换,它将物体沿某个方向“倾斜”,而不改变该方向上的尺寸
-
可以发生在
x
轴方向、y
轴方向,或者同时在两个方向上进行 -
错切变换的特点是图形会发生形状的倾斜,但不会改变图形的面积和直线的平行性
以
y
轴为依赖轴 ( 方向轴 ) 的错切变换, 即
{ x ′ = x + s h x ⋅ y y ′ = y \begin{cases} x'=x+sh_x \cdot y\\ y'=y \end{cases} {x′=x+shx⋅yy′=y
因为y = 0
上的点位置不变, 因此称y=0
为参考轴
[ x ′ y ′ 1 ] = [ 1 s h x 0 0 1 0 0 0 1 ] ⋅ [ x y 1 ] = S H ( s h x ) [ x y 1 ] , s h x = tan ( α ) \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & sh_x & 0\\ 0 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SH(sh_x) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, sh_x=\tan (\alpha) x′y′1 = 100shx10001 ⋅ xy1 =SH(shx) xy1 ,shx=tan(α)
以y = yref
为参考轴的错切变换
{ x ′ = x + s h x ⋅ ( y − y r e f ) y ′ = y \begin{cases} x'=x+sh_x \cdot (y-y_{ref})\\ y'=y \end{cases} {x′=x+shx⋅(y−yref)y′=y[ x ′ y ′ 1 ] = [ 1 s h x − s h x ⋅ y r e f 0 1 0 0 0 1 ] ⋅ [ x y 1 ] = S H ( s h x ) [ x y 1 ] , s h x = tan ( α ) \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & sh_x & -sh_x \cdot y_{ref}\\ 0 & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SH(sh_x) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, sh_x=\tan (\alpha) x′y′1 = 100shx10−shx⋅yref01 ⋅ xy1 =SH(shx) xy1 ,shx=tan(α)
以
x
轴为依赖轴 ( 方向轴 ) 的错切变换, 即
{ x ′ = x y ′ = y + s h y ⋅ x \begin{cases} x'=x\\ y'=y+sh_y \cdot x \end{cases} {x′=xy′=y+shy⋅x
[ x ′ y ′ 1 ] = [ 1 0 0 s h y 1 0 0 0 1 ] ⋅ [ x y 1 ] = S H ( s h y ) [ x y 1 ] , s h y = tan ( β ) \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0\\ sh_y & 1 & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SH(sh_y) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, sh_y=\tan (\beta) x′y′1 = 1shy0010001 ⋅ xy1 =SH(shy) xy1 ,shy=tan(β)
以x = xref
为参考轴的错切变换
{ x ′ = x y ′ = y + s h y ⋅ ( x − x r e f ) \begin{cases} x'=x\\ y'=y+sh_y \cdot (x-x_{ref}) \end{cases} {x′=xy′=y+shy⋅(x−xref)[ x ′ y ′ 1 ] = [ 1 0 0 s h y 1 − s h y ⋅ x r e f 0 0 1 ] ⋅ [ x y 1 ] = S H ( s h x ) [ x y 1 ] , s h x = tan ( α ) \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0\\ sh_y & 1 & -sh_y \cdot x_{ref} \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} =SH(sh_x) \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}, sh_x=\tan (\alpha) x′y′1 = 1shy00100−shy⋅xref1 ⋅ xy1 =SH(shx) xy1 ,shx=tan(α)
复合操作
复合平移相当于多次平移 相加
复合缩放相当于多次缩放 相乘
复合旋转相当于多次旋转 角度相加
当进行连续的几何操作时,需要将对应的变换矩阵按从右向左顺序相乘
- 操作顺序会影响最终结果, 因为矩阵乘法不可交换
关于任意参照点 P(xr,yr)
的旋转变换, 缩放变换
旋转变换
先平移 (-xr,-yr)
, 再旋转角 θ
, 最后平移 (xr,yr)
, 即变换矩阵
M
(
x
r
,
y
r
;
θ
)
=
T
(
−
x
r
,
−
y
r
)
⋅
R
(
θ
)
⋅
T
(
x
r
,
y
r
)
=
[
1
0
x
r
0
1
y
r
0
0
1
]
⋅
[
c
o
s
θ
−
s
i
n
θ
0
s
i
n
θ
c
o
s
θ
0
0
0
1
]
⋅
[
1
0
−
x
r
0
1
−
y
r
0
0
1
]
=
[
c
o
s
θ
−
s
i
n
θ
x
r
(
1
−
c
o
s
θ
)
+
y
r
s
i
n
θ
s
i
n
θ
c
o
s
θ
y
r
(
1
−
c
o
s
θ
)
−
x
r
s
i
n
θ
0
0
1
]
M(x_r,y_r;\theta)=T(-x_r,-y_r) \cdot R(\theta) \cdot T(x_r,y_r) \\= \begin{bmatrix}1 & 0 & x_r \\ 0 & 1 & y_r \\ 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot \begin{bmatrix}1 & 0 & -x_r \\ 0 & 1 & -y_r \\ 0 & 0 & 1 \end{bmatrix} \\= \begin{bmatrix} cos\theta & -sin\theta & x_r(1-cos\theta)+y_rsin\theta \\ sin\theta & cos\theta & y_r(1-cos\theta)-x_rsin\theta \\ 0 & 0 & 1\end{bmatrix}
M(xr,yr;θ)=T(−xr,−yr)⋅R(θ)⋅T(xr,yr)=
100010xryr1
⋅
cosθsinθ0−sinθcosθ0001
⋅
100010−xr−yr1
=
cosθsinθ0−sinθcosθ0xr(1−cosθ)+yrsinθyr(1−cosθ)−xrsinθ1
同理, 缩放变换
先平移 (-xr,-yr)
, 再缩放 (sx,sy)
倍, 最后平移 (xr,yr)
, 即变换矩阵
M ( x r , y r ; s x , s y ) = T ( − x r , − y r ) ⋅ S ( s x , s y ) ⋅ T ( x r , y r ) = [ 1 0 x r 0 1 y r 0 0 1 ] ⋅ [ s x 0 0 0 s y 0 0 0 1 ] ⋅ [ 1 0 − x r 0 1 − y r 0 0 1 ] = [ s x 0 x r ( 1 − s x ) 0 s y y r ( 1 − s y ) 0 0 1 ] M(x_r,y_r;s_x,s_y)=T(-x_r,-y_r) \cdot S(s_x,s_y) \cdot T(x_r,y_r)\\=\begin{bmatrix}1 & 0 & x_r \\ 0 & 1 & y_r \\ 0 & 0 & 1 \end{bmatrix} \cdot\begin{bmatrix} s_x & 0 & 0\\ 0 & s_y & 0 \\ 0 & 0 & 1\end{bmatrix} \cdot\begin{bmatrix}1 & 0 & -x_r \\ 0 & 1 & -y_r \\ 0 & 0 & 1 \end{bmatrix}=\begin{bmatrix} s_x & 0 & x_r(1-s_x)\\ 0 & s_y & y_r(1-s_y)\\ 0 & 0 & 1\end{bmatrix} M(xr,yr;sx,sy)=T(−xr,−yr)⋅S(sx,sy)⋅T(xr,yr)= 100010xryr1 ⋅ sx000sy0001 ⋅ 100010−xr−yr1 = sx000sy0xr(1−sx)yr(1−sy)1
关于任意轴 (直线 L
) 的对称变换
- 平移使
L
过坐标原点 (T1)- 旋转
θ
使L
与横坐标重合 (R1)- 求关于
x
轴的对称图形 (SY)- 旋转
-θ
(R2)- 平移使
L
回到原先位置 (T2)θ旋转=−tan−1(k)即总变换
M = T 2 ⋅ R 2 ⋅ S Y x ⋅ R 1 ⋅ T 1 = T ( 0 , − b ) ⋅ R ( − θ ) ⋅ S Y x ⋅ R ( θ ) ⋅ T ( 0 , b ) , L : y = k x + b , θ = tan − 1 ( k ) M=T_2 \cdot R_2 \cdot SY_x \cdot R_1 \cdot T_1= T(0,-b) \cdot R(-\theta) \cdot SY_x \cdot R(\theta) \cdot T(0,b) \\, L: y=kx+b,\theta = \tan^{-1}(k) M=T2⋅R2⋅SYx⋅R1⋅T1=T(0,−b)⋅R(−θ)⋅SYx⋅R(θ)⋅T(0,b),L:y=kx+b,θ=tan−1(k)
仿射变换
变换前后,能保持平行直线的关系
{ x ′ = a x + b y + e y ′ = c y + d x + f \begin{cases} x'=ax+by+e\\ y'=cy+dx+f \end{cases} {x′=ax+by+ey′=cy+dx+f
变换矩阵为
A f = [ a b e c d f 0 0 1 ] A_f= \begin{bmatrix} a&b&e\\c&d&f\\0&0&1 \end{bmatrix} Af= ac0bd0ef1
固定坐标系模式和活动坐标系模式
之前讲的都是基于固定坐标系模式下的变换, 还有一种活动坐标系模式下的变换
- 在固定坐标系模式下,每个变换都是相对于固定的全局坐标系(即世界坐标系)进行的
- 变换的顺序非常重要,后面的操作不会影响前面操作的坐标系
- 在活动坐标系模式下,每次变换都会基于图形自身的坐标系进行
- 每次操作完成后,图形的坐标系随之变化,后续操作都是在新坐标系下进行的
以以下操作顺序为为例
- 平移 (1, 1)
- 缩放 2 倍
- 旋转 90 度
- 平移 (5, 4)
- 在固定坐标系模式下,变换矩阵按照顺序从右向左相乘:
M 固 = T 2 ⋅ R ⋅ S ⋅ T 1 M_固 = T_2 \cdot R \cdot S \cdot T_1 M固=T2⋅R⋅S⋅T1
- 在活动坐标系模式下,矩阵相乘的顺序是从左到右:
M 活 = T 1 ⋅ S ⋅ R ⋅ T 2 M_活 = T_1 \cdot S \cdot R \cdot T_2 M活=T1⋅S⋅R⋅T2
二维图形的显示流程
三种坐标系
- 世界坐标系
- 相对于物体所在的整个空间
- 局部坐标系
- 相对于物体
- 屏幕坐标系 (设备坐标系)
- 在显示区域绘制图形的坐标系
- 坐标轴方向可能根据不同的设备而不同
窗口与视区
- 窗口
- 在世界坐标系中指定的一个矩形区域来指定需要显示的图形
- 视区
- 在设备坐标系中指定的矩形区域, 来指定窗口内的图形在屏幕上显示的大小及位置
- 窗口到视区的变换
- 窗口与视区在不同坐标系, 物体坐标必须进行变换后才能在视区显示
设世界坐标系中窗口左下角
(xmin,ymin)
,两边长Ex,Ey
设设备坐标系中视区左下角
(umin,vmin)
,两边长Eu,Ev
变换步骤:
- 世界坐标系中平移使
(xmin,ymin)
至原点- 旋转使窗口边与坐标重合
- 若窗口边与视区边平行, 则旋转角
α = 0
- 放缩使窗口大小与视区相等
- 设备坐标系中平移窗口与视图重合
变换矩阵为
M w v = T ( u m i n , v m i n ) ⋅ S ( E u E x , E v E y ) ⋅ R ( − α ) ⋅ T ( − x m i n , − y m i n ) M_{wv}=T(u_{min},v_{min}) \cdot S(\frac {E_u} {E_x},\frac {E_v} {E_y}) \cdot R(-\alpha) \cdot T(-x_{min},-y_{min}) Mwv=T(umin,vmin)⋅S(ExEu,EyEv)⋅R(−α)⋅T(−xmin,−ymin)
三维几何变换
一下内容均基于右手坐标系
三维齐次坐标
点 (x,y,z)
对应的齐次坐标为
(
x
h
,
y
h
,
z
h
,
h
)
,
其中
x
h
=
h
x
,
y
h
=
h
y
,
z
h
=
h
z
,
h
≠
0
(x_h,y_h,z_h,h), \text{其中 }x_h=hx,y_h=hy,z_h=hz,h\neq 0
(xh,yh,zh,h),其中 xh=hx,yh=hy,zh=hz,h=0
标准齐次坐标 (x,y,z,1)
平移变换
[
x
′
y
′
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
(
t
x
,
t
y
,
t
z
)
[
x
y
z
1
]
\begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =T(t_x,t_y,t_z) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}
x′y′z′1
=
100001000010txtytz1
⋅
xyz1
=T(tx,ty,tz)
xyz1
旋转变换
旋转变换分为
- 绕
x
轴
[ 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 ] = R x ( θ ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & cos\theta & -sin\theta & 0 \\ 0 & sin\theta & cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =R_x(\theta) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = 10000cosθsinθ00−sinθcosθ00001 ⋅ xyz1 =Rx(θ) xyz1
- 绕
y
轴
[ x ′ y ′ z ′ 1 ] = [ c o s θ 0 − s i n θ 0 0 1 0 0 s i n θ 0 c o s θ 0 0 0 0 1 ] ⋅ [ x y z 1 ] = R y ( θ ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} cos\theta & 0 & -sin\theta & 0 \\ 0 & 1 & 0 & 0 \\ sin\theta & 0 & cos\theta & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =R_y(\theta) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = cosθ0sinθ00100−sinθ0cosθ00001 ⋅ xyz1 =Ry(θ) xyz1
- 绕
z
轴
[ x ′ y ′ z ′ 1 ] = [ c o s θ − s i n θ 0 0 s i n θ c o s θ 0 0 0 0 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] = R z ( θ ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} cos\theta & -sin\theta & 0 & 0 \\ sin\theta & cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =R_z(\theta) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = cosθsinθ00−sinθcosθ0000100001 ⋅ xyz1 =Rz(θ) xyz1
缩放变换
[
x
′
y
′
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
(
s
x
,
s
y
,
s
z
)
[
x
y
z
1
]
\begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =S(s_x,s_y,s_z) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}
x′y′z′1
=
sx0000sy0000sz00001
⋅
xyz1
=S(sx,sy,sz)
xyz1
错切变换
错切按照依赖轴不同可以分为以下:
x
轴为依赖轴
[ x ′ y ′ z ′ 1 ] = [ 1 0 0 0 s h y 1 0 0 s h z 0 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] = S H x ( s h y , s h z ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & 0 & 0 \\ sh_y & 1 & 0 & 0 \\ sh_z & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =SH_x(sh_y,sh_z) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = 1shyshz0010000100001 ⋅ xyz1 =SHx(shy,shz) xyz1
y
轴为依赖轴
[ x ′ y ′ z ′ 1 ] = [ 1 s h x 0 0 0 1 0 0 0 s h z 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] = S H y ( s h x , s h z ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & sh_x & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & sh_z & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =SH_y(sh_x,sh_z) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = 1000shx1shz000100001 ⋅ xyz1 =SHy(shx,shz) xyz1
z
轴为依赖轴
[ x ′ y ′ z ′ 1 ] = [ 1 0 s h x 0 0 1 s h y 0 0 0 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] = S H z ( s h x , s h y ) [ x y z 1 ] \begin{bmatrix} x' \\ y' \\ z' \\ 1 \end{bmatrix}= \begin{bmatrix} 1 & 0 & sh_x & 0 \\ 0 & 1 & sh_y & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} =SH_z(sh_x,sh_y) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} x′y′z′1 = 10000100shxshy100001 ⋅ xyz1 =SHz(shx,shy) xyz1
对称变换
分别关于 x
轴对称, y
轴对称, z
轴对称
S
Y
y
z
=
[
−
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
]
,
S
Y
x
z
=
[
1
0
0
0
0
−
1
0
0
0
0
1
0
0
0
0
1
]
,
S
Y
x
y
=
[
1
0
0
0
0
1
0
0
0
0
−
1
0
0
0
0
1
]
SY_{yz}=\begin{bmatrix} -1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}, SY_{xz}=\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & -1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}, SY_{xy}=\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & -1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}
SYyz=
−1000010000100001
,SYxz=
10000−10000100001
,SYxy=
1000010000−100001
关于绕空间任意轴的旋转
设旋转轴
AB
由任意一点A(xa,ya,za)
及其方向向量(a,b,c)
定义空间一点
P(xp,yp,zp)
绕AB
轴旋转到P’(xp’,yp’,zp’)
,转角为θ
旋转步骤
- 将
A
点移到坐标原点- 使
AB
分别绕x
轴、y
轴旋转适当角度与z
轴重合- 将点
P
绕z
轴旋转θ
角- 作上述变换的逆操作,使
AB
回到原来位置变换矩阵
R A B ( θ ) = T ( x a , y a , z a ) ⋅ R x ( − α ) ⋅ R y ( − β ) ⋅ R ( θ ) ⋅ R y ( β ) ⋅ R x ( α ) ⋅ T ( − x a , − y a , − z a ) , 其中 α = tan − 1 ( b c ) , β = tan − 1 ( a b 2 + c 2 ) R_{AB}(\theta)=T(x_a,y_a,z_a) \cdot R_x(-\alpha) \cdot R_y(-\beta) \cdot R(\theta) \cdot R_y(\beta) \cdot R_x(\alpha) \cdot T(-x_a,-y_a,-z_a) \\ ,其中\ \alpha=\tan^{-1}(\frac{b}{c}),\beta=\tan^{-1}(\frac{a}{\sqrt{b^2+c^2}}) RAB(θ)=T(xa,ya,za)⋅Rx(−α)⋅Ry(−β)⋅R(θ)⋅Ry(β)⋅Rx(α)⋅T(−xa,−ya,−za),其中 α=tan−1(cb),β=tan−1(b2+c2a)
坐标系之间的变换
设有两个坐标系:
OXYZ
和O’UVN
- 点
O’
在OXYZ
中的坐标为(Ox,Oy,Oz)
- 单位向量
O’U,O‘V,O’N
在OXYZ
中分别为(Ux,Uy,Uz)
,(Vx,Vy,Vz)
,(Nx,Ny,Nz)
- 现要将坐标系
OXYZ
中的图形变换到坐标系O‘UVN
中去,记变换为Mxyz→uvn
- 将坐标系平移对齐, 再由线性代数知识可以求得这两个坐标系之间的正交变换即可
M xyz → uvn = R ⋅ T ( − O x , − O y , − O z ) , R = [ u x u y u z 0 v x v y v z 0 w x w y w z 0 0 0 0 1 ] M_{\text{xyz} \to \text{uvn}} = R \cdot T(-Ox, -Oy, -Oz),\ R=\begin{bmatrix} u_x & u_y & u_z & 0 \\ v_x & v_y & v_z & 0 \\ w_x & w_y & w_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} Mxyz→uvn=R⋅T(−Ox,−Oy,−Oz), R= uxvxwx0uyvywy0uzvzwz00001
- 或使用变换合成先平移后旋转对齐