【现代图形学基础 Games101】2. 3D Transformation

本文详细介绍了3D空间中的几何变换,包括缩放3D(Scale3D)、反射3D(Reflection3D)、剪切3D(Shear3D)、绕轴旋转(Rotate)以及平移3D(Translation)。通过矩阵表示法,展示了这些变换如何影响3D坐标系中的点和向量,同时提供了旋转的Rodrigues公式。这些变换在计算机图形学和虚拟现实等领域中具有广泛应用。
摘要由CSDN通过智能技术生成

3D Transformation

类比 2D 变换:
[ x ′ y ′ z ′ 1 ] = [ a b c t x d e f t y g h i t z 0 0 0 1 ] [ x y z 1 ] \begin{bmatrix} x^{'} \\ y^{'} \\ z^{'} \\ 1 \end{bmatrix} = \Large{ \begin{bmatrix} \textcolor{orange}{a} & \textcolor{orange}{b} & \textcolor{orange}{c} & \textcolor{#0aa}{t_x} \\ \textcolor{orange}{d} & \textcolor{orange}{e} & \textcolor{orange}{f} & \textcolor{#0aa}{t_y} \\ \textcolor{orange}{g} & \textcolor{orange}{h} & \textcolor{orange}{i} & \textcolor{#0aa}{t_z} \\ 0 & 0 & 0 & 1 \end{bmatrix} } \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} xyz1=adg0beh0cfi0txtytz1xyz1
变换后取:
{ ( x ,   y ,   z ,   1 ) i f   p o i n t , ( x ,   y ,   z ,   0 ) i f   v e c t o r . \begin{cases} (x,\ y,\ z,\ 1) & if\ point, \\ \\ (x,\ y,\ z,\ 0) & if\ vector. \end{cases} (x, y, z, 1)(x, y, z, 0)if point,if vector.
下面我们来讨论在三维空间中的变换矩阵。

1. Scale 3D

S ( s x ,   s y ,   s z ) = [ s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 ] \bf{S}(s_x,\ s_y,\ s_z) = \Large{ \begin{bmatrix} \Large{s_x} & \Large{0} & \Large{0} & \Large{0} \\ \Large{0} & \Large{s_y} & \Large{0} & \Large{0} \\ \Large{0} & \Large{0} & \Large{s_z} & \Large{0} \\ 0 & 0 & 0 & 1 \end{bmatrix} } S(sx, sy, sz)=sx0000sy0000sz00001

2. Reflection 3D

绕哪个轴翻转,就在哪个行上将 1 变为 -1,以绕 x 水平翻转为例:
R = [ − 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] \bf{R} = \Large{ \begin{bmatrix} \Large{-1} & \Large{0} & \Large{0} & \Large{0} \\ \Large{0} & \Large{1} & \Large{0} & \Large{0} \\ \Large{0} & \Large{0} & \Large{1} & \Large{0} \\ 0 & 0 & 0 & 1 \end{bmatrix} } R=1000010000100001

3. Shear 3D

定义 a y x 、 h y a_{yx}、h_y ayxhy 分别指以在 y 方向上切变 x 的最大距离和形状在 y 方向上的高度:
S h ( a y x ,   h y ,   ⋯   ) = [ 1 a y x / h y a z x / h z 0 a x y / h x 1 a z y / h z 0 a x z / h x a y z / h y 1 0 0 0 0 1 ] \bf{Sh}(a_{yx},\ h_{y},\ \cdots) = \Large{ \begin{bmatrix} \Large{1} & \Large{a_{yx}/h_{y}} & \Large{a_{zx}/h_{z}} & \Large{0} \\ \Large{a_{xy}/h_{x}} & \Large{1} & \Large{a_{zy}/h_{z}} & \Large{0} \\ \Large{a_{xz}/h_{x}} & \Large{a_{yz}/h_{y}} & \Large{1} & \Large{0} \\ 0 & 0 & 0 & 1 \end{bmatrix} } Sh(ayx, hy, )=1axy/hxaxz/hx0ayx/hy1ayz/hy0azx/hzazy/hz100001
若仅在 y 方向上切变 x:
S h ( a y x ,   h y ) = [ 1 a y x / h y 0 0 0 1 0 0 0 0 1 0 0 0 0 1 ] \bf{Sh}(a_{yx},\ h_{y}) = \Large{ \begin{bmatrix} \Large{1} & \Large{a_{yx}/h_{y}} & \Large{0} & \Large{0} \\ \Large{0} & \Large{1} & \Large{0} & \Large{0} \\ \Large{0} & \Large{0} & \Large{1} & \Large{0} \\ 0 & 0 & 0 & 1 \end{bmatrix} } Sh(ayx, hy)=1000ayx/hy10000100001

4. Rotate

绕轴旋转

desc

绕 x, y, z 轴旋转的变换矩阵:
R x ( θ ) = [ 1 0 0 0 0 cos ⁡ θ − sin ⁡ θ 0 0 sin ⁡ θ cos ⁡ θ 0 0 0 0 1 ] R y ( θ ) = [ cos ⁡ θ 0 sin ⁡ θ 0 0 1 0 0 − sin ⁡ θ 0 cos ⁡ θ 0 0 0 0 1 ] R z ( θ ) = [ cos ⁡ θ − sin ⁡ θ 0 0 sin ⁡ θ cos ⁡ θ 0 0 0 0 1 0 0 0 0 1 ] \begin{array}{l} R_x(\theta) = {\Large \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \textcolor{orange}{\cos\theta} & \textcolor{orange}{-\sin\theta} & 0 \\ 0 & \textcolor{orange}{\sin\theta} & \textcolor{orange}{\cos\theta} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} } \\ \\ R_y(\theta) = {\Large \begin{bmatrix} \textcolor{orange}{\cos\theta} & 0 & \textcolor{orange}{\sin\theta} & 0 \\ 0 & 1 & 0 & 0 \\ \textcolor{orange}{-\sin\theta} & 0 & \textcolor{orange}{\cos\theta} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} } \\ \\ R_z(\theta) = {\Large \begin{bmatrix} \textcolor{orange}{\cos\theta} & \textcolor{orange}{-\sin\theta} & 0 & 0 \\ \textcolor{orange}{\sin\theta} & \textcolor{orange}{\cos\theta} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} } \\ \end{array} Rx(θ)=10000cosθsinθ00sinθcosθ00001Ry(θ)=cosθ0sinθ00100sinθ0cosθ00001Rz(θ)=cosθsinθ00sinθcosθ0000100001

