es

https://math.mit.edu/~gs/linearalgebra/ila5/linearalgebra5_10-6.pdf

Computer Graphics

Computer graphics deals with images, stationary or that are moved around. Their scale is changed. Three dimensions are projected onto two dimensions. All the main operations are done by matrices—but the shape of these matrices is surprising. In Computer Graphics, matrices are used to represent many different types of data. Games that involve 2D or 3D graphics rely on some matrix operations to display the game environment and characters in game.

The transformations of three-dimensional space are done with 4-by-4 matrices. You would expect 3-by-3. The reason for the change is that one (translation) of the six key operations cannot be done with a 3-by-3 matrix multiplication. Here are the six operations:

  • Translation (shift the origin to another point P₀(x₀, y₀, z₀)).
  • Rescaling (by c in all directions or by different factors c₁, c₂, c₃).
  • Shearing (in different directions).
  • Rotation (around an axis through the origin or an axis through P₀).
  • Reflection (with respect to some hyperplane).
  • Projection onto a plane through the origin or a plane through P₀).

Translation

Translation is the easiest—just add (x₀, y₀, z₀) to every point. But this is not linear! No 3×3 matrix can move the origin. So we change the coordinates of the origin to (0, 0, 0, 1). This is why the matrices are 4-by-4. The “homogeneous coordinates” of the point (x, y, z) are (x, y, z, 1) and we now show how they work.

Translation shifts the whole three-dimensional space along the vector v₀. The origin moves to ((x₀, y₀, z₀). This vector v₀ is added to every point v in ℝ³. Using homogeneous coordinates, the 4-by-4 matrix T shifts the whole space by v₀:

\[ {\bf T} = \begin{bmatrix} 1&0&0&x_0 \\ 0&1&0&y_0 \\ 0&0&1&z_0 \\ 0&0&0&1 \end{bmatrix} = \begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&1&0 \\ x_0 & y_0 & z_0 & 1 \end{pmatrix}^{\mathrm T} . \]
Since Computer Graphics works with row vectors, but most mathematical subjets use column vectors, we try to please both parties (almost impossible task). Therefore, we utilize different notations for matrices as operators. If a matrix acts from left on column vectors, w write it in brackets; otherwise we embrace it in parentheses when row vectors are multiplied by matrix from right. Correspondingly, the first matrix in the formula above is considered as as an operator acting on column vectors, whereas the latter acts on row vectors from right: [0, 0, 0, 1]T = [x₀, y₀, z₀, 1].

   
Example 1:    ■
End of Example 1

Rescaling

Scaling is used to make a picture fit a page, we change its width and height. Another example provides a copier by rescaling a figure by 85%. In linear algebra, we achive this by multiplying the identity matrix by scalar 0.85. That matrix is normally 2-by-2 for a plane and 3-by-3 for a solid. In computer graphics, with homogeneous coordinates, the matrix becomes one size larger:
\[ {\bf S} = \begin{bmatrix} 0.85 &0&0&0 \\ 0&0.85 &0&0 \\ 0&0&0.85 &0 \\ 0&0&0&1 \end{bmatrix} \quad\mbox{or} \quad \begin{pmatrix} c&0&0&0 \\ 0&c&0&0 \\ 0&0&c&0 \\ 0&0&0&1 \end{pmatrix}^{\mathrm T} . \]
S is not cI (constant times the identity matrix). We keep the “1” in the lower corner. Then [x, y, z, 1] times S is the correct answer in homogeneous coordinates. The origin stays in its normal position because [0 0 0 1]S = [0 0 0 1].

If we change that 1 to c, the result is strange. The point (cx, cy, cz, c) is the same as (x, y, z, 1). The special property of homogeneous coordinates is that multiplying by cI does not move the point. The origin in ℝ³ has homogeneous coordinates (0, 0, 0, 1) and (0, 0, 0, c) for every nonzero c. This is the idea behind the word “homogeneous.”

Scaling can be different in different directions. To fit a full-page picture onto a half-page, scale the y direction by ½. To create a margin, scale the x direction by 3/4. The graphics matrix is diagonal but not 2-by-2. It is 3-by-3 to rescale a plane

\[ {\bf S} = \begin{bmatrix} \frac{3}{4} &0&0 \\ 0&\frac{1}{2} &0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} \frac{3}{4} &0&0 \\ 0&\frac{1}{2} &0 \\ 0&0&1 \end{pmatrix} \]
and 4-by-4 to rescale a space:
\[ {\bf S} = \begin{bmatrix} c_1 &0&0&0 \\ 0&c_2& 0&0 \\ 0&0&c_3&0 \\ 0&0&0&1 \end{bmatrix} = \begin{pmatrix} c_1 &0&0&0 \\ 0&c_2& 0&0 \\ 0&0&c_3&0 \\ 0&0&0&1 \end{pmatrix} . \]
That last matrix S rescales the x, y, z directions by positive numbers c₁, c₂,c₃. The extra column in all these matrices leaves the extra 1 at the end of every point.

