三维仿射变换矩阵

三维仿射变换矩阵

三维仿射变换矩阵有 3 × 4 、 4 × 4 3\times4、4\times4 3×4、4×4两种写法,都是施加到三维点的齐次式上, 4 × 4 4\times4 4×4的仿射变换矩阵是在 3 × 4 3\times4 3×4的矩阵后追加一行 ( 0 , 0 , 0 , 1 ) (0,0,0,1) (0,0,0,1),便于通过连续左乘计算组合变换矩阵,这里只对平移、缩放、旋转三种变换展开分析,剪切、反射这两种变换暂不展开,并且对旋转变换会做比较细致的分析。

平移变换

平移量为 ( a , b , c ) (a,b,c) (a,b,c)的平移变换矩阵是:

1 0 0 a 0 1 0 b 0 0 1 c \] \\begin{bmatrix} 1 \& 0 \& 0 \& a\\\\ 0 \& 1 \& 0 \& b\\\\ 0 \& 0 \& 1 \& c \\end{bmatrix} 100010001abc ## 缩放变换   点 ( x , y , z ) (x,y,z) (x,y,z)变成 ( a x , b y , c z ) (ax,by,cz) (ax,by,cz)的缩放矩阵是 \[ a 0 0 0 0 b 0 0 0 0 c 0 \] \\begin{bmatrix} a \& 0 \& 0 \& 0\\\\ 0 \& b \& 0 \& 0\\\\ 0 \& 0 \& c \& 0 \\end{bmatrix} a000b000c000 ## 旋转变换 ### 绕x、y、z单个轴旋转的变换   三维点绕 x x x轴逆时针旋转 α \\alpha α角的旋转变换矩阵为: R x ( α ) = \[ 1 0 0 0 0 cos ⁡ α − sin ⁡ α 0 0 sin ⁡ α cos ⁡ α 0 0 0 0 1 \] R_x(\\alpha) = \\begin{bmatrix} 1 \& 0 \& 0 \& 0\\\\ 0 \& \\cos\\alpha \& -\\sin\\alpha \& 0\\\\ 0 \& \\sin\\alpha \& \\cos\\alpha \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} Rx(α)= 10000cosαsinα00−sinαcosα00001   三维点绕 y y y轴逆时针旋转 β \\beta β角的旋转变换矩阵为: R y ( β ) = \[ cos ⁡ β 0 sin ⁡ β 0 0 1 0 0 − sin ⁡ β 0 cos ⁡ β 0 0 0 0 1 \] R_y(\\beta) = \\begin{bmatrix} \\cos\\beta \& 0 \& \\sin\\beta \& 0\\\\ 0 \& 1 \& 0 \& 0\\\\ -\\sin\\beta \& 0 \& \\cos\\beta\& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} Ry(β)= cosβ0−sinβ00100sinβ0cosβ00001   三维点绕 z z z轴逆时针旋转 γ \\gamma γ角的旋转变换矩阵为: R z ( γ ) = \[ cos ⁡ γ − sin ⁡ γ 0 0 sin ⁡ γ cos ⁡ γ 0 0 0 0 1 0 0 0 0 1 \] R_z(\\gamma) = \\begin{bmatrix} \\cos\\gamma \& -\\sin\\gamma \& 0 \& 0\\\\ \\sin\\gamma \& \\cos\\gamma \& 0 \& 0\\\\ 0 \& 0 \& 1 \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} Rz(γ)= cosγsinγ00−sinγcosγ0000100001   因此,三维点先绕 x x x轴逆时针旋转 α \\alpha α角,再绕 y y y轴逆时针旋转 β \\beta β角,最后绕 z z z轴逆时针旋转 γ \\gamma γ角的旋转变换矩阵为(**注意顺序重要** ): R z ( γ ) R y ( β ) R x ( α ) = \[ cos ⁡ γ − sin ⁡ γ 0 0 sin ⁡ γ cos ⁡ γ 0 0 0 0 1 0 0 0 0 1 \] \[ cos ⁡ β 0 sin ⁡ β 0 0 1 0 0 − sin ⁡ β 0 cos ⁡ β 0 0 0 0 1 \] \[ 1 0 0 0 0 cos ⁡ α − sin ⁡ α 0 0 sin ⁡ α cos ⁡ α 0 0 0 0 1 \] = \[ cos ⁡ β cos ⁡ γ sin ⁡ α sin ⁡ β cos ⁡ γ − sin ⁡ γ cos ⁡ α sin ⁡ β cos ⁡ α cos ⁡ γ + sin ⁡ α sin ⁡ γ 0 cos ⁡ β sin ⁡ γ sin ⁡ α sin ⁡ β sin ⁡ γ + cos ⁡ α cos ⁡ γ sin ⁡ γ sin ⁡ β cos ⁡ α − sin ⁡ α cos ⁡ γ 0 − sin ⁡ β sin ⁡ α cos ⁡ β cos ⁡ α cos ⁡ β 0 0 0 0 1 \] \\begin{matrix}R_z(\\gamma) R_y(\\beta)R_x(\\alpha) = \\begin{bmatrix} \\cos\\gamma \& -\\sin\\gamma \& 0 \& 0\\\\ \\sin\\gamma \& \\cos\\gamma \& 0 \& 0\\\\ 0 \& 0 \& 1 \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} \\begin{bmatrix} \\cos\\beta \& 0 \& \\sin\\beta \& 0\\\\ 0 \& 1 \& 0 \& 0\\\\ -\\sin\\beta \& 0 \& \\cos\\beta\& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} \\begin{bmatrix} 1 \& 0 \& 0 \& 0\\\\ 0 \& \\cos\\alpha \& -\\sin\\alpha \& 0\\\\ 0 \& \\sin\\alpha \& \\cos\\alpha \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} \\\\ = \\begin{bmatrix} \\cos\\beta\\cos\\gamma \& \\sin\\alpha\\sin\\beta\\cos\\gamma−\\sin\\gamma\\cos\\alpha \& \\sin\\beta\\cos\\alpha\\cos\\gamma+\\sin\\alpha\\sin\\gamma \& 0\\\\ \\cos\\beta\\sin\\gamma \& \\sin\\alpha\\sin\\beta\\sin\\gamma+\\cos\\alpha\\cos\\gamma \& \\sin\\gamma\\sin\\beta\\cos\\alpha−\\sin\\alpha\\cos\\gamma \& 0\\\\ -\\sin\\beta \& \\sin\\alpha\\cos\\beta \& \\cos\\alpha\\cos\\beta \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix}\\end{matrix} Rz(γ)Ry(β)Rx(α)= cosγsinγ00−sinγcosγ0000100001 cosβ0−sinβ00100sinβ0cosβ00001 10000cosαsinα00−sinαcosα00001 = cosβcosγcosβsinγ−sinβ0sinαsinβcosγ−sinγcosαsinαsinβsinγ+cosαcosγsinαcosβ0sinβcosαcosγ+sinαsinγsinγsinβcosα−sinαcosγcosαcosβ00001   详细推导可参考这篇[博客](https://blog.csdn.net/shenquanyue/article/details/103262512) ### 绕任意轴旋转   绕点 ( x 0 , y 0 , z 0 ) (x_0,y_0,z_0) (x0,y0,z0)且单位法向量为 ( a , b , c ) (a,b,c) (a,b,c)的轴旋转的变换矩阵为: \[ cos ⁡ θ + a 2 ( 1 − cos ⁡ θ ) a b ( 1 − cos ⁡ θ ) − c sin ⁡ θ a c ( 1 − cos ⁡ θ ) + b sin ⁡ θ ( ( 1 − a 2 ) x 0 − a ( b y 0 + c z 0 ) ) ( 1 − cos ⁡ θ ) + ( c y 0 − b z 0 ) sin ⁡ θ a b ( 1 − cos ⁡ θ ) + c sin ⁡ θ cos ⁡ θ + b 2 ( 1 − cos ⁡ θ ) b c ( 1 − c o s θ ) − a sin ⁡ θ ( ( 1 − b 2 ) y 0 − b ( a x 0 + c z 0 ) ) ( 1 − cos ⁡ θ ) + ( a z 0 − c x 0 ) sin ⁡ θ a c ( 1 − cos ⁡ θ ) − b sin ⁡ θ b c ( 1 − cos ⁡ θ ) + a sin ⁡ θ cos ⁡ θ + c 2 ( 1 − cos ⁡ θ ) ( ( 1 − c 2 ) z 0 − c ( a x 0 + b y 0 ) ) ( 1 − cos ⁡ θ ) + ( b x 0 − a y 0 ) sin ⁡ θ 0 0 0 1 \] \\begin{bmatrix} \\cos\\theta + a\^2(1-\\cos\\theta) \& ab(1-\\cos\\theta)-c\\sin\\theta \& ac(1-\\cos\\theta)+b\\sin\\theta \& ((1-a\^2)x_0-a(by_0+cz_0))(1-\\cos\\theta)+(cy_0-bz_0)\\sin\\theta \\\\ ab(1-\\cos\\theta)+c\\sin\\theta \& \\cos\\theta+b\^2(1-\\cos\\theta) \& bc(1-cos\\theta)-a\\sin\\theta \& ((1-b\^2)y_0-b(ax_0+cz_0))(1-\\cos\\theta)+(az_0-cx_0)\\sin\\theta \\\\ ac(1-\\cos\\theta)-b\\sin\\theta \& bc(1-\\cos\\theta)+a\\sin\\theta \& \\cos\\theta+c\^2(1-\\cos\\theta) \& ((1-c\^2)z_0-c(ax_0+by_0))(1-\\cos\\theta)+(bx_0-ay_0)\\sin\\theta \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} cosθ+a2(1−cosθ)ab(1−cosθ)+csinθac(1−cosθ)−bsinθ0ab(1−cosθ)−csinθcosθ+b2(1−cosθ)bc(1−cosθ)+asinθ0ac(1−cosθ)+bsinθbc(1−cosθ)−asinθcosθ+c2(1−cosθ)0((1−a2)x0−a(by0+cz0))(1−cosθ)+(cy0−bz0)sinθ((1−b2)y0−b(ax0+cz0))(1−cosθ)+(az0−cx0)sinθ((1−c2)z0−c(ax0+by0))(1−cosθ)+(bx0−ay0)sinθ1   特别地,绕原点且单位法向量为 ( a , b , c ) (a,b,c) (a,b,c)的轴旋转的变换矩阵为: \[ cos ⁡ θ + a 2 ( 1 − cos ⁡ θ ) a b ( 1 − cos ⁡ θ ) − c sin ⁡ θ a c ( 1 − cos ⁡ θ ) + b sin ⁡ θ 0 a b ( 1 − cos ⁡ θ ) + c sin ⁡ θ cos ⁡ θ + b 2 ( 1 − cos ⁡ θ ) b c ( 1 − c o s θ ) − a sin ⁡ θ 0 a c ( 1 − cos ⁡ θ ) − b sin ⁡ θ b c ( 1 − cos ⁡ θ ) + a sin ⁡ θ cos ⁡ θ + c 2 ( 1 − cos ⁡ θ ) 0 0 0 0 1 \] \\begin{bmatrix} \\cos\\theta + a\^2(1-\\cos\\theta) \& ab(1-\\cos\\theta)-c\\sin\\theta \& ac(1-\\cos\\theta)+b\\sin\\theta \& 0 \\\\ ab(1-\\cos\\theta)+c\\sin\\theta \& \\cos\\theta+b\^2(1-\\cos\\theta) \& bc(1-cos\\theta)-a\\sin\\theta \& 0 \\\\ ac(1-\\cos\\theta)-b\\sin\\theta \& bc(1-\\cos\\theta)+a\\sin\\theta \& \\cos\\theta+c\^2(1-\\cos\\theta) \& 0 \\\\ 0 \& 0 \& 0 \& 1 \\end{bmatrix} cosθ+a2(1−cosθ)ab(1−cosθ)+csinθac(1−cosθ)−bsinθ0ab(1−cosθ)−csinθcosθ+b2(1−cosθ)bc(1−cosθ)+asinθ0ac(1−cosθ)+bsinθbc(1−cosθ)−asinθcosθ+c2(1−cosθ)00001   详细推导可参考这篇[博客](https://blog.csdn.net/u013407012/article/details/103721902)

