Computer Graphics Chapter Five

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 82

Chapter 5

Geometrical Transformations

1
outline
 3D Transformation
 Matrix Representation
 Homogeneous Coordinates
 Combination of Transformations

2
Geometric transformation
 A geometric transformation in computer graphics and multimedia
applications refers to a change in position, size, shape or orientation of
an object or image.
 Transformations are a fundamental part of the computer graphics.
Transformations are the movement of the object in Cartesian plane .
 These transformations can be performed using mathematical algorithms
and matrices to manipulate the coordinates of an object in a 2D or 3D
space.
3
Cont..
 These transformations are typically performed using matrix
operations, where the object’s coordinates are transformed according
to a transformation matrix.
 The result of these transformations can be visualized on a computer
screen to produce the desired effect.
 The transformed coordinates are then used to render the object in its
new position, orientation, size, or shape
4
TYPES OF TRANSFORMATION

 There are two types of transformation in computer


graphics.

1) 2D transformation

2) 3D transformation
 Types of 2D and 3D transformation

1) Translation 2) Rotation 3) Scaling


4) Shearing 5) reflection

5
2D Transformation
 2D transformations refer to the transformations applied to objects or images in a 2D plane.

 Some common types of 2D transformations include:

1. Translation: A translation moves an object from one position to another without changing

its orientation or size.

2. Rotation: A rotation changes the orientation of an object around a fixed point, known as

the origin.

3. Scaling: A scaling transformation changes the size of an object, either uniformly

(isotropic scaling) or non-uniformly (anisotropic scaling).

6
Cont..
4. Shear: A shear transformation changes the shape of an object,
moving its parallel sides closer together or further apart.

5. Reflection: A reflection transformation creates a mirror image of an


object across a specified axis.

7
3D Transformation
 When the transformation takes place on a 3D plane, it is called 3D
transformation

 The translation, scaling and rotation transformations used for 2D can be


extended to three dimensions.

 In 3D, each transformation is represented by a 4x4 matrix.


 Using homogeneous coordinates it is possible to represent each type of
transformation in a matrix form and integrate transformations into one
matrix
 To apply transformations, simply multiply matrices, also easier in
hardware and software implementation

8
3-D Transformation
 In very general terms a 3D model is a mathematical representation
of a physical entity that occupies space.
 In more practical terms, a 3D model is made of a description of its
shape and a description of its color appearance.
 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 like
Translation, Scaling, Rotation, Shear, etc.
9
Cont..
 Properties of 3-D Transformation:
 Lines are preserved,
 Parallelism is preserved,
 Proportional distances are preserved.

10
Three Dimensional Transformations
 The geometric transformations play a vital role in generating images
of three Dimensional objects with the help of these transformations.
 The location of objects relative to others can be easily expressed.
 Sometimes viewpoint changes rapidly, or sometimes objects move in
relation to each other.

11
Homogeneous Coordinates
 The geometry we want to transform is obviously three-dimensional.

However, we will gain two key advantages by moving from three component
Cartesian coordinates to four-component homogeneous coordinates.

These are:-

1) the ability to apply perspective and

2) the ability to translate (move) the model using only a linear transform.

12
Cont..
 That is, we will be able to get all the rotations, translations, scaling, and
projective transformations we need by doing matrix multiplication if
we first move to a four-coordinate system.
 More accurately, the projective transformation is a key step in creating
perspective, and it is the step we must perform in our shaders.
 Homogeneous coordinates can represent directions

13
 Homogeneous coordinates: 4 components
 Transformation matrices: 4×4 elements
b c
a p
d e f
q 
g h i r
 0 0  1
0

 W H Y WE U S E TRAN S FO RM ATI O N
Transformation are used to position objects, to shape object, to change
viewing positions, and even how something is viewed.

14
Transformation Matrices

 Transformation matrix is a basic tool for transformation.


 A matrix with n x m dimensions is multiplied with the coordinate of