注意旋转变换矩阵的形式,只关注前三个维度的矩阵,并取旋转维度的余子式,那么该余子式将是一个平面旋转变换矩阵。

不过绕 y 轴的旋转变换矩阵稍有不同,这是因为我们定义旋转的正方向是顺着该轴负方向看去的逆时针方向。

对于在 x, z 轴上的旋转变换,根据余子式的形式,前者在 y, z 平面上做旋转操作,后者在 x, y 平面上做旋转操作,如果分别顺着这两个轴的负方向看去,y -> z 和 x -> y 均是逆时针方向,与我们平常所见的二维坐标系没什么不同。

而在 y 轴上的旋转变换就不太一样了,再根据余子式的形式,它在 x, z 平面农商做旋转操作,如果顺着 y 轴负方向看去,将 x, z 轴放在平面上观察,x -> z 将是顺时针方向。

这导致我们的逆时针旋转在这个坐标系看来 —— 不严谨地说 —— 是顺时针。

Rodrigues’ Rotation Formula

绕任意轴的旋转:
R ( n ⃗ ,   α ) = cos ⁡ ( α ) I + [ 1 − cos ⁡ ( α ) ] n n T + sin ⁡ ( α ) [ 0 − n z n y n z 0 − n x − n y n x 0 ] \begin{array}{l} \bf{R}(\vec{n},\ \alpha) = \cos(\alpha)I + [1 - \cos(\alpha)]nn^T + \sin(\alpha) \begin{bmatrix} 0 & -n_z & n_y \\ n_z & 0 & -n_x \\ -n_y & n_x & 0 \end{bmatrix} \end{array} R(n , α)=cos(α)I+[1cos(α)]nnT+sin(α)0nznynz0nxnynx0

5. Translation

T ( t x ,   t y ,   t z ) = [ 1 0 0 t x 0 1 0 t y 0 0 1 t z 0 0 0 1 ] \bf{T}(t_x,\ t_y,\ t_z) = \Large{ \begin{bmatrix} \Large{1} & \Large{0} & \Large{0} & \Large{t_x} \\ \Large{0} & \Large{1} & \Large{0} & \Large{t_y} \\ \Large{0} & \Large{0} & \Large{1} & \Large{t_z} \\ 0 & 0 & 0 & 1 \end{bmatrix} } T(tx, ty, tz)=100001000010txtytz1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高厉害

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值