Unit 3
Unit 3
Prepared By:
Aarati Gangshetty
Unit III – 2-D, 3-D Transformations and Projections
• Syllabus
Unit III 2-D, 3-D Transformations and Projections 07 Hours
2-D transformations: introduction, homogeneous coordinates, 2-D
transformations - Translation, scaling, rotation and shear, rotation about an
arbitrary point.
Department of Computer
Computer Graphics 2
Engineering
Introduction
• Major asset of computer graphics is the ease with which certain
alterations to a picture may be performed. Like,
– Viewing a building from different angles
– Zooming in and out
– Changing positions of a character / sub picture
– Changing the size of a graph
• These alterations are easy to perform as images are stored as a series of
numbers in the computer. These numbers may be modified by
mathematical operations called transformations
• Computer images are generated from a series of line segments which are
represented by the coordinates of their endpoints.
• Transformations are expressed in terms of matrix multiplications
Department of Computer
Computer Graphics 3
Engineering
Matrices
• Matrix multiplication is possible on two matrices M1 ( R1, C1) and M2
(R2, C2) only if C1 = R2. The resultant is matrix M3(R1, C2)
• E.g.
1 2 3 1 0 -1 7
4 5 6 -1 2 -1 16
* =
7 8 9 0 1 -1 25
I = 0 1 0
0 0 1
Department of Computer
Computer Graphics 4
Engineering
Basic Transformations
• Scaling Transformation
• Rotation Transformation
• Translation Transformation
Purposes:
– To move the position of objects
– To alter the shape / size of objects
– To change the orientation of objects
Department of Computer
Computer Graphics 5
Engineering
2D Transformation
(x’,y’)
(tx,ty)
(x,y)
Translation
• Given: P ( x, y )
P ( 3.7, 4.1)
T (7.1,8.2)
T (t x , t y )
• Two-Dimensional rotation
– Rotation axis and angle are specified for rotation r
– Convert coordinates into polar form for calculation
r
x r cos y y sin
– Example, to rotation an object with angle a
• The new position coordinates
x' r cos( ) r cos cos r sin sin x cos y sin
y ' r sin( ) r cos sin r sin sin x sin y cos
• In matrix format
cos sin
R P' R P
sin cos
about a point (x, y )
• Rotation r r
2
1 6
0
1 2 3 4 5 6 7 8 9 10
x
• Positive angles are measured counterclockwise (from x
towards y)
• For negative angles, you can use the
identities:Clockwise
– cos(-q) = cos(q) and sin(-q)=-sin(q)
Scaling
(x,y)
Scaling
– If the scale factor had been greater than 1, it
would be larger and farther away.
WATCH OUT: Objects grow and move!
y
6
3 6 9
3 3
2
1 2 3
1 1
0
1 2 3 4 5 6 7 8 9 10
x
Note: House shifts position relative to origin
Scaling
• Given: P ( x, y ) P (1.4,2.2)
S ( s x , s y ) S (3,3)
Rotate Shear
x
y
z
3D Point Homogenous Coordinate
A 3D point P is represented in
homogeneous coordinates by a 4-dim. Vect:
x
y
P
z
1
3D Point Homogenous Coordinate
P T P
3D Translation
An object is translated in 3D dimensional by
transforming each of the defining points of the
objects .
3D Translation
An Object represented as a set of polygon surfaces, is translated
by translate each vertex of each surface and redraw the polygon
facets in the new position.
Inverse Translation:
T (t , t , t ) T ( t , t , t )
1
x y z x y z
3D Rotation
Rotation Transformations
• In 2D, rotation is about a point. In 3D, rotation is about an axis
– In general, rotations are specified by a rotation axis and an angle
• This axis can be a major (x, y, z) or an arbitrary axis in space
– Rotation about the z axis: In xy plane
– Rotation about the y axis: In xz plane
– Rotation about the x axis: In yz plane
– Rotation about an arbitrary axis
Department of Computer
Computer Graphics 37
Engineering
Rotation About a Major Axis
x ' cos sin 0 0 x
y ' sin cos 0 0 y
About ‘z’ :
z ' 0 0 1 0 z In xy plane
1 0 0 0 1 1
x ' 1 0 0 0 x
y ' 0 cos sin 0 y
About ‘x’ :
z ' 0 sin cos 0 z In yz plane
1 0 0 0 1 1
Department of Computer
Computer Graphics 38
Engineering
3D Scaling
Scaling
• It is used to resize the object in 3D space.
• We can apply uniform as well as non uniform
scaling by selecting proper scaling factor.
• Scaling in 3D is similar to scaling in 2D. Only
one extra coordinate need to consider into it.
Scaling
• Simple coordinate axis scaling can be
𝑌
Scali
performed as below,
ng
Z
Example- Scaling
• Example: - Scale the line with coordinates
and respectively with scale factor .
y
1 0 0 0
(x2,y2,z2) 0 1 0 0
T
0 0 1 0
(x1,y1,z1) x1 y1 z1 1
z
Translate the arbitrary axis back to original position (T-1)
y
(x2,y2,z2)
1 0 0 0
0 1 0 0
T-1 =
(x1,y1,z1) 0 0 1 0
x x1 y1 z1 1
z
Rotate the arbitrary axis about x axis ( Rx )
1 0 0 0
y 0 cos I sin I 0
Rx
0 sin I cos I 0
(0,b,c)
(a,b,c) 0 0 0 1
I 1 0 0 0
0 c / v b / v 0
x
Rx
0 b / v c / v 0
z
0 0 0 1
1 0 0 0
0 c / v b / v 0
Rx =
-1
0 b / v c / v 0
0 0 0 1
Rotate the arbitrary axis about y axis ( Ry )
cos J 0 sin J 0
y 0 1 0 0
Ry
sin J 0 cos J 0
(a,b,c) 0 0 0 1
v/l 0 a/l 0
v l 0
J x 1 0 0
Ry
a /l 0 v/l 0
z
0 0 0 1
v/l 0 a/l 0
0 1 0 0
Ry = a / l
-1
0 v/l 0
0 0 0 1
Rotate the object about z axis ( Rz)
cos sin 0 0
sin cos 0 0
Rz
0 0 1 0
0 0 0 1
Rotation About an Arbitrary Axis
Rθ = T.Rx.Ry.Rz.Ry-1.Rx-1.T-1
Rθ = v/l 0 a / l 0
1 0 0 0 1 0 0 0
0 c / v b / v 0 1 0 0
0 1 0 0 0
0 0 1 0 0 b / v c / v 0 a /l 0 v / l 0
x1 y1 z1 1 0 0 0 1 0 0 0 1
cos sin 0 0 v/l 0 a/l 0 1 0 0 0
sin 0 1 0 0 c / v b / v 0
cos 0 0 0
0 0 1 0 a /l 0 v /l 0 0 b / v c / v 0
0 0 0 1 0 0 0 1 0 0 0 1
1 0 0 0
0 1 0 0
0 0 1 0
x1 y1 z1 1
Projection