In certain instances, it may be required that an object has to be resized in the same coordinate system. The axes are then resized to different scales. As mentioned before, to scale a 2D point in the x direction by Sx and in the y direction by Sy we require transforming it as:

\[ \left( x_2 , y_2 \right) = \left( S_x x_1 , S_y y_1 \right) . \]
To achieve this, we use a matrix representation of the form,
\[ \begin{pmatrix} x_2 \\ y_2 \end{pmatrix} = \begin{bmatrix} S_x & 0 \\ 0 & S_y \end{bmatrix} \begin{pmatrix} x_1 \\ y_1 \end{pmatrix} \]
or
\[ \begin{bmatrix} x_2 & y_2 \end{bmatrix} = \begin{bmatrix} x_1 & y_1 \end{bmatrix} \begin{pmatrix} S_x & 0 \\ 0 & S_y \end{pmatrix} . \]

Computer graphics uses affine transformations, linear plus shift. An affine transformation is executed on projective space ℙ³, where points are identified with homogeneous coordinates (x, y, z, 1) rather than Cartesian coordinates (x, y, z) ∈ ℝ³. In 2D, a scaling transformation has the following affine form:

\[ {\bf S} = \begin{bmatrix} S_x & 0&0 \\ 0 & S_y&0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} S_x & 0&0 \\ 0 & S_y &0 \\ 0&0&1 \end{pmatrix}^{\mathrm T} . \]

3D models have several uses in computer assisted design (CAD) for engineering purposes. Using advanced scanning techniques with the help of MRI, 3D models of organs can be created that can help diagnose and assist in treatments of patients. In other medical uses, 3D models of proteins can help cancer research. There are many 3D models that are often used in movies and TV shows to represent characters as well as objects. These objects can be made realistic with advanced modeling techniques.

The scaling 4×4 matrix S is the same size as the affine translation matrix T. They can be multiplied. To translate and then rescale, multiply v T S. To rescale and then translate, multiply v S T, which is different from v T S, enerally speaking.    

Example 2:    ■
End of Example 2

Shearing

A typycal matrix that perform shearing in two-dimensional space is
\[ {\\mathbf{Ш} = \begin{bmatrix} a&c \\ 0&b \end{bmatrix} = \begin{pmatrix} a&0 \\ c&b \end{pmatrix}^{\mathrm T} . \]
Its affine (augmented) counterpart is read as
\[ \mathbf{Ш} = \begin{bmatrix} a&c&0 \\ 0&b&0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} a&0&0 \\ c&b&0 \\ 0&0&1 \end{pmatrix}^{\mathrm T} . \]
The following two animations demonstrate how a shear matrix effects a unit square when 𝑎 increases first follows by c change (left figure). Another animation shows transformations of unit square when oth parameters 𝑎 and b increase.

Parameters 𝑎 and c change independently and in sequence, first 𝑎 for expansion, then c for shearing.
     
Expansion and Shearing both occurring as parameters 𝑎 and c change together.

   
Example 3:    ■
End of Example 3

Rotation

Regular 2D rotation (by angle θ around the origin in counterclockwise direction) matrix \( \displaystyle \quad \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \quad \) has the following affine counterpart:
\[ {\bf R} (\theta ) = \begin{bmatrix} \cos\theta & - \sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} \cos\theta & \sin\theta & 0 \\ -\sin\theta & \cos\theta & 0 \\ 0&0&1 \end{pmatrix}^{\mathrm T} . \]
The affine matrix above describles a rotation in two-dimensional case around the origin in counterclockwise direction. This means that multiplication by this matrix a vector (from left or from right) results a new vector (either column or row) rotated by amount of θ radians. However, if you need to define a rotation around an arbitrary point P₀(x₀, y₀), you need to tanslate P₀ to (0, 0), then rotate by θ, then translate (0, 0) back to (x₀, y₀):
\[ {\bf v}\,{\bf T}_{-}{\bf R}(\theta )\,{\bf T}_{+} = \begin{bmatrix} x&y&1 \end{bmatrix} \begin{pmatrix} 1&0&0 \\ 0&1&0 \\ -x_0 & -y_0 & 1 \end{pmatrix} \begin{pmatrix} \cos\theta & \sin\theta & 0 \\ -\sin\theta & \cos\theta & 0 \\ 0&0&1 \end{pmatrix} \begin{pmatrix} 1&0&0 \\ 0&1&0 \\ x_0 & y_0 & 1 \end{pmatrix} . \]
   
