Chapter 5 - 3D Transformations
Chapter 5 - 3D Transformations
3D Transformations
3-D Transformation is the process of manipulating the view of a three-D object with respect to its
original position by modifying its physical attributes through various methods of transformation.
Properties of 3-D Transformation:
• Lines are preserved,
• Parallelism is preserved,
• Proportional distances are preserved.
Homogeneous Coordinates
A point in homogeneous coordinates is represented as a four-element column vector of three
coordinates and a scale factor w ¹¹¹ 0. For example:
One advantage of this approach is that translation, which normally must be expressed as an addition,
can be represented as a matrix multiplication. Another advantage is that homogeneous coordinate
representations simplify perspective transformations.
Types of Transformations:
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shear
3D Translation
3D Translation is a process of moving an object from one position to another in a three-dimensional
plane.
• Initial coordinates of the object O = (Xold, Yold, Zold)
1
Given a Translation vector (Tx, Ty, Tz)-
This translation is achieved by adding the translation coordinates to the old coordinates of the object as-
2
Example: Given a 3D object with coordinate points A(0, 3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0). Apply
the translation with the distance 1 towards X axis, 1 towards Y axis and 2 towards Z axis and obtain the
new coordinates of the object.
Given-
• Old coordinates of the object = A (0, 3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0)
• Translation vector = (Tx, Ty, Tz) = (1, 1, 2)
• Xnew = Xold + Tx = 0 + 1 = 1
• Ynew = Yold + Ty = 3 + 1 = 4
• Znew = Zold + Tz = 1 + 2 = 3
• Xnew = Xold + Tx = 3 + 1 = 4
• Ynew = Yold + Ty = 3 + 1 = 4
• Znew = Zold + Tz = 2 + 2 = 4
3
Applying the translation equations, we have-
• Xnew = Xold + Tx = 3 + 1 = 4
• Ynew = Yold + Ty = 0 + 1 = 1
• Znew = Zold + Tz = 0 + 2 = 2
• Xnew = Xold + Tx = 0 + 1 = 1
• Ynew = Yold + Ty = 0 + 1 = 1
• Znew = Zold + Tz = 0 + 2 = 2
Thus, New coordinates of the object = A (1, 4, 3), B(4, 4, 4), C(4, 1, 2), D(1, 1, 2).
3D Rotation
3D Rotation is a process of rotating an object with respect to an angle in a three dimensional plane.
Consider a point object O has to be rotated from one angle to another in a 3D plane.
Let-
4
• X-axis Rotation
• Y-axis Rotation
• Z-axis Rotation
• Xnew = Xold
• Ynew = Yold
5
For Z-Axis Rotation-
• Znew = Zold
Example: Given a homogeneous point (1, 2, 3). Apply rotation 90 degree towards X, Y and Z axis and
find out the new coordinate points.
Given-
• Xnew = Xold = 1
• Ynew = Yold = 2
• Znew = Zold = 3
7
3D Scaling
In computer graphics, scaling is a process of modifying or altering the size of objects.
Let-
• Xnew = Xold x Sx
• Ynew = Yold x Sy
• Znew = Zold x Sz
8
Example: Given a 3D object with coordinate points A(0, 3, 3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0). Apply
the scaling parameter 2 towards X axis, 3 towards Y axis and 3 towards Z axis and obtain the new
coordinates of the object.
Given-
• Old coordinates of the object = A (0, 3, 3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0)
• Scaling factor along X axis = 2
• Scaling factor along Y axis = 3
• Scaling factor along Z axis = 3
• Xnew = Xold x Sx = 0 x 2 = 0
• Ynew = Yold x Sy = 3 x 3 = 9
• Znew = Zold x Sz = 3 x 3 = 9
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 3 x 3 = 9
• Znew = Zold x Sz = 6 x 3 = 18
9
Thus, New coordinates of corner B after scaling = (6, 9, 18).
• Xnew = Xold x Sx = 3 x 2 = 6
• Ynew = Yold x Sy = 0 x 3 = 0
• Znew = Zold x Sz = 1 x 3 = 3
• Xnew = Xold x Sx = 0 x 2 = 0
• Ynew = Yold x Sy = 0 x 3 = 0
• Znew = Zold x Sz = 0 x 3 = 0
3D Reflection
• Reflection is a kind of rotation where the angle of rotation is 180 degree.
• The reflected object is always formed on the other side of mirror.
• The size of reflected object is same as the size of original object.
Let-
10
In 3 dimensions, there are 3 possible types of reflection-
• Xnew = Xold
• Ynew = Yold
• Znew = -Zold
11
• Xnew = -Xold
• Ynew = Yold
• Znew = Zold
• Xnew = Xold
• Ynew = -Yold
• Znew = Zold
12
Example: Given a 3D triangle with coordinate points A(3, 4, 1), B(6, 4, 2), C(5, 6, 3). Apply the
reflection on the XY plane and find out the new coordinates of the object.
Given-
• Old corner coordinates of the triangle = A (3, 4, 1), B(6, 4, 2), C(5, 6, 3)
• Reflection has to be taken on the XY plane
Let the new coordinates of corner A after reflection = (Xnew, Ynew, Znew).
• Xnew = Xold = 3
• Ynew = Yold = 4
• Znew = -Zold = -1
Let the new coordinates of corner B after reflection = (Xnew, Ynew, Znew).
• Xnew = Xold = 6
• Ynew = Yold = 4
• Znew = -Zold = -2
Let the new coordinates of corner C after reflection = (Xnew, Ynew, Znew).
• Xnew = Xold = 5
13
• Ynew = Yold = 6
• Znew = -Zold = -3
Thus, New coordinates of the triangle after reflection = A (3, 4, -1), B(6, 4, -2), C(5, 6, -3).
3D Shearing
3D Shearing is an ideal technique to change the shape of an existing object in a three dimensional
plane.In a three dimensional plane, the object size can be changed along X direction, Y direction as
well as Z direction.
Let-
14
Shearing in X Axis-
• Xnew = Xold
Shearing in Y Axis-
• Ynew = Yold
15
Shearing in Z Axis-
• Znew = Zold
Example: Given a 3D triangle with points (0, 0, 0), (1, 1, 2) and (1, 1, 3). Apply shear parameter 2 on
X axis, 2 on Y axis and 3 on Z axis and find out the new coordinates of the object.
Solution-
Given-
• Old corner coordinates of the triangle = A (0, 0, 0), B(1, 1, 2), C(1, 1, 3)
• Shearing parameter towards X direction (Shx) = 2
16
Shearing in X Axis-
For Coordinates A(0, 0, 0)
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
• Xnew = Xold = 0
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
• Xnew = Xold = 1
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
• Xnew = Xold = 1
17
Thus, New coordinates of the triangle after shearing in X axis = A (0, 0, 0), B(1, 3, 5), C(1, 3, 6).
Shearing in Y Axis-
For Coordinates A(0, 0, 0)
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
• Ynew = Yold = 0
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
• Ynew = Yold = 1
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
• Ynew = Yold = 1
18
Thus, New coordinates of corner C after shearing = (3, 1, 6).
Thus, New coordinates of the triangle after shearing in Y axis = A (0, 0, 0), B(3, 1, 5), C(3, 1, 6).
Shearing in Z Axis-
For Coordinates A(0, 0, 0)
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
• Znew = Zold = 0
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
• Znew = Zold = 2
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
19
• Ynew = Yold + Shy x Zold = 1 + 2 x 3 = 7
• Znew = Zold = 3
Thus, New coordinates of the triangle after shearing in Z axis = A (0, 0, 0), B(5, 5, 2), C(7, 7, 3).
In OpenGL translation, rotation, and scaling are performed using commands such as:
What these commands do in practice is to generate the corresponding transformation matrix for the
operation that was requested, multiply it by whatever matrix is currently on top of the currently active-
matrix stack, and replace the matrix on the top of the stack with the result. If you want to calculate and
save the result of a complex series of transformations, one approach is to push an identity matrix onto
the stack, perform each of the operations in turn, and then save a copy of the result from the top of the
stack into a global or static variable, (possibly popping it off the stack if it won't be needed there
immediately)
20