3D transformation:-
3D transformations refer to the process of changing the position, orientation, and size of objects
in three-dimensional space. These transformations are fundamental in computer graphics, CAD
(Computer-Aided Design), animation, and games.
There are several types of 3D transformations:
1. Translation
Translation moves an object from one location to another without rotating or resizing it. It
involves shifting an object along the X, Y, and Z axes.
Formula for translation:
T(x,y,z)T(x, y, z)T(x,y,z)
Where TTT is the translation vector, and x,y,zx, y, zx,y,z are the translation amounts
along each axis.
2. Scaling
Scaling changes the size of an object. It can either enlarge or shrink the object along the X, Y,
and Z axes. The scaling transformation is typically represented by a scaling factor for each axis.
Formula for scaling:
S(sx,sy,sz)S(s_x, s_y, s_z)S(sx,sy,sz)
Where sx,sy,szs_x, s_y, s_zsx,sy,sz are scaling factors for the X, Y, and Z axes.
3. Rotation
Rotation changes the orientation of an object around one of the axes (X, Y, or Z). The rotation is
done in a counter-clockwise direction, and the amount of rotation is measured in degrees or
radians.
Formula for rotation about the X-axis:
Rx(θ)R_x(\theta)Rx(θ)
Where θ\thetaθ is the angle of rotation.
Formula for rotation about the Y-axis:
Ry(θ)R_y(\theta)Ry(θ)
Formula for rotation about the Z-axis:
Rz(θ)R_z(\theta)Rz(θ)
In general, the 3D rotation matrix for an object is defined by one or more of the following
rotation matrices depending on the axis of rotation:
Around the X-axis:
Rx(θ)=(1000cos(θ)−sin(θ)0sin(θ)cos(θ))R_x(\theta) = \begin{pmatrix} 1 & 0 & 0
\\ 0 & \cos(\theta) & -\sin(\theta) \\ 0 & \sin(\theta) & \cos(\theta) \end{pmatrix}Rx(θ)=
1000cos(θ)sin(θ)0−sin(θ)cos(θ)
Around the Y-axis:
Ry(θ)=(cos(θ)0sin(θ)010−sin(θ)0cos(θ))R_y(\theta) = \begin{pmatrix}
\cos(\theta) & 0 & \sin(\theta) \\ 0 & 1 & 0 \\ -\sin(\theta) & 0 & \cos(\theta)
\end{pmatrix}Ry(θ)=cos(θ)0−sin(θ)010sin(θ)0cos(θ)
Around the Z-axis:
Rz(θ)=(cos(θ)−sin(θ)0sin(θ)cos(θ)0001)R_z(\theta) = \begin{pmatrix} \cos(\theta)
& -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{pmatrix}Rz(θ)=
cos(θ)sin(θ)0−sin(θ)cos(θ)0001
4. Shearing
Shearing involves changing the shape of an object in such a way that the transformation pushes
one layer of the object in a different direction than the other. It can be done along any of the axes
and is usually represented by a shear matrix.
Formula for shearing:
Hxy=(1shx0shy10001)H_{xy} = \begin{pmatrix} 1 & sh_x & 0 \\ sh_y & 1 & 0 \\ 0 & 0
& 1 \end{pmatrix}Hxy=1shy0shx10001
5. Perspective Transformation
Perspective transformation involves adjusting the depth perception of an object, making distant
objects appear smaller. This is especially important for rendering 3D objects onto a 2D screen
(e.g., in games and animations).
The perspective matrix is typically defined as:
P=(f/d0000f/d0000(f+n)/(f−n)−2fn/(f−n)0010)P = \begin{pmatrix} f/d & 0 & 0 & 0 \\ 0
& f/d & 0 & 0 \\ 0 & 0 & (f+n)/(f-n) & -2fn/(f-n) \\ 0 & 0 & 1 & 0 \end{pmatrix}P=
f/d0000f/d0000(f+n)/(f−n)100−2fn/(f−n)0
Where fff is the focal length and nnn is the near plane, and ddd is the distance from the
camera.
Combining Transformations
In practice, these transformations are often combined into a single matrix operation. To do this,
we multiply the matrices representing each transformation in the order they should be applied.
6. Homogeneous Coordinates
To perform all these transformations efficiently, 3D graphics systems use homogeneous
coordinates. This means representing 3D coordinates as a 4D vector, which allows translations
to be represented as matrix multiplications.
Example of a point P(x,y,z)P(x, y, z)P(x,y,z) in homogeneous coordinates:
Ph=(xyz1)P_h = \begin{pmatrix} x \\ y \\ z \\ 1 \end{pmatrix}Ph=xyz1
This allows for a unified approach to all transformations, making them easier to compute and
combine.
Numerical problem of transformation:-
Let's work through a numerical example involving 3D transformations. We will apply multiple
transformations — translation, rotation, and scaling — to a point in 3D space. We'll do the
following steps:
Problem:
Given the point P(1,2,3)P(1, 2, 3)P(1,2,3), perform the following transformations:
1. Translate the point by (3,−2,1)(3, -2, 1)(3,−2,1).
2. Rotate the point 90 degrees around the Z-axis.
3. Scale the point by a factor of 2 along the X-axis, 3 along the Y-axis, and 1 along the Z-
axis.
We'll compute each transformation step by step.
Step 1: Translation
Translation involves moving the point along the X, Y, and Z axes. The translation vector is
T=(3,−2,1)T = (3, -2, 1)T=(3,−2,1), and the point is P=(1,2,3)P = (1, 2, 3)P=(1,2,3).
To translate the point:
P′=P+T=(1+3,2−2,3+1)=(4,0,4)P' = P + T = (1 + 3, 2 - 2, 3 + 1) = (4, 0,
4)P′=P+T=(1+3,2−2,3+1)=(4,0,4)
So after the translation, the point becomes P′(4,0,4)P'(4, 0, 4)P′(4,0,4).
Step 2: Rotation
Now we rotate the point 90 degrees around the Z-axis. The rotation matrix for a 90-degree
rotation around the Z-axis is:
Rz(90∘)=(cos(90∘)−sin(90∘)0sin(90∘)cos(90∘)0001)R_z(90^\circ) = \begin{pmatrix}
\cos(90^\circ) & -\sin(90^\circ) & 0 \\ \sin(90^\circ) & \cos(90^\circ) & 0 \\ 0 & 0 & 1
\end{pmatrix}Rz(90∘)=cos(90∘)sin(90∘)0−sin(90∘)cos(90∘)0001
Since cos(90∘)=0\cos(90^\circ) = 0cos(90∘)=0 and sin(90∘)=1\sin(90^\circ) = 1sin(90∘)=1,
the matrix becomes:
Rz(90∘)=(0−10100001)R_z(90^\circ) = \begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1
\end{pmatrix}Rz(90∘)=010−100001
Now apply this matrix to the translated point P′(4,0,4)P'(4, 0, 4)P′(4,0,4):
(x′y′z′)=Rz(90∘)×(404)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = R_z(90^\circ) \times
\begin{pmatrix} 4 \\ 0 \\ 4 \end{pmatrix}x′y′z′=Rz(90∘)×404
Performing the multiplication:
x′=0×4+(−1)×0+0×4=0x' = 0 \times 4 + (-1) \times 0 + 0 \times 4 = 0x′=0×4+(−1)×0+0×4=0
y′=1×4+0×0+0×4=4y' = 1 \times 4 + 0 \times 0 + 0 \times 4 = 4y′=1×4+0×0+0×4=4
z′=0×4+0×0+1×4=4z' = 0 \times 4 + 0 \times 0 + 1 \times 4 = 4z′=0×4+0×0+1×4=4
So, after the rotation, the new coordinates of the point are (0,4,4)(0, 4, 4)(0,4,4).
Step 3: Scaling
Next, we apply scaling. The scaling factors are sx=2s_x = 2sx=2, sy=3s_y = 3sy=3, and sz=1s_z
= 1sz=1. The scaling matrix is:
S=(200030001)S = \begin{pmatrix} 2 & 0 & 0 \\ 0 & 3 & 0 \\ 0 & 0 & 1 \end{pmatrix}S=200
030001
Now, apply the scaling matrix to the rotated point (0,4,4)(0, 4, 4)(0,4,4):
(x′y′z′)=S×(044)\begin{pmatrix} x' \\ y' \\ z' \end{pmatrix} = S \times \begin{pmatrix} 0 \\ 4 \\ 4
\end{pmatrix}x′y′z′=S×044
Performing the multiplication:
x′=2×0+0×4+0×4=0x' = 2 \times 0 + 0 \times 4 + 0 \times 4 = 0x′=2×0+0×4+0×4=0
y′=0×0+3×4+0×4=12y' = 0 \times 0 + 3 \times 4 + 0 \times 4 = 12y′=0×0+3×4+0×4=12
z′=0×0+0×4+1×4=4z' = 0 \times 0 + 0 \times 4 + 1 \times 4 = 4z′=0×0+0×4+1×4=4
So, after scaling, the final coordinates of the point are (0,12,4)(0, 12, 4)(0,12,4).
Final Result:
After applying translation, rotation, and scaling, the final position of the point P(1,2,3)P(1, 2,
3)P(1,2,3) is:
(0,12,4)\boxed{(0, 12, 4)}(0,12,4)
This process demonstrates how to apply different transformations step by step to a point in 3D
space.