Differences between 2D and 3D transformations
文章目录
1. Translation
1.1 2D Translation

-
Translation distances: t x t_{x} tx and t y t_{y} ty .
-
Original coordinate position: ( x , y ) (x,y) (x,y) .
-
New coordinate position: ( x ′ , y ′ ) (x',y') (x′,y′) .
-
x ′ = x + t x , y ′ = y + t y x'=x+t_{x}, \quad\quad y'=y+t_{y} x′=x+tx,y′=y+ty .
-
Translation vector: ( t x , t y ) (t_{x}, t_{y}) (tx,ty) .
-
Translation matrix:
-
P = [ x y ] , P ′ = [ x ′ y ′ ] , T = [ t x t y ] P ′ = P + T \mathbf{P}=\left[\begin{array}{l} x \\ y \end{array}\right], \quad \mathbf{P}^{\prime}=\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \end{array}\right], \quad \mathbf{T}=\left[\begin{array}{l} t_x \\ t_y \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{P}+\mathbf{T} P=[xy],P′=[x′y′],T=[txty]P′=P+T
-
2D translation transformation equations:
-
[ x ′ y ′ 1 ] = [ 1 0 t x 0 1 t y 0 0 1 ] ⋅ [ x y 1 ] P ′ = T ( t x , t y ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{lll} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{T}\left(t_x, t_y\right) \cdot \mathbf{P} ⎣⎡x′y′1⎦⎤=⎣⎡100010txty1⎦⎤⋅⎣⎡xy1⎦⎤P′=T(tx,ty)⋅P
1.2 3D Translation

-
Translation distances: t x , t y , t z t_{x}, \quad t_{y}, \quad t_{z} tx,ty,tz .
-
Original coordinate position: ( x , y , z ) (x,y,z) (x,y,z) .
-
New coordinate position: ( x ′ , y ′ , z ′ ) (x',y',z') (x′,y′,z′) .
-
x ′ = x + t x , y ′ = y + t y , z ′ = z + t z x'=x+t_{x}, \quad\quad y'=y+t_{y}, \quad\quad z'=z+t_{z} x′=x+tx,y′=y+ty,z′=z+tz .
-
Translation vector: ( t x , t y , t z ) (t_{x}, t_{y}, t_{z}) (tx,ty,tz) .
-
3D translation transformation equations:
-
[ 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 ] P ′ = T ⋅ P \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 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] \cdot\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{T} \cdot \mathbf{P} ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡100001000010txtytz1⎦⎥⎥⎤⋅⎣⎢⎢⎡xyz1⎦⎥⎥⎤P′=T⋅P
2. Rotation
2.1 2D Rotation

-
Rotation point: ( x r , y r ) (x_{r}, y_{r}) (xr,yr) .
-
When the rotation point is the coordinate origin:
-
Rotate a point at position ( x , y ) (x,y) (x,y) through an angle θ \theta θ about the origin:
-
x ′ = x cos θ − y sin θ y ′ = x sin θ + y cos θ \begin{aligned} &x^{\prime}=x \cos \theta-y \sin \theta \\ &y^{\prime}=x \sin \theta+y \cos \theta \end{aligned} x′=xcosθ−ysinθy′=xsinθ+ycosθ
-
Rotation matrix:
-
R = [ cos θ − sin θ sin θ cos θ ] P ′ = R ⋅ P \mathbf{R}=\left[\begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R} \cdot \mathbf{P} R=[cosθsinθ−sinθcosθ]P′=R⋅P
-
-
When the rotation point is not the coordinate origin:
-
Rotate a point from position ( x , y ) (x, y) (x,y) to position ( x ′ , y ′ ) \left(x^{\prime}, y^{\prime}\right) (x′,y′) through an angle θ \theta θ about rotation point ( x r , y r ) \left(x_r, y_r\right) (xr,yr):
-
x ′ = x r + ( x − x r ) cos θ − ( y − y r ) sin θ y ′ = y r + ( x − x r ) sin θ + ( y − y r ) cos θ \begin{aligned} &x^{\prime}=x_r+\left(x-x_r\right) \cos \theta-\left(y-y_r\right) \sin \theta \\ &y^{\prime}=y_r+\left(x-x_r\right) \sin \theta+\left(y-y_r\right) \cos \theta \end{aligned} x′=xr+(x−xr)cosθ−(y−yr)sinθy′=yr+(x−xr)sinθ+(y−yr)cosθ
-
-
2D rotation transformation equations:
-
[ x ′ y ′ 1 ] = [ cos θ − sin θ 0 sin θ cos θ 0 0 0 1 ] ⋅ [ x y 1 ] P ′ = R ( θ ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{ccc} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R}(\theta) \cdot \mathbf{P} ⎣⎡x′y′1⎦⎤=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤⋅⎣⎡xy1⎦⎤P′=R(θ)⋅P
2.2 3D Rotation

-
Rotation axis: x − a x i s , y − a x i s , z − a x i s x-axis, \quad y-axis, \quad z-axis x−axis,y−axis,z−axis .
-
If the rotation axis is z − a x i s z-axis z−axis:
-
x ′ = x cos θ − y sin θ y ′ = x sin θ + y cos θ z ′ = z \begin{aligned} &x^{\prime}=x \cos \theta-y \sin \theta \\ &y^{\prime}=x \sin \theta+y \cos \theta \\ &z^{\prime}=z \end{aligned} x′=xcosθ−ysinθy′=xsinθ+ycosθz′=z
-
3D rotation transformation equations:
-
[ x ′ y ′ z ′ 1 ] = [ cos θ − sin θ 0 0 sin θ cos θ 0 0 0 0 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] P ′ = R z ( θ ) ⋅ P \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 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] \cdot\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R}_z(\theta) \cdot \mathbf{P} ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡cosθsinθ00−sinθcosθ0000100001⎦⎥⎥⎤⋅⎣⎢⎢⎡xyz1⎦⎥⎥⎤P′=Rz(θ)⋅P
-
-
3D rotation transformation equations about an axis that is parallel to the x − a x i s x-axis x−axis .
- P ′ = T − 1 ⋅ R x ( θ ) ⋅ T ⋅ P R ( θ ) = T − 1 ⋅ R x ( θ ) ⋅ T \mathbf{P}^{\prime}=\mathbf{T}^{-1} \cdot \mathbf{R}_x(\theta) \cdot \mathbf{T} \cdot \mathbf{P} \\\\ \mathbf{R}(\theta)=\mathbf{T}^{-1} \cdot \mathbf{R}_x(\theta) \cdot \mathbf{T} P′=T−1⋅Rx(θ)⋅T⋅PR(θ)=T−1⋅Rx(θ)⋅T
-
3D rotation transformation equations about an axis that is not parallel to any axes:
-
V = P 2 − P 1 = ( x 2 − x 1 , y 2 − y 1 , z 2 − z 1 ) \begin{aligned} \mathbf{V} &=\mathbf{P}_2-\mathbf{P}_1 \\ &=\left(x_2-x_1, y_2-y_1, z_2-z_1\right) \end{aligned} V=P2−P1=(x2−x1,y2−y1,z2−z1)
-
u = V ∣ V ∣ = ( a , b , c ) \mathbf{u}=\frac{\mathbf{V}}{|\mathbf{V}|}=(a, b, c) u=∣V∣V=(a,b,c)
-
a = x 2 − x 1 ∣ V ∣ , b = y 2 − y 1 ∣ V ∣ , c = z 2 − z 1 ∣ V ∣ a=\frac{x_2-x_1}{|\mathbf{V}|}, \quad b=\frac{y_2-y_1}{|\mathbf{V}|}, \quad c=\frac{z_2-z_1}{|\mathbf{V}|} a=∣V∣x2−x1,b=∣V∣y2−y1,c=∣V∣z2−z1
-
If the direction is P 1 → P 2 \mathbf{P_1} \rightarrow \mathbf{P_2} P1→P2 , move P 1 \mathbf{P_1} P1 to the origin.
-
T = [ 1 0 0 − x 1 0 1 0 − y 1 0 0 1 − z 1 0 0 0 1 ] \mathbf{T}=\left[\begin{array}{cccc} 1 & 0 & 0 & -x_1 \\ 0 & 1 & 0 & -y_1 \\ 0 & 0 & 1 & -z_1 \\ 0 & 0 & 0 & 1 \end{array}\right] T=⎣⎢⎢⎡100001000010−x1−y1−z11⎦⎥⎥⎤
-
Rotate the vector about the x − a x i s x-axis x−axis and into the x z xz xz plane:
-
R x ( α ) = [ 1 0 0 0 0 c d − b d 0 0 b d c d 0 0 0 0 1 ] \mathbf{R}_x(\alpha)=\left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & \frac{c}{d} & -\frac{b}{d} & 0 \\ 0 & \frac{b}{d} & \frac{c}{d} & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] Rx(α)=⎣⎢⎢⎡10000dcdb00−dbdc00001⎦⎥⎥⎤
-
Then, rotate the vector about the y − a x i s y-axis y−axis and into the z − a x i s z-axis z−axis:
-
R y ( β ) = [ d 0 − a 0 0 1 0 0 a 0 d 0 0 0 0 1 ] \mathbf{R}_y(\beta)=\left[\begin{array}{cccc} d & 0 & -a & 0 \\ 0 & 1 & 0 & 0 \\ a & 0 & d & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] Ry(β)=⎣⎢⎢⎡d0a00100−a0d00001⎦⎥⎥⎤
-
Finally, rotate the vector as the specified rotation angle θ \theta θ about the z − a x i s z-axis z−axis:
-
R z ( θ ) = [ cos θ − sin θ 0 0 sin θ cos θ 0 0 0 0 1 0 0 0 0 1 ] \mathbf{R}_z(\theta)=\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] Rz(θ)=⎣⎢⎢⎡cosθsinθ00−sinθcosθ0000100001⎦⎥⎥⎤
-
The composition of these transformations:
-
R ( θ ) = T − 1 ⋅ R x − 1 ( α ) ⋅ R y − 1 ( β ) ⋅ R z ( θ ) ⋅ R y ( β ) ⋅ R x ( α ) ⋅ T \mathbf{R}(\theta)=\mathbf{T}^{-1} \cdot \mathbf{R}_x^{-1}(\alpha) \cdot \mathbf{R}_y^{-1}(\beta) \cdot \mathbf{R}_z(\theta) \cdot \mathbf{R}_y(\beta) \cdot \mathbf{R}_x(\alpha) \cdot \mathbf{T} R(θ)=T−1⋅Rx−1(α)⋅Ry−1(β)⋅Rz(θ)⋅Ry(β)⋅Rx(α)⋅T
-
3. Scaling
3.1 2D Scaling