objects.
 Usually 3 x 3 or 4 x 4 matrices are used for transformation.
 For example, consider the following matrix for various operation.

15
Matrix Representation of 2D Transformation

16
Matrix Representation of 3D Transformation

17
Translation

 It is the movement of an object from one position to another position.


Translation is done using translation vectors.
 There are three vectors in 3D instead of two. These vectors are in x,
y, and z directions.
 Translation in the x-direction is represented using T x.

 The translation is y-direction is represented using T y.

 The translation in the z- direction is represented using T z.

18
cont..
 If P is a point having co-ordinates in three directions (x, y, z) is
translated, then after translation its coordinates will be (x 1 y1 z1) after
translation.
 Tx Ty Tz are translation vectors in x, y, and z directions respectively.

x =x+ Tx
1

y =y+Ty
1

z =z+ Tz
1

19
Cont..

 Moving of object is called translation.


 In 3 dimensional homogeneous coordinate
representation , a point is transformed from position

P = ( x, y , z) to P’=( x’, y’, z’)

This can be written as: Using P’= T . P where T is


translation vector

20
original

translation along y, or V
= (0, k, 0)

TRANSLATION

21
Cont..
 Three-dimensional transformations are performed by transforming each vertex of the
object. If an object has five corners, then the translation will be accomplished by
translating all five points to new locations.
 Following figure 1 shows the translation of point and figure 2 shows the translation
of the cube.

22
Cont..
 Matrix for translation

 Matrix representation of point translation


Point shown in fig is (x, y, z). It become (x1,y1,z1) after translation.
Tx Ty Tz are translation vector.

23
Example

 Example: A point has coordinates in the x, y, z direction i.e., (5, 6, 7). The translation is
done in the x-direction by 3 coordinate and y direction by 3 coordinates and in the z-
direction by 2 coordinates. Shift the object. Find coordinates of the new position.
 Solution: Co-ordinate of the point are (5, 6, 7)
Translation vector in x direction = 3
Translation vector in y direction = 3
Translation vector in z direction = 2
Translation matrix is

24
Cont..
 Multiply co-ordinates of point with translation matrix

= [5+0+0+3, 0+6+0+3, 0+0+7+2, 0+0+0+1] = [8,9,9,1]


 x becomes x =8
1

y becomes y =9
1

z becomes z1=9
25
Exercise

Perform translation transformation on the following figure where the given


translation Vector are Tx = 2, Ty = 4, Tz = 6.

26
Solution: On applying Translation Transformation we get
corresponding points

27
Cont..
 After performing translation transformation over the Fig.1, it will
look like as below

28
3-D SCALING
 You can change the size of an object using scaling transformation
 In the scaling process , you either expand or compress the
dimensions of the object .
 Scaling can be achieved by multiplying the original
coordinates of the object with scaling factor to get the desired
result

29
3-D SCALING

• Scaling factor determines whether the object size is to be increased


or reduced.
• If scaling factor > 1, then the object size is increased.
• If scaling factor < 1, then the object size is reduced
 The general transformation matrix for scaling is

 x '   sx 0 0 0  x 
y ' 0 y   
0  y 
    0 s 0
 z '  0  z 
 0  
0
 1   1 1 
30 sz
Cont..

31
3-D SCALING

Scaling in x,y,z-direction by
factor a, e, j-units respectively.

32
Original scale all axes scale Y axis offset from origin

Scaling

33
Cont.
Let-
This scaling is achieved by using the
 Initial coordinates of the object O =
following scaling equations-
(Xold, Yold,Zold)
X = Xold x Sx
new
 Scaling factor for X-axis = Sx
Y = Yold x Sy
new
 Scaling factor for Y-axis = Sy
Z = Zold x Sz
new
 Scaling factor for Z-axis = Sz
 New coordinates of the object O
after scaling = (Xnew, Ynew, Znew)
34
Cont.
 In Matrix form, the above scaling equations may be represented as-

 Example: Given a 3D object with coordinate points A(0, 3, 3), B(3, 3,


6), C(3, 0, 1).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.
35
Cont.
Solution- For Coordinates A(0, 3, 3)
Let the new coordinates of A after
 Given-