Example 4:
Roger
   ■
End of Example 4

In three dimensions, every rotation R(n, θ) turns around an axis, which we identify with a unit vector n along the line of rotation in ℝ³. The axis doesn’t move—it is a line of eigenvectors with λ = 1. Suppose the axis is in the z=direction. The 1 in matrix R(n, θ) is to leave the z-axis alone, the extra 1 in affine matrix R(n, θ) is to leave the origin alone:

\[ {\bf R}_z (\theta ) = \begin{pmatrix} \cos\theta & \sin\theta & 0&0 \\ -\sin\theta & \cos\theta &0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{pmatrix} = \begin{bmatrix} \cos\theta & -\sin\theta & 0&0 \\ \sin\theta & \cos\theta &0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{bmatrix}^{\mathrm T} . \]
When dealing with 3D rotations you must take account to which axis you would like to perform the translation. Here is a rotation over the x-axis.
\[ {\bf v} = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \end{pmatrix} = \begin{bmatrix} 1&0&0 \\ 0& \cos\theta & -\sin\theta \\ 0&\sin \theta & \cos \theta \end{bmatrix} \begin{pmatrix} x\\ y\\ z \end{pmatrix} . \]
Here is a rotation around the y-axis:
\[ {\bf v} = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \end{pmatrix} = \begin{bmatrix} \cos\theta & 0 & -\sin\theta \\ 0&1&0 \\ \sin \theta & 0 & \cos \theta \end{bmatrix} \begin{pmatrix} x\\ y\\ z \end{pmatrix} . \]
Here is a rotation around the z-axis:
\[ {\bf v} = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \end{pmatrix} = \begin{bmatrix} \cos \theta & -\sin\theta & 0 \\ \sin\theta & \cos \theta & 0 \\ 0&0^1 \end{bmatrix} \begin{pmatrix} x\\ y\\ z \end{pmatrix} . \]
   
Example 5:    ■
End of Example 5

Reflection

Reflection matrices, also known as mirror matrices are not elements of SO(n) because their determinant is −1. These orthogonal matrices constitute subset of O(n) and they can be expressed as
\begin{equation} \label{EqRef.1} {\bf M} = {\bf I} - 2\,\hat{\bf n}\,\hat{\bf n}^{\mathrm T} , \end{equation}
where n is a unit vector orthogonal to the hyperplane that goes through the origin.    
Example 6:    ■
End of Example 6

Projection

In linear algebra, a projector operator or matrix P such that P² = P. The usual projection onto the plane with normal unit vector n is the matrix
\begin{equation} \label{EqProj.1} {\bf P} = {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} , \end{equation}
where I is the identity matrix and n is column unit vector (to hyperplane). Matrix P is a projector matrix because
\[ {\bf P}^2 = {\bf P} \, {\bf P} = \left( {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} \right) \left( {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} \right) = {\bf I} - 2 \hat{\bf n}\,\hat{\bf n}^{\mathrm T} + \hat{\bf n}\,\hat{\bf n}^{\mathrm T} \, \hat{\bf n}\,\hat{\bf n}^{\mathrm T} = {\bf P} \]
since nTn = [1], whicj is 1-by-1 matrix with single entry of "1." Recall that nT ∈ ℝ1×n is a row vector and n ∈ ℝn×1 is a column vector. We start with the folloing illustrative example of two-dimensional case.    
Example 7: We start with a smple case when line goes through the origin: \[ L\ : \quad x - 2\,y = 0 . \] Clearly, vector [1, −2] is orthogonal to L. It is convenient to work with unit vectors, so we introduce the normal one: \[ \hat{\bf n} = \frac{1}{\sqrt{5}} \left[ 1 \ -2 \right]^{\mathrm T} = \frac{1}{\sqrt{5}} \begin{bmatrix} 1 \\ -2 \end{bmatrix} . \] Its orthogonal vector goes along line L, \[ \hat{\bf n}^{\perp} = \frac{1}{\sqrt{5}} \left[ 2 \ 1 \right]^{\mathrm T} = \frac{1}{\sqrt{5}} \begin{bmatrix} 2 \\ 1 \end{bmatrix} . \] Using this unit normal vector n, we build the projection matrix \[ {\bf P} = {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} = {\bf I} - \frac{1}{\sqrt{5}} \begin{bmatrix} 1 \\ -2 \end{bmatrix} \cdot \frac{1}{\sqrt{5}} \begin{bmatrix} 1 & -2 \end{bmatrix} = \frac{1}{5} \begin{bmatrix} 4&2 \\ 2&1 \end{bmatrix} . \]
P = IdentityMatrix[2] - {{1, -2}, {-2, 4}}/5
{{4/5, 2/5}, {2/5, 1/5}}
P . P == P
True
Let us take a vector that has a projection that is easy to verify: v = (0, 1). Since line L makes angle of 30° with positive abscissa. Therefore, \[ {\bf v}_{\|} = \left( {\bf v} \bullet \hat{\bf n}^{\perp} \right) \hat{\bf n}^{\perp} = \frac{1}{5} \left[ 2 \ 1 \right]^{\mathrm T} = \frac{1}{5} \begin{bmatrix} 2 \\ 1 \end{bmatrix} . \]
v = {0, 1}; np = {2, 1}/Sqrt[5]; Dot[v, np]
1/Sqrt[5]
and \[ {\bf v}_{\perp} = \left( {\bf v} \bullet \hat{\bf n} \right) \hat{\bf n} = -\frac{2}{\sqrt{5}}\,\hat{\bf n} , \qquad {\bf v}_{\|} = \frac{1}{5} \begin{bmatrix} -2 \\ 4 \end{bmatrix} . \] We verify with Mathematica upon multiplcation of the projection matrix and given vector v
P = IdentityMatrix[2] - {{1, -2}, {-2, 4}}/5; P . {0, 1}
{2/5, 1/5}
Therefore, projection of vector [0, 1] on line L is the vector of length 1/2: \[ {\bf v}_{\|} = \frac{1}{5} \begin{bmatrix} 2 & 1 \end{bmatrix}^{\mathrm T} . \]    ■
End of Example 7
    In homogeneous coordinates, the projection matrix becomes 4 by 4 (but the origin doesn’t move):