-
Scaling factors: S x , S y S_x, \quad S_y Sx,Sy .
-
Object positions: ( x , y ) (x, y) (x,y) .
-
Transformed coordinates: ( x ′ , y ′ ) (x', y') (x′,y′) .
-
If the fixed point is the coordinate origin:
-
x ′ = x ⋅ s x , y ′ = y ⋅ s y x^{\prime}=x \cdot s_x, \quad y^{\prime}=y \cdot s_y x′=x⋅sx,y′=y⋅sy .
-
Scaling matrix:
-
[ x ′ y ′ ] = [ s x 0 0 s y ] ⋅ [ x y ] P ′ = S ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \end{array}\right]=\left[\begin{array}{cc} s_x & 0 \\ 0 & s_y \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{S} \cdot \mathbf{P} [x′y′]=[sx00sy]⋅[xy]P′=S⋅P
-
-
if the fixed point is ( x f , y f ) (x_f,y_f) (xf,yf) :
-
for ( x , y ) (x,y) (x,y) , the scaled coordinates ( x ′ , y ′ ) (x',y') (x′,y′) are:
-
x ′ − x f = ( x − x f ) s x , y ′ − y f = ( y − y f ) s y x^{\prime}-x_f=\left(x-x_f\right) s_x, \quad y^{\prime}-y_f=\left(y-y_f\right) s_y x′−xf=(x−xf)sx,y′−yf=(y−yf)sy
-
x ′ = x ⋅ s x + x f ( 1 − s x ) y ′ = y ⋅ s y + y f ( 1 − s y ) \begin{aligned} &x^{\prime}=x \cdot s_x+x_f\left(1-s_x\right) \\ &y^{\prime}=y \cdot s_y+y_f\left(1-s_y\right) \end{aligned} x′=x⋅sx+xf(1−sx)y′=y⋅sy+yf(1−sy)
-
-
2D scaling transformation equations:
-
[ x ′ y ′ 1 ] = [ s x 0 0 0 s y 0 0 0 1 ] ⋅ [ x y 1 ] P ′ = S ( s x , s y ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{ccc} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{S}\left(s_x, s_y\right) \cdot \mathbf{P} ⎣⎡x′y′1⎦⎤=⎣⎡sx000sy0001⎦⎤⋅⎣⎡xy1⎦⎤P′=S(sx,sy)⋅P
3.2 3D Scaling

-
Scaling factors: s x , s y , s z s_x, \quad s_y, \quad s_z sx,sy,sz .
-
Object positions: ( x , y , z ) (x, y,z) (x,y,z) .
-
Transformed coordinates: ( x ′ , y ′ , z ′ ) (x', y',z') (x′,y′,z′) .
-
If the fixed point is the coordinate origin:
- x ′ = x ⋅ s x , y ′ = y ⋅ s y , z ′ = z ⋅ s z x^{\prime}=x \cdot s_x, \quad y^{\prime}=y \cdot s_y, \quad z^{\prime}=z \cdot s_z x′=x⋅sx,y′=y⋅sy,z′=z⋅sz
-
3D scaling transformation equations:
-
[ 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 ] \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 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] \cdot\left[\begin{array}{c} x \\ y \\ z \\ 1 \end{array}\right] ⎣⎢⎢⎡x′y′z′1⎦⎥⎥⎤=⎣⎢⎢⎡sx0000sy0000sz00001⎦⎥⎥⎤⋅⎣⎢⎢⎡xyz1⎦⎥⎥⎤
-
Construct a scaling transformation with respect to any fixed position ( x f , y f , z f ) (x_f,y_f,z_f) (xf,yf,zf) :
-
T ( x f , y f , z f ) ⋅ S ( s x , s y , s z ) ⋅ T ( − x f , − y f , − z f ) = [ s x 0 0 ( 1 − s x ) x f 0 s y 0 ( 1 − s y ) y f 0 0 s z ( 1 − s z ) z f 0 0 0 1 ] \mathbf{T}\left(x_f, y_f, z_f\right) \cdot \mathbf{S}\left(s_x, s_y, s_z\right) \cdot \mathbf{T}\left(-x_f,-y_f,-z_f\right)=\left[\begin{array}{cccc} s_x & 0 & 0 & \left(1-s_x\right) x_f \\ 0 & s_y & 0 & \left(1-s_y\right) y_f \\ 0 & 0 & s_z & \left(1-s_z\right) z_f \\ 0 & 0 & 0 & 1 \end{array}\right] T(xf,yf,zf)⋅S(sx,sy,sz)⋅T(−xf,−yf,−zf)=⎣⎢⎢⎡sx0000sy0000sz0(1−sx)xf(1−sy)yf(1−sz)zf1⎦⎥⎥⎤
本文详细介绍了2D和3D空间中的基本几何变换,包括平移、旋转和缩放。对于2D平移,通过(x', y')坐标表示平移向量(tx, ty),3D平移则增加了tz轴的平移距离。2D旋转围绕原点或任意点进行,涉及旋转角度和旋转中心;3D旋转则涉及到绕x、y、z轴的旋转。至于缩放,2D和3D中都区分了固定点为原点和平移点的情况,分别给出了相应的变换矩阵和公式。这些变换在图形学、计算机视觉和游戏开发等领域有广泛应用。
1037

被折叠的 条评论
为什么被折叠?