scaling = (Xnew, Ynew, Znew).
 Old coordinates of the object Applying the scaling equations, we
have-
=A (0, 3, 3), B(3, 3, 6), C(3, 0, 1)
X
new = Xold x Sx = 0 x 2 = 0
 Scaling factor along X axis = 2 Y = Yold x Sy = 3 x 3 = 9
new
Z = Zold x Sz = 3 x 3 = 9
new
 Scaling factor along Y axis = 3 Thus, New coordinates of corner A
 after scaling = (0, 9, 9).
Scaling factor along Z axis = 3
36
Cont.
For Coordinates B(3, 3, 6) For Coordinates C(3, 0, 1)
 Let the new coordinates of B after Let the new coordinates of C
scaling = (Xnew, Ynew, Znew). after scaling = (Xnew, Ynew, Znew).
 Applying the scaling equations, we Applying the scaling equations,
have- we have-
X
 Xnew = Xold x Sx = 3 x 2 = 6 new = Xold x Sx = 3 x 2 = 6
Y
 Ynew = Yold x Sy = 3 x 3 = 9 new = Yold x Sy = 0 x 3 = 0
Z = Z x S = 1 x 3 = 3
 Znew = Zold x Sz = 6 x 3 = 18 new old z
Thus, New coordinates of
 Thus, New coordinates of corner B
after scaling = (6, 9, 18). corner C after scaling = (6, 0,
37 3).
Example. Scale the cube below using scaling factor of sx=2,sy=3 and sz=2

38
Cont.
 3-D Rotation
It is a process of changing the angle of the object.
Rotation can be clockwise or anticlockwise.
For 2D we describe the angle of rotation, but for a 3D angle of rotation and axis of
rotation are required.
The axis can be either x or y or z.

39
Cont.
 Rotation about an arbitrary axis
 There are three kinds of arbitrary rotation, here we can rotate an object just
parallel(or along) a specific axis so that the coordinate about which the object
rotates remains unchanged and the rest two of the coordinates get changes.
 There are three kinds of such rotations that are possible:
 Rotation about the X-axis,
 Rotation about the Y-axis,
 Rotation about the Z-axis.

40
Cont.
 1) Rotation about the x-axis:
 In this kind of rotation, the object is rotated parallel to the x-axis (principal axis),
where the x coordinate remains unchanged and the rest of the two
coordinates y and z only change.
 Consider a point with initial coordinate P(x,y,z) in 3D space is made to rotate
parallel to the principal axis(x-axis).
 The coordinate position would change to P'(x,y,z).

41
Cont.
 A rotation transformation matrix is used to calculate the new position coordinate
P’, which shown as below:
 This rotation is achieved by using the following rotation equations-
 Xnew = Xold
 Ynew = Yold x cosθ – Zold x sinθ
 Znew = Yold x sinθ + Zold x cosθ

 OR in matrix form

42
Cont.
 P(Xnew Ynew Znew 1) is new position for coordinate P(X Y Z 1).

43
2) Rotation about the y-axis:
This rotation is achieved by using the
following rotation equations-
X
new = Zold x sinθ + Xold x cosθ
Y
new = Yold
Z
new = Yold x cosθ – Xold x sinθ
In Matrix form

44
3) Rotation about the z-axis:
 This rotation is achieved by using the following rotation equations-

 Xnew = Xold x cosθ – Yold x sinθ

 Ynew = Xold x sinθ + Yold x cosθ

 Znew = Zold
In matrix form:

45
Cont.
 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.
 Solution-
 Given-
 Old coordinates = (Xold, Yold, Zold) = (1, 2, 3)
 Rotation angle = θ = 90º
For X-Axis Rotation-
 Let the new coordinates after rotation = (X , Y , Z ).
new new new
 Applying the rotation equations, we have-
 Xnew = Xold = 1
 Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3
 Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2