\begin{equation} \label{EqProj.2} {\bf P} = \begin{bmatrix} &&&0 \\ {\bf I} - & \hat{\bf n}\,\hat{\bf n}^{\mathrm T} & &0 \\ &&& 0 \\ 0&0&0&1 \end{bmatrix} . \end{equation}

The matrix P gave a “parallel” projection. All points move parallel to n, until they reach the plane. The other choice in computer graphics is a “perspective” projection. This is more popular because it includes foreshortening. With perspective, an object looks larger as it moves closer. Instead of staying parallel to n (and parallel to each other), the lines of projection come toward the eye—the center of projection. This is how we perceive depth in a two-dimensional photograph.

Now we want to project a vector onto a plane nx = b, where n is unit vector perpendicular to the plan, x = (x₁, x₂, x₃) ∈ ℝ³, and b = (b₁, b₂, b₃) ∈ ℝ³. This plane does not go through the origin, but through the vector b ≠ 0.

The projection onto the flat (nx = b, which is a plane going through any point other than the origin) has three steps. Translate b to the origin by matrix T. Project along the n direction, and translate back along the row vector b. A projection matrix is symmetric, but transition matrices T and T+ depend on whether vectors are written as rowss or as columns. Since computer graphics works with roews, we demontrarate this approach first:

