Вы находитесь на странице: 1из 38

COMPUTER GRAPHICS

UNIT-III
2D Geometric Transformations

GEOMETRIC TRANSFORMATION /
COORDINATE TRANSFORMATION

Geometric transformation means change in


orientation, Size and Shape.
Coordinate Transformation

TWO DIMENSIONAL GEOMETRIC


TRANSFORMATIONS
2D

Translations.
2D Scaling
2D Rotation
Matrix Representation of 2D
transformation
Formula for Transformation
Matrix of Transformed object= Matrix of object . Matrix of
transformation

2D TRANSLATIONS.
Point P defined as P( x, y ),
translate to Point P( x, y) a distance d x parallel to x axis, d y parallel to y axis.
x x d x y y d y
Define the column vectors
dx
x
x

P , P ,T
y
y
dy
Now
P P T

P
P

EXAMPLE: 2D TRANSLATION

5
6

6
5

dx = 2
dy = 3

4
3
3

3
2
1
0

Component-wise addition of vectors


v = v + t

where

x
v
,
y

10

x'
v'
,
y
'

X
dx
t

dy

and

x = x + dx
y = y + dy
To move polygons: translate vertices of polygon after adding translation
factors and redraw lines between them.
Translation always Preserves lengths and shape of object (Distortion in
object shape will not occur).

2D SCALING FROM THE ORIGIN.


Point P defined as P ( x, y ),
Perform a scale (stretch) to Point P( x, y) by a factor s x along the x axis,
and s y along the y axis.
x s x . x,

y s y . y
P

Define the matrix


sx
S
0

0
s y

Now
P S P or

x s x
y 0

0
.

sy

x
y

TYPES OF SCALING
After

applying Scaling factor coordinates of


object is either increase or decrease.
Expansion and compression of object is
depend upon the scaling factor Sx and Sy.

Uniform Scaling

If Sx = Sy < 1

If Sx = Sy > 1

Non uniform scaling

If Sx Sy < 1
occurs.
If Sx Sy > 1

Uniform compression occurs.


Uniform Expansion Will occur.
Non uniform compression
Non uniform expansion Will occur.
7

TYPES OF SCALING (CONT)

Uniform Scaling

Non Uniform scaling

EXAMPLE: 2D SCALING

Y
sx 3
sy 2

6
5
4
3
2
2
1

1
0

6
2

3
1

9
2

10

Component-wise scalar multiplication of vectors


v = Sv
and

where

x
v
,
y

sx
S
0

s y

x'
v'

y '

x' s x x
y' s y y

HOMOGENEOUS COORDINATES
2D case

Add a 3rd coordinate to every 2D point

A point (a, b) in 2D can be represented as (a,b,1) in


homogeneous coordinate system.
Any point (x, y, w) where w!=0 represents a point at location
(x/w, y/w) in this coordinate system.

3D Case
Add a 4th coordinate to every 3D point
A point (a, b, c) in 3D can be represented as (a,b,c,1) in
homogeneous coordinate system.
Any point (x, y, z, w) in 3D where w!=0 represents a point at
location (x/w, y/w, z/w) in this coordinate system.

HOMOGENEOUS COORDINATES
x' x t x
y' y t y

Q: How can we represent translation as a 3x3


matrix?

1 0 0
Translation 0 1 0
tx ty 1

TRANSLATION
Example

of translation

Homogeneous Coordinates
x' 1 0 t x x x t x
y ' 0 1 t y y t
y
y


1 0 0 1 1 1

tx = 2
ty = 1

QUESTION
Object coordinates are (00,10,11,01)
Perform uniform expansion of this object.

13

QUESTION
Q1. Write a 2X2 transformation matrix for
each of the following scaling transformation.
(1)The entire picture is 3 times as large.
(2)The entire picture is 1/3 as large.
(3)The X direction is 4 times as large and the y
direction unchanged.
(4) The x direction reduced to the original
and y direction increased by 7/5 times.

14

QUESTION
Translate the square ABCD whose coorditates
are A(0,0), B(3,0),c(3,3),D(0,3).
Translate this square 1.5 unit in x direction and
0.5 unit in y direction.
After translation performing scaling with scaling
factor sx=1.5 and sy=0.5

15

QUESTION

Find the transformation matrix that transforms the


square ABCD whose center is at (2,2) is reduced to
half of its size, with center still remaining at (2,2).
The coordinate of square ABCD are A(0,0), B(0,4),
C(4,4),D(4,0). Find the coordinates of new square.

16

QUESTION
Prove that two scaling transformation is
commutative
Commutative property is
S1.s2=s2.s1
Prove that two successive translation are additive.

Prove that two successive scaling is multiplicative

17

COMPOSITE TRANSFORMATIONS

Composite 2D Translation (Two successive


Translation)

T T(t x1 , t y1 ) T(t x 2 , t y 2 )
T(t x1 t x 2 , t y1 t y 2 )
1 0 tx2

0 1 t y2
0 0 1

1 0 t x1 1 0 t x1 t x 2

0 1 t y1 0 1 t y1 t y 2
0 0 1 0 0

Two Successive Translation is Additive

COMPOSITE TRANSFORMATIONS

Composite 2D Scaling (two successive Scaling)

T S( s x1 , s y1 ) S( s x 2 , s y 2 )
S( s x1s x 2 , s y1s y 2 )
sx 2