46
Cont.
 Thus, New coordinates after rotation = (1, -3, 2).
For Y-Axis Rotation-
 Let the new coordinates after rotation = (X , Y , Z ).
new new new
Applying the rotation equations, we have-
X
new = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3

 Ynew = Yold = 2
 Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1
 Thus, New coordinates after rotation = (3, 2, -1).

47
Cont.
For Z-Axis Rotation-
 Let the new coordinates after rotation = (X , Y , Z ).
new new new
 Applying the rotation equations, we have-
 Xnew = Xold x cosθ – Yold x sinθ = 1 x cos90° – 2 x sin90° = 1 x 0 – 2 x 1 = -2
 Ynew = Xold x sinθ + Yold x cosθ = 1 x sin90° + 2 x cos90° = 1 x 1 + 2 x 0 = 1
 Znew = Zold = 3
 Thus, New coordinates after rotation = (-2, 1, 3).
 Note: Rotation angle in Counter-clockwise direction is always considered +ve, while
in the clockwise direction rotation angle is always considered -ve.
 It is a common convention agreed for 3D rotation.
48
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.
 Consider a point object O has to be reflected in a 3D plane.
Let-
•Initial coordinates of the object O = (Xold, Yold, Zold)

•New coordinates of the reflected object O after reflection = (Xnew, Ynew,Znew)

49
Cont.
Reflection Relative to XY Plane:
 In 3 dimensions, there are 3 possible types This reflection is achieved by using the
of reflection- following reflection equations-
X
new = Xold
Y = Yold
new
Z = -Zold
new
In Matrix form, the above reflection
equations may be represented as-

50
Cont.
Reflection Relative to YZ Plane: Reflection Relative to XZ Plane:
 This reflection is achieved by using the This reflection is achieved by using

following reflection equations- the following reflection equations-


X
 X
new = -Xold new = Xold

 Ynew = Yold Y = -Yold


new

 Znew = Zold Z = Zold


new

 In Matrix form, the above reflection


In Matrix form, the above reflection
equations may be represented as- equations may be represented as-

51
Example
 Given a 3D triangle with coordinate points A(3, 4, For Coordinates A(3, 4, 1)
1), B(6, 4, 2), C(5, 6, 3). Apply the reflection on the Let the new coordinates of
XY plane and find out the new coordinates of the corner A after reflection =
object. (Xnew, Ynew, Znew).
Solution- Applying the reflection

 Given- equations, we have-


X
 new = Xold = 3
Old corner coordinates of the triangle = A (3, 4, 1),
Y
B(6, 4, 2), C(5, 6, 3) new = Yold = 4
Z
 new = -Zold = -1
Reflection has to be taken on the XY plane
Thus, New coordinates of
corner A after reflection = (3,
4, -1).
52
Cont.
For Coordinates B(6, 4, 2) For Coordinates C(5, 6, 3)
 Let the new coordinates of corner B after Let the new coordinates of corner C

reflection = (Xnew, Ynew, Znew). after reflection = (Xnew, Ynew, Znew).


Applying the reflection equations, we
 Applying the reflection equations, we have-
have-
 Xnew = Xold = 6
X
new = Xold = 5
 Ynew = Yold = 4 Y
new = Yold = 6
 Znew = -Zold = -2 Z
new = -Zold = -3
 Thus, New coordinates of corner B after Thus, New coordinates of corner C
reflection = (6, 4, -2). after reflection = (5, 6, -3).
Thus, New coordinates of the triangle
after reflection = A (3, 4, -1), B(6, 4, -
2), C(5, 6, -3).
53
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 shape
can be changed along X direction, Y
direction as well as Z direction.
 So, there are three versions of shearing-

54
Cont.
Shearing in X Axis-
 Consider a point object O has to be sheared in a