\begin{equation} \label{EqProj.3} {\bf T}_{-} {\bf P}\,{\bf T}_{+} = \begin{pmatrix} {\bf I} &0 \\ -{\bf b} &1 \end{pmatrix} \begin{pmatrix} {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} & 0 \\ 0& 1 \end{pmatrix} \begin{pmatrix} {\bf I} &0 \\ {\bf b} &1 \end{pmatrix} . \end{equation}
In case of using column vectors, affine projection matrix reads as
\begin{equation} \label{EqProj.4} {\bf T}_{+} {\bf P}\,{\bf T}_{-} = \begin{bmatrix} {\bf I} & {\bf b} \\ 0 & \phantom{-}1 \end{bmatrix} \begin{bmatrix} {\bf I} - \hat{\bf n}\,\hat{\bf n}^{\mathrm T} & 0 \\ 0&1 \end{bmatrix} \begin{bmatrix} \{\bf I| & -{\bf b} \\ 0 & \phantom{-}1 \end{bmatrix} \end{equation}
   
Example 8:    ■
End of Example 8
    The matrix P gave a “parallel ” projection. All points move parallel to n, until they reach the plane. The other choice in computer graphics is a “perspective ” projection. This is more popular because it includes foreshortening. With perspective, an object looks larger as it moves closer. Instead of staying parallel to n (and parallel to each other), the lines of projection come toward the eye—the center of projection. This is how we perceive depth in a two-dimensional photograph.

========================== to be checked ==============

The second process in 3D graphics is called animation. This process defines relationships between 3D objects in a three dimensional space over time. This can be done through many different methods such as key frames, inverse kinematics and motion capture. Motion capture is the modeling of a 3D animation by using sensors or cameras to capture the motion of an object or a person in the real world. Inverse kinematics is a powerful tool when developing games or movies that makes it possible to calculate the precise positions for a joint system so it will eventually reach a certain goal. This is done in movies to capture facial expressions of actors to be used in animation to depict those expressions on animated characters. For example, in Pirates of the Caribbean movie, Davy Jones facial expressions was modeled with his face tentacles in the movie with the help of motion capture of the actor’s face. Similarly, inverse kinematics is a process where the path of an object can be used by partial information or data from some other source. A known application of this process is in Robotics where this process is employed to calculate the trajectory needed for robot’s limb in order to successfully perform a maneuver or a task. Therefore this process requires a sophisticated application of Linear Algebra. If you look at the picture that was discovered on a recent blog you can see that Mario is jumping with a velocity of (1,3). You can see that he is moving pretty fast upwards and to the right with an acceleration of (0,-1). In the game the player normally uses an analog to control the left and right movement of the character. Then the player would press some sort of button for the character to jump. This is a perfect example to show you how games use vector addition and subtraction to calculate the overall velocity and position of the player.

The third process in 3D graphics is called 3D rendering. 3D rendering makes use of a 3D wire frame model of an object or multiple objects to produce an animated scene or a 2D image from the scene. This is done through the application of two operations. First operation is transport, which means how much light is being shone on to the surface being rendered, from what direction this light is coming, and how intense the light source is. The second operation is called scattering which determines how the surface is being rendered interacts with light. These two operations are required to render 3D models in CAD animation, or even physics and weather animations etc. Although in this animation setting, such as some video games, movies and advertisements, other sophisticated techniques such as god rays or scanline rendering are used to improve the quality.

Rigid Body Transformations

A rigid body transformation is one that changes the location and orientation of an object, but not its shape. All angles, lengths, areas, and volumes are preserved. Translation and rotation are the only rigid body transformations. Reflection is not considered a rigid body transformation.

All rigid body transformations are orthogonal, angle-preserving, invertible, and affine. Rigid body transforms are the most restrictive class of transforms, but they are also extremely common in practice. The determinant of any rigid body transformation matrix is 1.    ■

In conclusion, Linear Algebra is used in many different ways in computer graphics. The mathematical structure of computer graphics takes advantage of many operations and theorems in Linear Algebra to assist in 2D/3D models, in animations and in rendering.

There are many uses for 3D wireframes such as viewing the model from any angle or even using it to analyze the distances between the edge and corners. This technique has been in use for almost as long as computer displays have been around. It became noticed in late 1970’s and early 1980’s when it was used in computer games. Around the same time, 3D object rendering started being used in movies to depict objects. Making of 3D graphics can be divided into the following different processes:

First is the modeling of a surface of an object into a representation of a collection of points in 3D space. This process is done with the help of a modeling software, or by using specialized 3D scanners. However, the end result is always a collection of points in 3D space. These points are vectors in Linear Algebra, on which the processes of Linear Algebra such as transformation, rotation and scaling can be applied.

2D Affine Transformations

Matrix Representations of 2D Affine Transformations include extra dimension. Matrices are in brackets when they considered as operators acting on column vectors from left. Matrices are embraced in parentheses when they multiply row vectors from right.

Translation:

\[ \mathbf{T} = \begin{bmatrix} 1&0&\Delta x \\ 0&1&\Delta y \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} 1&0&0 \\ 0&1&0 \\ \Delta x & \Delta y &1 \end{pmatrix}^{\mathrm T} . \]

Scale:

\[ \mathbf{S} = \begin{bmatrix} s_x & 0 & 0 \\ 0& s_y & 0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} s_x & 0 & 0 \\ 0& s_y & 0 \\ 0&0&1 \end{pmatrix} . \]

Reflection (also known as mirroring) in the plane is given a line and maps points by flipping the plane about this line.

\[ \mathbf{M}_x = \begin{bmatrix} -1&0&0 \\ 0&1&0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} -1&0&0 \\ 0&1&0 \\ 0&0&1 \end{pmatrix} . \]

Rotation in positive (counterclockwise) direction by angle θ (in radians) when frame is fixed:

\[ \mathbf{R}[\theta ] = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} \cos\theta & \sin\theta & 0 \\ -\sin\theta & \cos\theta & 0 \\ 0&0&1 \end{pmatrix}^{\mathrm T} . \]

