banner
IWSR

IWSR

美少女爱好者,我永远喜欢芳泽瑾。另外 P5 天下第一!

三维图形基本几何变换的矩阵推导

前言#

This article is a derivative of Homogeneous Coordinates and Matrix Derivation of Basic Geometric Transformations in 2D Graphics. Understanding 2D transformations makes it easy to derive 3D transformations.

Basic Geometric Transformations in 3D Graphics#

Translation#

Describes the transformation from point (x, y, z) to (x + dx, y + dy, z + dz).

Introducing homogeneous coordinates, it can be expressed as (x, y, z, 1) and transformed to (x + dx, y + dy, z + dz, 1).

Given:

(a11a12a13a14a21a22a23a24a31a32a33a34a41a42a43a44)(xyz1)=(x+dxy+dyz+dz1)\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} x + d_x \\ y + d_y \\ z + d_z \\ 1 \end{pmatrix}

We have:

{a11x+a12y+a13z+a14=x+dxa21x+a22y+a23z+a24=y+dya31x+a32y+a33z+a34=z+dza41x+a42y+a43z+a44=1\begin{cases} a_{11}x + a_{12}y + a_{13}z + a_{14} = x + d_x \\ a_{21}x + a_{22}y + a_{23}z + a_{24} = y + d_y \\ a_{31}x + a_{32}y + a_{33}z + a_{34} = z + d_z \\ a_{41}x + a_{42}y + a_{43}z + a_{44} = 1 \\ \end{cases}

Solving for:

(100dx010dy001dz0001)\begin{pmatrix} 1 & 0 & 0 & dx \\ 0 & 1 & 0 & dy \\ 0 & 0 & 1 & dz \\ 0 & 0 & 0 & 1 \end{pmatrix}

Scaling#

Describes the transformation from point (x, y, z) to (sx * x, sy * y, sz * z), where sx, sy, sz are constants.

Introducing homogeneous coordinates, it can be expressed as (x, y, z, 1) and transformed to (sx * x, sy * y, sz * z, 1).

Given:

(a11a12a13a14a21a22a23a24a31a32a33a34a41a42a43a44)(xyz1)=(sxxsyyszz1)\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} s_x * x \\ s_y * y \\ s_z * z \\ 1 \end{pmatrix}

We have:

{a11x+a12y+a13z+a14=sxxa21x+a22y+a23z+a24=syya31x+a32y+a33z+a34=szza41x+a42y+a43z+a44=1\begin{cases} a_{11}x + a_{12}y + a_{13}z + a_{14} = s_x * x \\ a_{21}x + a_{22}y + a_{23}z + a_{24} = s_y * y \\ a_{31}x + a_{32}y + a_{33}z + a_{34} = s_z * z \\ a_{41}x + a_{42}y + a_{43}z + a_{44} = 1 \\ \end{cases}

Solving for:

(sx0000sy0000sz00001)\begin{pmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Rotation#

For 3D rotation, it can be decomposed into the product of three matrices (rotation around the x-axis, rotation around the y-axis, rotation around the z-axis).

Rotation around the z-axis —— Rz(β)#

Do you remember the derivation of 2D rotation? When we rotate on the plane formed by the x and y axes, it can also be viewed as rotation around the z-axis. So the 3D rotation is easy to understand, it's just adding an additional dimension that remains fixed.

That is:

(a11a12a13a14a21a22a23a24a31a32a33a34a41a42a43a44)(xyz1)=(xcosβysinβycosβ+xsinβz1)\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} xcosβ - ysinβ \\ ycosβ + xsinβ \\ z \\ 1 \end{pmatrix}

We have:

{a11x+a12y+a13z+a14=xcosβysinβa21x+a22y+a23z+a24=ycosβ+xsinβa31x+a32y+a33z+a34=za41x+a42y+a43z+a44=1\begin{cases} a_{11}x + a_{12}y + a_{13}z + a_{14} = xcosβ - ysinβ \\ a_{21}x + a_{22}y + a_{23}z + a_{24} = ycosβ + xsinβ \\ a_{31}x + a_{32}y + a_{33}z + a_{34} = z \\ a_{41}x + a_{42}y + a_{43}z + a_{44} = 1 \\ \end{cases}

Solving for:

Rzβ=(cosβsinβ00sinβcosβ0000100001)R_{z}β = \begin{pmatrix} cosβ & -sinβ & 0 & 0 \\ sinβ & cosβ & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Rotation around the x-axis —— Rx(α)#

Similarly (keeping x fixed):

Rxα=(10000cosαsinα00sinαcosα00001)R_{x}α = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & cosα & -sinα & 0 \\ 0 & sinα & cosα & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Rotation around the y-axis —— Ry(γ)#

Similarly (keeping y fixed):

Ryγ=(cosγ0sinγ00100sinγ0cosγ00001)R_{y}γ = \begin{pmatrix} cosγ & 0 & sinγ & 0 \\ 0 & 1 & 0 & 0 \\ -sinγ & 0 & cosγ & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

So we have the rotation matrix in 3D:

R=RxαRyγRzβR = R_{x}αR_{y}γR_{z}β

But you may wonder how to decompose the rotation around an axis θ into α, β, γ? Let's leave this question for another article.

However, currently the rotation axes are limited to passing through the origin. If the rotation axis does not pass through the origin, we need to first move the axis to the origin, then rotate, and finally move it back to its original position. Any complex transformation can be decomposed into the composition of several simple transformations.

Shearing#

Shearing along the X-axis#

Describes the transformation from (x, y, z) to (x + m * y + n * z, y, z), where m and n are tangent functions.

(a11a12a13a14a21a22a23a24a31a32a33a34a41a42a43a44)(xyz1)=(x+my+nzyz1)\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix} = \begin{pmatrix} x + m * y + n * z \\ y \\ z \\ 1 \end{pmatrix}

Solving for:

(1mn0010000100001)\begin{pmatrix} 1 & m & n & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

Shearing along the Y-axis#

Describes the transformation from (x, y, z) to (x, y + m * x + n * z, z).

Skipping the solution, I believe you can understand the meaning of the row and column terms.

(1000m1n000100001)\begin{pmatrix} 1 & 0 & 0 & 0 \\ m & 1 & n & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}

Shearing along the Z-axis#

Describes the transformation from (x, y, z) to (x, y, z + m * x + n * y).

(10000100mn100001)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ m & n & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。