Computer-Graphics U3 PDF
Computer-Graphics U3 PDF
Computer-Graphics U3 PDF
in
UNIT 3
Two Dimensional Transformations
In many applications, changes in orientations, size, and shape are accomplished with
geometric transformations that alter the coordinate descriptions of objects.
Other transformations:
Reflection
Shear
We translate a 2D point by adding translation distances, tx and ty, to the original coordinate
position (x,y):
x' = x + tx, y' = y + ty
1 0t x
0 1 t y
0 01
Then we can rewrite the formula as:
x' 1 0 tx x
0 t y
y' = 1 y
1 0 01 1
For example, to translate a triangle with vertices at original coordinates (10,20), (10,10),
(20,10) by tx=5, ty=10, we compute as followings:
x' 1 0 5 10 1*10 0 * 20 5 *1 15
y' = 0 1 10 20 = 0 *10 1* 20 10 *1 = 30
1 0 01 1 0 *10 0 * 20 1*1 1
Translation of vertex
(10,10):
x' 1 0 5 20 1* 20 0 *10 5 *1 25
y' =0 1 10 10 = 0 * 20 1*10 10 *1 = 20
1 0 01 1 0 * 20 0 *10 1*1 1
The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.
Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10)
by tx=15, ty=5. Roughly plot the original and resultant triangles.
To rotate an object about the origin (0,0), we specify the rotation angle ?. Positive and
negative values for the rotation angle define counterclockwise and clockwise rotations
respectively. The followings is the computation of this rotation for a point:
Alternatively, this rotation can also be specified by the following transformation matrix:
cos sin 0
0
sin cos
0 0 1
Then we can rewrite the formula as:
1 0 0 1 1
For example, to rotate a triange about the origin with vertices at original coordinates (10,20),
(10,10), (20,10) by 30 degrees, we compute as followings:
0 0 1 0 0 1 0 0 1
Rotation of vertex (10,20):
2
Smartzworld.com 2 jntuworldupdates.org
Smartworld.asia Specworld.in
The resultant coordinates of the triangle vertices are (-1.34,22.32), (3.6,13.66), and
(12.32,18.66) respectively.
Alternatively, this scaling can also be specified by the following transformation matrix:
sx 0 0
0 s 0
y
0
0 1
Then we can rewrite the formula as:
x' sx 0 0 x
y' = 0 s 0 y
y
1 0 01 1
For example, to scale a triange with respect to the origin, with vertices at original
coordinates (10,20), (10,10), (20,10) by sx=2, sy=1.5, we compute as followings:
x' 20 0 10 2 *10 0 * 20 0 *1 20
y' = 0 1.5 0 20 = 0 *10 1.5 * 20 0 *1 = 30
1 0 0 1 1 0 *10 0 * 20 1*1 1
Smartzworld.com 3 jntuworldupdates.org
Smartworld.asia Specworld.in
x' 2 0 0 20 2 * 20 0 *10 0 *1 40
y' = 0 1.5 0 10 = 0 * 20 1.5 *10 0 *1 = 15
1 0 01 1 0 * 20 0 *10 1*1 1
The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively.
Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) by
sx=1.5, sy=2, with respect to the origin. Roughly plot the original and resultant
triangles.
C'=A(BC)
C' = (AB)C
The advantage of computing it using C' = (AB)C instead of C'=A(BC) is that, for
computing the 3 vertices of the triangle, C1, C2, C 3, the computation time is shortened:
Using C'=A(BC):
1. compute B C1 and put the result into I1
2. compute A I1 and put the result into C1'
3. compute B C2 and put the result into I2
4. compute A I2 and put the result into C2'
5. compute B C3 and put the result into I3
6. compute A I3 and put the result into C3'
Using C' = (AB)C:
- compute A B and put the result into M
- compute M C1 and put the result into C1''
- compute M C2 and put the result into C2'
- compute M C3 and put the result into C3
Smartzworld.com 4 jntuworldupdates.org
Smartworld.asia Specworld.in
Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30
degrees and then translate it by tx=5, ty=10,
0 0 1 0 0 1
And we compute the translation matrix:
1 0 5
A= 0 1 10
0 0 1
Then, we compute M=AB
1 0 5 0.866 0.5 0
M= 0 1 10 0.5 0.866 0
0 0 1 0
0 1
1* 0.866 0 * 0.5 5 * 0 1* 0.5 0 * 0.866 5 * 0 1* 0 0 * 0 5 *1
M= 0 * 0.866 1* 0.5 10 * 0 0 * 0.5 1* 0.866 10 * 0 0 * 0 1* 0 10 *1
0 0 1
Then, we compute the transformations of the 3 vertices:
Transformation of vertex (10,20):
Transformation of vertex
(10,10):
Smartzworld.com 5 jntuworldupdates.org
Smartworld.asia Specworld.in
The resultant coordinates of the triangle vertices are (3.66,32.32), (8.66,23.66), and
(17.32,28.66) respectively.
This means that if we want to translate and rotate an object, we must be careful about the
order in which the composite matrix is evaluated. Using the previous example, if you
compute C' = (AB)C, you are rotating the triangle with B first, then translate it with A,
but if you compute C' = (BA)C, you are translating it with A first, then rotate it with B.
The result is different.
Exercise: Translate a triangle with vertices (10,20), (10,10), (20,10) by t x=5, ty=10 and then
rotate it about the origin by 30 degrees. Compare the result with the one obtained
previously: (3.66,32.32), (8.66,23.66), and (17.32,28.66) by plotting the original
triangle together with these 2 results.
1 0 t x1 1 0 tx2 1*1 0 * 0 t x1 * 0 1* 0 0 *1 t x1 * 0 1* t x 2 0 * t y 2 t x1 *1
0 t 0 1t
1 y1 y2 = 0 *1 1* 0 t y1 * 0 0 * 0 1*1 t y1 * 0 0 * t x 2 1* t y 2 t y1 *1
0 0 1 0 0 1 0 *1 0 * 0 1* 0 0 * 0 0 *1 1* 0 0 * t x 2 0 * tu 2 1*1
1 0 t x1 t x 2
01 t t
= y1 y2
0 0 1
Smartzworld.com 6 jntuworldupdates.org
Smartworld.asia Specworld.in
Rotations
By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the
origin, it is equal to rotating the shape once by an angle ? + a about the origin.
Similarly, this additive property can be demonstrated by composite transformation matrix:
0 0 1 0 0 1
cos cos ( sin ) * sin 0 * 0 cos * ( sin ) ( sin ) * cos 0 * 0 cos * 0 ( sin ) * 0 0 *1
= sin cos cos * sin 0*0 sin * ( sin ) cos * cos 0*0 sin * 0 cos * 0 0 *1
0 * cos 0 * sin 1* 0 0 * ( sin ) 0 * cos 1* 0 0 * 0 0 * 0 1 *1
cos( ) sin( ) 0
0
= sin( ) cos( )
0 0 1
s x1 0 0 sx2 0 0
0 s 0 0 s 0
y1 y2
0 0 1 0 0 1
s x1 * s x 2 0 * 0 0 * 0 s x1 * 0 0 * s y 2 0 * 0 s x1 * 0 0 * 0 0 *1
= 0 *s x2 s y1 * 0 0*0 0*0 s y1 * s y 2 0*0 0*0 s y1 * 0 0 *1
0*s 0 * 0 1* 0 0*0 0*s 1* 0 0*0 0*0 1*1
x2 y2
s x1 * s x 2 0 0
= 0 s *s 0
y1 y2
0 0 1
This demonstrates that 2 successive scalings with respect to the origin are multiplicative.
Smartzworld.com 7 jntuworldupdates.org
Smartworld.asia Specworld.in
- Translate the object so that the pivot-point position is moved to the origin.
- Rotate the object about the origin.
- Translate the object so that the pivot point is returned to its original position.
1 0 xr cos sin 0 1 0 xr
y y
0 1 r sin cos 0 0 1 r
0
0 1 0 0 1 0 0 1
cos sin xr 1 0 xr
y 0 y
= sin cos r 1 r
0 0 1 0 0 1
cos sin x r cos y r sin xr
0 0
1. Translate the object so that the fixed point coincides with the origin.
2. Scale the object with respect to the origin.
3. Use the inverse translation of step 1 to return the object to its original position.
Smartzworld.com 8 jntuworldupdates.org
Smartworld.asia Specworld.in
1 0 xf sx 0 0 1 0 xf sx 0 x f (1 s x )
0
1 yf 0 sy 0 0 1 y
f = 0 s y y f (1 s y )
0 0 1 0 0 1 0 0 1 0 0 1
Scaling along an arbitrary direction is not as simple as scaling along the x-y axis. The
procedure of scaling along and normal to an arbitrary direction (s1 and s2), with respect to
the origin, is:
1. Rotate the object so that the directions for s1 and s2 coincide with the x and y axes
respectively.
2. Scale the object with respect to the origin using (s1, s2).
3. Use an opposite rotation to return points to their original orientation.
Reflection
Reflection about the x axis:
x' 1 0 0 x
y' = 0 1 0 y
1 0 01 1
ie. x'=x; y'=-y
Smartzworld.com 9 jntuworldupdates.org
Smartworld.asia Specworld.in
1 0 01 1
ie. x'=-x; y'=-y
Shear
X-direction shear, with a shearing parameter shx,
relative to the x-axis:
x' 1 sh x 0 x
y' =0 1 0 y
1 0 0 1 1
ie. x'=x+y*shx; y'=-x
Exercise: Think of a y-direction shear, with a shearing parameter shy, relative to the y-axis.
Suppose we want to transform object descriptions from the xy system to the x'y' system:
cos( ) sin( ) xr 1 0 x0
y 0 y
sin( ) cos( ) r 1 0
0 0 1 0 0 1
Smartzworld.com 10 jntuworldupdates.org