Is achieved by using the following
3D plane. equations-
X
Let- new = Xold
 Initial coordinates of the object O = (X , Y , Y
old old new = Yold + Shy x Xold
Zold) Z = Z + Sh x X
new old z old
 Shearing parameter towards X direction = Shx InMatrix form, the above shearing
 Shearing parameter towards Y direction = Shy equations may be represented as-
 Shearing parameter towards Z direction = Shz
 New coordinates of the object O after shearing =
(Xnew, Ynew, Znew)

55
Cont.
Shearing in Y Axis- Shearing in Z Axis-
 Is achieved by using the following shearing Is achieved by using the following

equations- shearing equations-


X
 X
new = Xold + Shx x Yold
new = Xold + Shx x Zold
Y = Yold + Shy x Zold
 Ynew = Yold new
Z = Zold
 Znew = Zold + Shz x Yold new
InMatrix form, the above shearing
 In Matrix form, the above shearing equations
may be represented as- equations may be represented as-

56
Example
Shearing in X Axis-
Given a 3D triangle with points (0, 0, 0), (1, 1, 2) and  For Coordinates A(0, 0, 0)
(1, 1, 3). Apply shear parameter 2 on X axis, 2 on Y  Let the new coordinates of corner A

axis and 3 on Z axis and find out the new coordinates after shearing = (Xnew, Ynew, Znew).
 Applying the shearing equations, we
of the object.
have-
Solution- X
new = Xold = 0
 Given- Y = Yold + Shy x Xold = 0 + 2 x 0 = 0
new
 Old corner coordinates of the triangle = A (0, 0, 0), Z = Zold + Shz x Xold = 0 + 3 x 0 = 0
new
B(1, 1, 2), C(1, 1, 3)
 Thus, New coordinates of corner A
 Shearing parameter towards X direction (Shx) = 2
after shearing = (0, 0, 0).
 Shearing parameter towards Y direction (Shy) = 2
 Shearing parameter towards Y direction (Shz) = 3
57
Example
  For Coordinates C(1, 1, 3)
For Coordinates B(1, 1, 2)
 Let the new coordinates of corner C after
 Let the new coordinates of corner B after
shearing = (Xnew, Ynew, Znew).
shearing = (Xnew, Ynew, Znew).
 Applying the shearing equations, we have-
 Applying the shearing equations, we have- X
new = Xold = 1
 Xnew = Xold = 1
Y = Yold + Shy x Xold = 1 + 2 x 1 = 3
new
 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3 Z = Zold + Shz x Xold = 3 + 3 x 1 = 6
new
 Znew = Zold + Shz x Xold = 2 + 3 x 1 = 5  Thus,New coordinates of corner C after
 Thus, New coordinates of corner B after shearing = (1, 3, 6).
shearing = (1, 3, 5).  Thus, New coordinates of the triangle after
shearing in X axis = A (0, 0, 0), B(1, 3, 5),
C(1, 3, 6).

58
Composite Transformations
 A number of transformations or sequence of transformations can be combined into
single one called as composition.
 The resulting matrix is called as composite matrix.
 The process of combining is called as concatenation.
 For example, if we want to transform a large number of points by the same
sequence of three matrix transformations: a rotation R1, followed by a scaling S1
and finally another rotation R2. In this case, the overall transformation is.

P’=R2S1R1P

59
Cont.
 Therefore, we can implement this by composing R2, S1 and R1 into a single
composite matrix C, and then multiplying each point by C.
 Suppose, we’re asked to perform three or more different sorts of transformations
over a point(P0) simultaneously which is placed in 3D space, and let us assume that

these transformations are T1, T2, and T3 respectively, then in this case what we’ll
do?
 So, we will see the following solutions:

60
Cont.
 a) Obviously, first by applying series of Transformations one by one over the
coordinates of the object sequentially.
 First we performed transformation T1, then P0 become transformed to P1.

 Secondly, we perform transformation T2 and the point P1 become transformed to

P2.

 Lastly, we perform transformation T3 and we get the final result i.e; P3,and we will

get our final transformed point coordinate(P3).