相关推荐
Akiiiira13 小时前
【日撸 Java 三百行】Day 7(Java的数组与矩阵元素相加)
线性代数·矩阵
HHONGQI12321 小时前
LVGL- 按钮矩阵控件
矩阵·lvlgl
元亓亓亓2 天前
LeetCode热题100--54.螺旋矩阵--中等
算法·leetcode·矩阵
小羊在奋斗2 天前
【今日三题】ISBN号码(模拟) / kotori和迷宫(BFS最短路) / 矩阵最长递增路径(dfs)
矩阵·深度优先·宽度优先
18538162800余--2 天前
短视频矩阵系统批量剪辑模式开发详解,支持OEM
线性代数·ui·矩阵·音视频·概率论
HappyAcmen2 天前
线代第二章矩阵第五、六、七节矩阵的转置、方阵的行列式、方阵的伴随矩阵
笔记·学习·线性代数·矩阵
Mi Manchi262 天前
力扣热题100之搜索二维矩阵 II
python·leetcode·矩阵
18538162800余--3 天前
矩阵系统源码搭建 UI 设计开发指南,支持OEM
线性代数·ui·矩阵
元亓亓亓3 天前
LeetCode热题100--73.矩阵置零--中等
算法·leetcode·矩阵
豆沙沙包?3 天前
2025年- H17-Lc125-73.矩阵置零(矩阵)---java版
java·线性代数·矩阵