Shear:

Shearing is a transformation that skews the coordinate space; it is usually achieved by adding multiple of one coordinate to the other. This is obtained by matrix multiplication (from left or from right):

\[ \mathbf{Ш} = \begin{bmatrix} 1&a&0 \\ b&1&0 \\ 0&0&1 \end{bmatrix} = \begin{pmatrix} 1&b&0 \\ a&1&0 \\ 0&0&1 \end{pmatrix}^{\mathrm T} , \quad a, b \in \mathbb{R} , \]
where symbol "T" stands for transposition.    
Example 18: http://igg.unistra.fr/People/seo/2%20affine%20transformation.pdf Let us consider an inhabited set L of 𝔸² consisting of all points (x, y) satisfying the equation \[ 2\,x + y -3 = 0 . \] The set L is the line of slope −2 passing through the points (3/2, 0) and (0, 3) shown in Figure below.
Plot[3 - 2*x, {x, -0.5, 2}, PlotStyle -> Thickness[0.01]]
Rotating about the x-axis in 3D.
The line L can be made into an official affine space by defining the action d : L × ℝ ↦ L by \[ \left( x, 3 - 2\, x , \right) + v = \left( x+ v, 3 - 2\,x - 2\,v \right) . \] This action transfers L into an affine space. For example, for any two points P(𝑎, 3 −2𝑎) and Q(b −2b) on L, here is a unique (vector) u ∈ ℝ such that Q = P + u. It is clear that u = b − 𝑎. Note that the vector space ℝ is isomorphic to the line of equation 3x + y = 0 passing through the origin.

Similarly, the inhabited set H of 𝔸³ consisting of all points (x, y, z) satisfying the equation \[ 2\, x + 3\,y + z - 6 = 0 . \] The set H is the plane passing through the points (3, 0, 0), (0, 2, 0), and (0, 0, 1). The plane H can be made into an official affine space by defining the action d : H × ℝ² defines by \[ \left( x, y, 6 - 2\,x - 3\,y \right) + \begin{bmatrix} u \\ v \end{bmatrix} = \left( x + u , y + v , 6 - 2\,x -2\,u - 3\,y -3\,v \right) \] for any point (x, y, 6 −2x −3y) of H and any vector [u, v]T ∈ ℝ².

The affine matrix for corresponding transformation is ????    ■

End of Example 18
   
Example 19: We reconsider an affine transformation from Example 2: \[ \begin{bmatrix} x \\ y \end{bmatrix} \,\mapsto \, \begin{bmatrix} 1 & 1 \\ 0 & 2 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} \phantom{-}2 \\ -1 \end{bmatrix} , \] with matrix and free term \[ {\bf A} = \begin{bmatrix} 1 & 1 \\ 0 & 2 \end{bmatrix} \qquad \mbox{and} \qquad {\bf b} = \begin{bmatrix} \phantom{-}2 \\ -1 \end{bmatrix} , \] respectively. We demonstrate Mathematica's capabilitues to handle an affine transformation.
A = {{1, 1}, {0, 2}};
b = {2, -1};
t = AffineTransform[{A, b}]
TransformationFunction[\( \displaystyle \quad \left( \begin{array}{cc|c} 1&1&2 \\ 0&2&-1 \\ \hline 0&0&1 \end{array} \right) \) ]
We use another Mathematica command
TransformationMatrix@AffineTransform[{A, b}]
\( \displaystyle \quad \begin{pmatrix} 1&1&2 \\ 0&2&-1 \\ 0&0&1 \end{pmatrix} \)
Earlier, way back at the top of this page, we began a passage with "One might reasonably ask: 'What does the last line mean? What does the row containing {0.,0.|1.}, of the TransformationFunction do?'" We put off until now a more complete answer to that question. Before, what followed was a particular answer from the ChatBot representing Wolfram's Artificial Intelligence module in a Chat-Enabled notebook. Below we ask that same question of the same AI bot and this time we get:
The last row "0 0 1" of a 3x3 transformation matrix is a part of the homogeneous coordinate representation used in affine transformations.
In homogeneous coordinates, a 2D point (x, y) is represented as (x, y, 1) and a 2D vector is represented as (x, y, 0). The reason for this is to allow for translations to be represented as matrix multiplications.

The "0 0 1" row in the transformation matrix ensures that when this matrix is multiplied with a point represented in homogeneous coordinates, the 1 in the third component of the point stays a 1. This is necessary to keep the point a point, and not a vector.

In contrast, if the transformation matrix is multiplied with a vector, the 0 in the third component of the vector stays a 0, ensuring that the vector remains a vector and is not translated.