61
Cont.
 These are sequence of transformations undergo here:

 P1[X Y Z 1] = P0[X0 Y0 Z0 1].T1 ⇨ P1[X Y Z] = [X1 Y1 Z1]

 P2[X Y Z 1] = P1[X1 Y1 Z1 1].T2 ⇨ P2[X Y Z] = [X2 Y2 Z2]

 P3[X Y Z 1] = P2[X2 Y2 Z2 1].T3 ⇨ P3[X Y Z] = [X3 Y3 Z3]

 Note: Here T1, T2, T3 correspond to their transformation matrix condition.

 But the idea that is considered in composite transformation is slightly different,


we’ll
62
discuss as follows:
Cont.
 b) Second solution, by applying Composite transformation in a single shot.

 As its name suggests itself composite, here we compose two or more than two
transformations together and calculate a resultant(R) transformation matrix by
multiplying all the corresponding transformation matrix conditions with each other.

 The same equivalent result that we got over Point P0 and transformed it into P3 in
the above example can also be achieved by directly multiplying resultant R with the
point P0 rather than performing transformations T1, T2, and T3 sequentially one
after one.
63
Cont.
 R=[T1*T2*T3]
 P3[X Y Z 1] = P0[X0 Y0 Z0 1].R ⇨ P3[X Y Z] = [X3 Y3 Z3]
 Example: Consider we are given with a cube “OABCDEFG” over which we want to
perform:
Translation transformation(T1) if translation
distances are tx=2, ty=3, tz=2 ,then
Scaling transformation(T ) if scaling factors
2
are sx=2, sy=1, sz=3 and lastly perform,
Shearing transformation(T ) in x-direction
3
if shearing factors are sy=2 and sz=1.

64
Cont.
Solution: Applying each successive transformations separately
 First perform translation using the translation transformation
matrix:

 Forcoordinate A[0 0 4], the newly


T1=
translated coordinate would be A1:

 Now apply this translation transformation matrix condition  A1[xy z 1]=A[0 0 4 1]*
over the coordinates: = [2 3 6 1]
A1[x y z]= [2 3 6 ]
 For coordinate O[0 0 0], the newly translated coordinate
would be O1:
65
Cont.
 For coordinate:
 For coordinate B[0 4 2], the newly translated  C[2 4 0], C :[4 7 2] D[2 2 4], D :[4 5 6]
1 1
coordinate would be B1:  E[2 0 0], E1:[4 3 2] F[0 0 2], F1:[2 3 4]
 G[2 0 2], G1:[4 3 4]

 Continuing to compute for each coordinate we


will get the following translated coordinates:

66
Cont.

For coordinate O1[2 3 2], the newly
Secondly, we are said to perform Scaling
Scaled coordinate would be O2:
transformation T2:
 Use this scaling matrix:

T2 =

For coordinate A1[2 3 6], the newly


 Now apply this Scaling transformation Scaled coordinate would be A2:
matrix condition over the coordinates:

67
Cont.
 The scaled cube is:
 Continuing to compute for each coordinate we
will get the following scaled coordinates:
 B1[2 7 4], B2:[4 7 12]
 C1[4 7 2], C2:[8 7 6]
 D1[4 5 6], D2:[8 5 18]
 E1[4 3 2], E2:[8 3 6]
 F1[2 3 4], F2:[4 3 12]
 G1[4 3 4], G2:[8 3 12]

68
Cont.
Now, apply this Shearing
 Lastly, we perform Shearing transformation
transformation matrix condition over
T3 in x-direction: the coordinates:
 For coordinate O2[4 3 6], the newly
The Shearing transformation matrix for x-
Scaled coordinate would be O3:
direction is shown as:

69
Cont.

 For coordinate A2[4 3 18], the newly Continuing to compute for each

Scaled coordinate would be A3: coordinate we will get the following


Sheared coordinates:

B [4 7 12], B3:[4 15 16]


