Transcript Document

Computer Graphics
2D
Geometric Transformations
Faculty of Physical and Basic Education
Computer Science Dep.
2012-2013
E-mail:
[email protected]
[email protected]
Lecturer:
Azhee W. MD.
Lecture:Six
Geometric Transformations
 2D Transformation
 Translation
 Scaling
 Rotation
 Sharing
2
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
2D Transformation
 The operations that are applied to an object to
change its position, orientation, or size are called
geometric transformation






Some transformations:
Translation
Rotation
Scaling
Reflection
Shearing
3
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Translation
 a point (x,y) is translated to a new position (x1,y1)
by move it H units in the horizontal direction and
V units in vertical direction , mathematically this
can be represented as:
X1=X+H
y
Y1=Y+V
(x,y)
x
(0,0)
4
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Translation
 if H is positive, the point moves to the right,
if H is negative, the point move to the left.
 if V is positive, the point moves to the up,
if V is negative, the point move to the down.
 Remember that to move object we must translate every
point describing the object.
 To implement translation in matrix representation
 [x’ y’ 1] = [x y 1] *
1 0 0
0 1 0
H V 1
5
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Translation(example)
 Consider a triangle with vertices A(0,0),B(2,2) and
C(3,1),translate 2 units in the horizontal direction
and 1 unit in the Vertical direction
(2,2)
(3,1)
(0,0)
6
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Home work
Q)What was the required transformation to move
the green triangle to the red triangle? Here the green
triangle is represented by 3 points
triangle = { p1=(1,0), p2=(2,0), p3=(1.5,2) }
7
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Scaling
 An object can be made larger by increasing the
distance between the points describing the object.
 In general we can change the size of an object or
entire image by multiplying the distance between
points by an enlargement or reduction factor.
 This factor is called the scaling factor and the
operation that change the size is called scaling.
8
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Scaling
 if the scaling factor is greater than 1 is enlarge, if
the factor is less than 1, the object is made smaller,
a factor of 1 has no effect on the object.
 Whenever scaling is performed there is one point
that remain at the same location , this is called the
fixed point of the scaling transformation.
 to scale an object from a specific fixed point(Xf,Yf)
we perform the following three steps:
9
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
Scaling
 A) Translate the point(Xf,Yf) to the origin ,every
point (x,y) is moved to a new point (X1,Y1) :
X1=X-Xf
Y1=Y-Yf
 B) scale these translate points with the origin as the fixed
points:
X2=X1*Sx
Y2=Y1*Sy
 C) translate the origin back on the fixed point(Xf,Yf) :
X3=X2+Xf
Y3=Y2+Yf
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
10
Scaling
 where Sx,Sy are called the horizontal and vertical
scale factor, to implement scaling in matrix
representation(Homogeneous Vector)
 [x’ y’ 1]=[x y 1] * 1 0 0 * Sx 0 1
0 1 0
0 Sy 1
-Xf –Yf 1
0
0
*
1
10 0
0 1 0
Xf Yf 1
(xf,yf)
(A)
(B)
( c)
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
11
Scaling example
 Consider a triangle with vertices A(0,0),B(2,2) and
C(3,1),Scaling 2 units in the x axes and 2 unit in
the Y axes .
(2,2)
(3,1)
(0,0)
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
12
Home work
Q) consider a triangle with vertices A (4,4), B (10,3)
and c(7,10), now magnify it to thrice its size keeping
C(5,2).
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
13
Rotation Transformation
 Another useful transformation is the rotation of
the object about specified pivot point.
 After the object has been rotated, it still the same
distance away from the pivot point.
 It is possible to rotate one or more objects or the
entire image.
 About any point in world space in either a
clockwise(negative angle) or counterclockwise
(positive angle) direction.
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
14
Rotation Transformation
 Any point(x,y) can be represented by its radial
distance (r) ,from the origin and its angle( ) .
Y
(x’,y’)
r
(x,y)
r
(0,0)
X
Rotation about origin
x=r*cos( )
y=r*sin( )
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
15
Rotation Transformation
 there are two type of rotation :
 Counterclockwise
Cos(
- Sin(
)
)
Sin (
Cos(
)
)
 Clockwise
Cos(- Sin( -
)
)
Sin (- )
Cos( - )
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
16
Homogeneous Matrix Representation
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
17
Inverse 2D Transformations

University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
18
2D Rotation about an arbitrary point
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
19
2D Fixed Point Scaling
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
20
2D Reflection
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
21
2D Reflection (2)
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
22
2D Shearing
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
23
References
Donald Hearn, M. Pauline Baker,
Computer Graphics with OpenGL, 3rd
edition, Prentice Hall, 2004
Chapter 3, 4
University of sulaimanyiah - Faculty of Physical and Basic Education - Computer Dep. 2012-2013
24