So, the "0 0 1" row is essentially a part of the mathematical machinery that allows for points and vectors to be treated differently by affine transformations, particularly translations. It doesn't directly affect the scaling, rotation, shear or translation applied to the points or vectors.

Now we are in preparation to use a special Mathematica command FindGeometricTransform, which is suitable for image processing.

(* Define the points *)
rectPoints = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}} paraPoints = allCorners;
============================= what is allCorners;

Note first element of the output is an error term, which in our case is very close to zero . Second line of output uses Chop to display as zero

{error, transform} = FindGeometricTransform[paraPoints, rectPoints, TransformationClass -> "Affine"]
Chop[%]
{9.21221*10-16, TransformationFunction[ \( \displaystyle \quad \left( \begin{array}{cc|c} 1.& 1.& 2. \\ 2.22045*10^{-16} & 2.& -1. \\ \hline 0.&0.& 1. \end{array} \right) \) ]
{0, TransformationFunction[ \( \displaystyle \quad \left( \begin{array}{cc|c} 1.& 1.& 2. \\ 0. & 2.& -1. \\ \hline 0.&0.& 1. \end{array} \right) \) ]
Apply the transformation to the rectangl
transformedRect = transform@Rectangle[{-1, -1}, {1, 1}]
Plot the two objects
Graphics[{ {EdgeForm[Thick], Opacity[0.5], Red, Rectangle[{-1, -1}, {1, 1}]}, {EdgeForm[Thick], Opacity[0.5], Black, transformedRect} }, GridLines -> Automatic, PlotRange -> All, Axes -> True]
Affine transformation of a square.

Below we have two images of a man recorded at different points in time. We want to know how many errors he has made in the time that elapsed between these two images.

image1 =       image2 = --->
We are not surprised that he has made very few errors
err, tr} = FindGeometricTransform[img1, img2, TransformationClass -> "Affine"]
Chop[%]
{1.68485*10-12, TransformationFunction[ \( \displaystyle \quad \left( \begin{array}{cc|c} 0.828991 & 0.0561282 & 95.6187 \\ "0.180272 & 1.013978 & 58.300062 \\ \hline 0. & 0. & 1. \end{array} \right) \)
If we want to find out how tilted he has become, we apply the GeometricTransform Mathematica found to the first image to see he has become a little off level over the years.
ImagePerspectiveTransformation[img1, tr, DataRange -> Full]
Roger write.
   ■
End of Example 19
   
Example 20: http://igg.unistra.fr/People/seo/2%20affine%20transformation.pdf    ■
End of Example 20
   
Example 21:    ■
End of Example 21

Rotation: In its most general form, rotation is defined to take place about some fixed point. We will consider the simplest case where the fixed point is the origin of the coordinate frame.    

Example 22:    ■
End of Example 22

3D Affine Transformations

Now, we can extend all of previously discussed ideas to 3D in the following way. First, we convert all 3D points to homogeneous coordinates of point P(x, y, z), written in either row form or column form:
\[ \left[ x\, : \, y \, : \, z \, : \, 1\right] \in \mathbb{R}^{1 \times 4} \qquad \mbox{or} \qquad \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} \in \mathbb{R}^{4 \times 1} . \]
The following matrices constitute the basic affine transforms in 3D, expressed in homogeneous form:
\[ \mbox{Translate: } \ \begin{bmatrix} 1&0&0& \Delta x \\ 0&1&0 &\Delta y \\ 0&0&1& \Delta z \\ 0&0&0&1 \end{bmatrix} = \begin{pmatrix} 1&0&0& 0 \\ 0&1&0 &0 \\ 0&0&1& 0 \\ \Delta x & \Delta y& \Delta z&1 \end{pmatrix}^{\mathrm T} , \]
\[ \mbox{Scale: } \ \begin{bmatrix} s_x & 0&0&0 \\ 0&s_y & 0&0 \\ 0&0&s_z & 0 \\ 0&0&0&1 \end{bmatrix} = \begin{pmatrix} s_x & 0&0&0 \\ 0&s_y & 0&0 \\ 0&0&s_z & 0 \\ 0&0&0&1 \end{pmatrix} , \]
\[ \mbox{Shear: } \ \begin{bmatrix} 1 & h_{xy} & h_{xz} & 0 \\ h_{yx} & 1 & h_{yz} & 0 \\ h_{zx} & h_{zy} & 1 & 0 \\ 0&0&0&1 \end{bmatrix} = \begin{pmatrix} 1 & h_{yz} & h_{zx} & 0 \\ h_{xy} & 1 & h_{zy} & 0 \\ h_{xz} & h_{yz} & 1 & 0 \\ 0&0&0&1 \end{pmatrix}^{\mathrm T} . \]
   
Example 23:    ■
End of Example 23

Reflection in 3-space is given a plane, and flips points in space about this plane. In this case, reflection is just a special case of scaling, but where the scale factor is negative. A common simple version of this is when the plane about which the reflection is performed is one of the coordinate planes (corresponding to x = 0, y = 0, or z = 0).

For example, to reflect points about the xz-coordinate plane (that is, the plane y = 0), we can scale the y-coordinate by −1. Using the scaling matrix above, we have the following transformation matrix:

\[ \mathbf{M}_y = \begin{bmatrix} 1&0&0&0 \\ 0&-1&0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{bmatrix} . \]
The cases for the other two coordinate frames are similar.

   
Example 24:    ■
End of Example 24

Rotation: In its most general form, rotation is defined to take place about some fixed vector in space ℝ³. We will consider the simplest case where the fixed vector is one of the coordinate axes. There are three basic rotations: about the x, y and z-axes. In each case, the rotation is counterclockwise through an angle θ (given in radians). The rotation is assumed to be in accordance with a right-hand rule: if your right thumb is aligned with the axes of rotation, then positive rotation is indicated by the direction in which the fingers of this hand are pointing. To produce a clockwise rotation, simply negate the angle involved.

Consider a rotation about the z-axis. The z-unit vector and origin are unchanged. The x-unit vector is mapped to (cos θ, sin θ, 0, 0), and the y-unit vector is mapped to (− sin θ, cos θ, 0, 0). Thus the rotation matrix is:

\[ \mbox{Rotation about $z$ axis: } \ \begin{bmatrix} \cos \theta_z & -\sin \theta_z &0&0 \\ \sin \theta_z & \cos \theta_z &0&0 \\ 0&0&1&0 \\ 0&0&0&1 \end{bmatrix} . \]
   
Example 25:    ■
End of Example 25
RotationMatrix[\[Theta], {0, 0, 1}] // MatrixForm
\( \displaystyle \quad \begin{pmatrix} \cos \theta_z & -\sin \theta_z &0 \\ \sin \theta_z & \cos \theta_z &0 \\ 0&0&1 \end{pmatrix} \)
Observe that both points and vectors are altered by rotation. For the other two axes we have:
\[ \mbox{Rotation about $x$ axis: } \ \begin{bmatrix} 1&0&0&0 \\ 0&\cos \theta_x & -\sin \theta_x & 0 \\ 0&\sin \theta_x & \cos \theta_x & 0 \\ 0&0&0&1 \end{bmatrix} , \]
   
Example 26:    ■
End of Example 26
RotationMatrix[\[Theta], {1, 0, 0}] // MatrixForm
\( \displaystyle \quad \begin{pmatrix} 1&0&0 \\ 0&\cos \theta_x & -\sin \theta_x \\ 0&\sin \theta_x & \cos \theta_x \end{pmatrix} \)
\[ \mbox{Rotation about $y$ axis: } \ \begin{bmatrix} \cos \theta_y & 0 & \sin \theta_y & 0 \\ 0&1&0&0 \\ -\sin \theta_y & 0 & \cos \theta_y & 0 \\ 0&0&0&1 \end{bmatrix} , \]
A rotation by angle θ about an arbitrary axis can be decomposed into the concatenation of rotations about the x, y, and z axes (see section on Euler's theorem).

   
Example 27: Let us consider a line that goes through point P(7, 11, -5), which is parallel to the vector w = (3, 1, 8). We want to rotate the point Q(6, -9, 15) about this line through angels θ that are multiples of 5° until we are back at the point Q. Each rotation through a fixed angle θ is one application of an affiner map. The plot of these points is essentially the circle of rotation for Q. The formula for the rotated point Qnew is given by    ■
End of Example 27

  1. Chaku, S., Bhatnagar, A., 2D Transformations Analyzed by Both Column Vector and Row Vector Synthesis, International Journal of Engineering and Advanced Technology (IJEAT), VISSN: 2249 – 8958, olume-9 Issue-3, February 2020
  2. Gortler, S.J., Foundations of 3D Computer Graphics (Mit Press) , 2012.
  3. Hearn, D., Baker, P., Computer Graphics, C version, second edition.
  4. Hughes, J.F., van Dam, A., McGuire, M., Sklar, D., Foley, J.D., Feiner, S.K., Akeley, K., Computer Graphics. Principoles and Practice, Third edition, Addison-Wesley, Upper Saddle River, NJ. 2014.