0
0

0
sy2
0

0 s x1

0 0
1 0

s y1 0
0 1

s x1 s x 2

s y1 s y 2
0

0
1

Two Successive Scaling is Multiplicative

2D Rotation

20

2D ROTATION ABOUT THE


ORIGIN.

P(x,y)

P(x,y)

r
x
21

2D ROTATION ABOUT THE ORIGIN.


y

P(x,y)

P(x,y)

x r. cos
y r. sin

r
x

x
22

2D ROTATION ABOUT THE ORIGIN.


x r. cos( ) r. cos . cos r. sin . sin
y r. sin( ) r. cos . sin r. sin . cos

P(x,y)

P(x,y)

x r. cos
y r. sin

r
x

x
23

2D ROTATION ABOUT THE ORIGIN.


x r. cos( ) r. cos . cos r. sin . sin
y r. sin( ) r. cos . sin r. sin . cos
Substituting for r :
x r. cos
y r. sin

Gives us :
x x. cos y. sin
y x. sin y. cos

Rotation (Anticlockwise)

x cos
y sin

sin
.

cos

x
y

Rotation (Clockwise)

x cos
y sin

sin
.

cos

y 24

QUESTION
Rotate a point (10,0) in anticlockwise direction
Angle is 90 degree.

Rotation Anticlockwise
(Anticlockwise)
After rotating this point rotate this point in
x x cos sin
clockwise direction.

y sin

cos

Rotation (Clockwise)

x x
y y

cos
sin

sin

cos

25

TRANSFORMATIONS.
Translation.
P=T

+P

P=S

Scale

Rotation
P=R

P
We would like all transformations to be
multiplications

26

EXAMPLES

Translate [1,3] by [7,9]

1
0

0
1
0

7
1
9 3
1
1

8
12
1

Scale [2,3] by 5 in the X direction and 10 in the Y direction

Rotate [2,2] by 90 (/2)

cos( / 2)
sin( / 2)

5
0

0
10
0

sin( / 2)
cos( / 2)
0

0
1

2
3
1

0
2
0 2
1
1

10
30
1

0
1
0

1
0
0

0
2
0 2
1
1

2
2
1

27

Shearing Transformation
The searing transformation when applied to the object it results
distortion of shape. In sharing the parallel layers of any objects are
simply slided with respect to each other.
Types of Shearing Transformation
X- shear: In X-shear y coordinate remain unchanged, but x is
changed.
Y- shear: In Y-shear x coordinate remain unchanged, but y is
changed

x '
y '

x 1 0

y shx 1
X- Shear

x ' x 1 Shy
y ' y 0 1

Y- Shear

28

Question
Q1. Prove that simultaneous shearing in both direction ( X & y
direction) is not equal to the composition of pure shearing along Xaxis followed by pure shear along y- axis.
x '
y '

x

y

x '
y '

1 a
b 1

1 a

0 1

Pure Shearing

1
b

1 a .b a
0
1
b
1

29

QUESTIONS ON 2D
TRANSFORMATION

Shear following object 2 unit in x direction and 2 unit


in y direction.
Object coordinates are (00,10,11,01).

30

BASIC 2D TRANSFORMATIONS

Basic 2D transformations as 3x3 matrices


x ' s x
y ' 0

1 0

x' 1 0 t x x
y ' 0 1 t y
y

1 0 0 1 1

Translate
x' cos
y ' sin

1 0

sin
cos
0

Rotate

0
0

0
sy

x
y

1 1

Scale
0
0
1

x
y

1

x ' 1
y ' sh
x
1 0

shy
1
0

Shear

0 x
0 y
1 1

MATRIX COMPOSITION

Transformations can be combined by


matrix multiplication

x' 1 0 tx cos sin 0 sx 0 0


y ' 0 1 ty sin cos 0 0 sy 0

w' 0 0 1 0

0
1 0 0 1

p =

T(tx,ty)

R()

S(sx,sy)

x
y
w
p

PIVOT-POINT ROTATION

Rotation with respect to a pivot point (x,y)


T ( x, y ) R ( )
T ( x, y )
1 0 x cos


0 1 y sin
0 0 1 0

sin
cos
0

1 0

0 1
0 0

y
1

FIX POINT SCALING

Steps for Fix point Scaling

Translate

point to origin (Fig (b))


Perform Scaling Fig(c) Expansion or
compression
Inverse Translation Fig(d)

34

FIXED-POINT SCALING

Scaling with respect to a fixed point (x,y)

T ( x, y ) S ( sx , s y )
T ( x, y )
0 0 sx
1


0
1 0 0
x y 1 0

0 0
1 0 0

sy
0 0 1 0
0 1 x y 1

QUESTION

Q1. Magnify the triangle with vertices A(0,0), B(1,1),


C(5,2) to twice its size while keeping c(5,2) fixed.

36

COMPOSITE TRANSFORMATIONS

Composite 2D Rotation (Two Successive Rotation)

T R ( 2 ) R (1 )
R ( 2 1 )
cos 2

sin 2
0

sin 2
cos 2
0

0 cos 1

0 sin 1
1 0

sin 1 0
cos 1
0

0
1

cos( 2 1 ) sin( 2 1 ) 0

sin( 2 1 ) cos( 2 1 ) 0

0
0
1

Two Successive Rotation is Additive

Thanks

38

Вам также может понравиться