2
C [8 7 6], C :[8 23 14]
2 3
D [8 5 18], D :[8 21 26]
2 3
E [8 7 6], E :[8 19 14]
2 3
F [4 3 12], F :[4 11 16]
2 3
G [8 3 12], G :[8 19 20]
2 3
70
Cont.
 Finally, we get our resized slanted object in the x-direction after performing
transformations T1, T2 and T3.

71
Cont.
 Solution through Composite Transformation
 Through applying transformation T1, T2, and T3 one after one in sequential order the
same equivalent result could also be got by using the concept of Composite
Transformation.
 To perform composite transformation first we need to calculate the Resultant
Transformation matrix(R) by combining all the distinguished transformation matrix
representations together.

72
Cont.
 The resultant transformation matrix would be calculated as follows:
 The resultant transformation will be calculated by multiplying the Translation
transformation matrix with the Scaling transformation matrix and the resultant(R2)
multiplication of both will then be multiplied with the last given, Shearing
transformation matrix.

73
Cont.
 Now, multiply R2 with the Shearing transformation matrix to get resultant R:

 Now, apply this resultant transformation matrix condition over the coordinates:

74
Cont.
 For coordinate O[0 0 0], the new For coordinate A[0 0 4], the newly Scaled
Scaled coordinate would be O3: coordinate would be A3:

75
Cont.
 Continuing to compute for each Here, we get our final result in a single
coordinate we will get the shot:
following transformed
coordinates:
 B[0 4 2] = B3[4 15 16]
 C[2 4 0] = C3[8 23 14]
 D[2 2 4] = D3[8 21 26]
 E[2 0 0] = E3[8 19 14]
 F[0 0 2] = F3[4 11 16]
 G[2 0 2] = G3[8 19 20]
76
Cont.
 Advantage of using Composite matrices
 transformations become compact.
 The number of operations will be reduced.
 Rules used for defining transformation in form of equations are complex as
compared to matrix.

77
OpenGL Functions for 3D Transformations.
 In OpenGL, this translation would be specified by the command
glTranslatef( dx, dy, dz ); OR by glTranslated( dx, dy, dz );
 The translation will affect any drawing that is done after the command is given.
 Example: glTranslatef( 0, 0, 1 ); would translate objects by one unit in the Z direction.
 Scaling works in a similar way: Instead of one scaling factor, you need three.
 Command for scaling: glScalef( sx, sy, sz );
 You can use scaling by a factor of minus one to apply a reflection.
 For example, glScalef( 1, 1, -1 ); reflects objects through the xy-plane by reversing the
sign of the Z coordinate

78
Cont.
 The rotation function in OpenGL is glRotatef(r,ax,ay,az). You can also use glRotated.
 Here are a few examples of scaling, translation, rotation, and scaling in OpenGL:
 glScalef(2,2,2); // Uniform scaling by a factor of 2.
 glScalef(0.5,1,1); // Shrink by half in the x-direction only.
 glScalef(-1,1,1); // Reflect through the yz-plane. //
 glTranslatef(5,0,0); // Move 5 units in the positive x-direction
 glTranslatef(3,5,-7.5); // Move each point (x,y,z) to (x+3, y+5, z-7.5).

79
Cont.
 glRotatef(90,1,0,0); // Rotate 90 degrees about the x-axis.
// Moves the +y axis onto the +z axis
// and the +z axis onto the -y axis.
 glRotatef(-90,-1,0,0); // Has the same effect as the previous rotation.
 glRotatef(90,0,1,0); // Rotate 90 degrees about the y-axis.
// Moves the +z axis onto the +x axis
// and the +x axis onto the -z axis.

80
Cont.
 glRotatef(90,0,0,1); // Rotate 90 degrees about the z-axis.
// Moves the +x axis onto the +y axis
// and the +y axis onto the -x axis.
 glRotatef(30,1.5,2,-3); // Rotate 30 degrees about the line through
the points (0,0,0) and (1.5,2,-3).
 Remember that transforms are applied to objects that are drawn after the
transformation function is called, and that transformations apply to objects in the
opposite order of the order in which they appear in the code.

81
END
82

You might also like