Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CG 2d Trans

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

2D TRANSFORMATIONS

Transformations
• Rigid Body Transformations - transformations that do
not change the object.
• Translate
– If you translate a rectangle, it is still a rectangle
• Scale
– If you scale a rectangle, it is still a rectangle
• Rotate
– If you rotate a rectangle, it is still a rectangle
Translation
• A translation moves all points
in an object along the same
straight-line path to new
positions.
• The path is represented by a ?
vector, called the translation or
shift vector.
• We can write the components: ty=4
x' = x + tx
y' = y + ty (2, 2) tx= 6
• or in matrix form:
P' = P + T
x’ y’ = x y + tx ty
Example:
Q. Translate the polygon with coordinate A(2,5) , B(7,10)
and C(10,2) by 3 units in x direction and 4 units in y
direction.

Q. Translate the polygon with coordinate A(12,15) ,

B(-17,10) and C(10,21) by 5 units in x direction and 7


units in y direction .
Rotation
• Rotation - Repositions
an object along a
circular path
P’
• Rotation requires an
and a pivot point
P
• First, we’ll assume the
pivot is at the origin.
Rotation
• Review Trigonometry
=> cos = x/r , sin = y/r
• x = r. cos , y = r.sin
P’(x’, y’)

=> cos ( + ) = x’/r


•x’ = r. cos ( + )
r
•x’ = r.cos cos -r.sin sin y’ P(x,y)
•x’ = x.cos – y.sin r y

=>sin ( + ) = y’/r x’ x
y’ = r. sin ( + )
Identity of Trigonometry
•y’ = r.cos sin + r.sin cos
•y’ = x.sin + y.cos
Rotation
• We can write the components:
x' = x cos – y sin
y' = x sin + y cos

P’(x’, y’)
• or in matrix form:
P' = R • P
• can be clockwise (-ve) or
counterclockwise (+ve as our
example). y’
P(x,y)
• Rotation matrix
r y
cos sin
R
sin cos x
x’
• Default direction of rotation is
anticlockwise direction.
x’ y’ = x y cos ө sinө
-Sinө cosө
example
• A point (4,3) is rotated counterclockwise by
an angle of 45° . Find the rotation matrix
and resultant point.
Scaling
• Scaling changes the size of an
object and involves two scale
factors, Sx and Sy for the x-
and y- coordinates P’
respectively.
• Scales are about the origin.
• We can write the components:
x’ = sx • px
P
Y’ = sy • py
or in matrix form:
P' = S • P
Scale matrix as:
sx 0
S
0 sy
Scaling
• If the scale factors are in between 0
and 1  the points will be moved
closer to the origin  the object
will be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?

P’
Scaling
• If the scale factors are in between 0
and 1  the points will be moved
P’
closer to the origin  the object
will be smaller.
• Example :
•P(2, 5), Sx = 0.5, Sy = 0.5
P(2, 5)
•Find P’ ?
•If the scale factors are larger than 1
 the points will be moved away P’

from the origin  the object will be


larger.
• Example :
•P(2, 5), Sx = 2, Sy = 2
•Find P’ ?
Scaling
• If the scale factors are the
P’
same, Sx = Sy  uniform
scaling
• Only change in size (as
previous example)
•If Sx Sy  differential
scaling. P(1, 2)

•Change in size and shape


•Example : square  rectangle
•P(1, 3), Sx = 2, Sy = 5 , P’ ?
Homogeneous coordinates
• To fit the picture in to proper position many time we required to
perform sequence of transformation i.e. translation , rotation and
scaling.

• We have a general transformation of a point:

P' = P M1 + M2

• When we scale or rotate, we set M1, and M2 is the additive identity.


i. e. zero matrix

• When we translate, we set M2, and M1 is the multiplicative identity


.i.e. identity matrix

• To combine multiple transformations, we must explicitly compute


each transformed point.
Homogeneous coordinates
• In order to combine sequence of transformation we have to eliminate
the matrix addition associated with translation term in M2.

• To achieve this we have to represent M1 as 3X3 matrix instead of 2 X 2


by introducing dummy coordinate called Homogeneous coordinate

• Homogeneous coordinate is represented by the triplet (Xw , Yw W )

Where

X= Xw / W , Y=Yw / W

• For 2D transformation W can be any positive value but we take W= 1

• Each 2D position can be represented ith homogeneous coordinate as

( x , y , 1)
Homogeneous coordinate for translation are:

1 0 0
X’ Y’ 1 = X Y 1
0 1 0
tx ty 1

= X+tx Y+ty 1
Homogeneous coordinate for rotation are:

Cos Θ sin Θ 0
R =
-Sin Θ cos Θ 0
0 0 1

Cos Θ sin Θ 0
X’ Y’ 1 = X Y 1 -Sin Θ cos Θ 0
0 0 1

xCos Θ- ysin Θ xSin Θ+ycos Θ 1


=
Homogeneous coordinate for scaling are:

Sx 0 0
S =
0 sy 0
0 0 1

Sx 0 0
X’ Y’ 1 = X Y 1 0 sy 0
0 0 1

= x s x y sy 1
Q. Give 3 x 3 Homogeneous coordinate transformation

matrix for each of the following translation :

1. Shift the image right to 3 unit

2. Shift the image up 2 units

3. Move the image down ½ unit and right 1 unit

4. Move the image down 2/3 unit and left 4 units


Q. Find transformed matrix that transform the given

square ABCD to half its size with center till remaining at

the same position . The coordinates of the square are

A(1,1) , B (3 , 1) C (3 , 3) D (1, 3) and center at (2 ,2 ) also

find resultant coordinates of square.


Solution:
1. Translate the square so that its center coincides with
origin
2. Scale the square with respective the origin
3. Translate the square back to the original position.

tx = ty = 2 sx =sy = 0.5
Q. find transformation of triangle A(1,0) B(0 , 1) C(1,1) by

1. Rotating 45° about the origin and then translating 1


unit in x and y direction

2. Translating 1 unit in x and y direction and then


rotating 45° about the origin
Composite Transformation
• We can represent any sequence of transformations
as a single matrix.

• Composite transformations:
– Rotate about an arbitrary point – translate, rotate,
translate
– Scale about an arbitrary point – translate, scale,
translate
– Change coordinate systems – translate, rotate, scale
Order of operations
So, it does matter. Let’s look at an example:
1. Translate 1. Rotate
2. Rotate 2. Translate
Composite Transformation Matrix
General Pivot- Point Rotation

Operation :-
1. Translate (pivot point is moved to origin)
2. Rotate about origin

3. Translate (pivot point is returned to original position)

T(pivot) • R( ) • T(–pivot)
Composite Transformation Matrix
1 0 0 cos sin 0 1 0 0
0 1 0 . -sin cos 0 . 0 1 0
-tx -ty 1 0 0 1 tx ty 1

cos sin 0 1 0 0
-sin cos 0 . 0 1 0
-tx cos + ty sin -tx sin - ty cos 1 tx ty 1

cos sin 0
-sin cos 0
-tx cos + ty sin +tx -tx sin - ty cos +ty 1
Q. Perform counter clockwise 45° rotation of

triangle A(2,3 ) B(5,5) C(4,3) about point (1 , 1)


Composite Transformation Matrix
• Example
– Perform 60 rotation of a point P(2, 5) about a
pivot point (1,2). Find P’?
Composite Transformation Matrix
General Fixed-Point Scaling
Operation :-
1. Translate (fixed point is moved to origin)
2. Scale with respect to origin
3. Translate (fixed point is returned to original position)

T(fixed) • S(scale) • T(–fixed)


• Find the matrix that represents scaling of an
object with respect to any fixed point?

• Given P(6, 8) , Sx = 2, Sy = 3 and fixed


point (2, 2). Use that matrix to find P’?
Other transformations
Reflection: It is a transformation that produce mirror
image of an object relative to an axis of reflection

x-axis 1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about y axis

y-axis

1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about origin

1 0 0
0 1 0
0 0 1
Other transformations
Reflection: about y=x

0 1 0
1 0 0
0 0 1
Other transformations
Reflection: about y= -x

0 1 0
1 0 0
0 0 1
Other transformations
Shear : Transformation that slant the shape of an object .
X shear: preserve the y coordinate but change x value which

causes vertical line to tilt right

1 0 0
shx 1 0
0 0 1
Other transformations
y shear: preserve the x coordinate but change y value
which causes horizontal line to transform in to lines
which slope up or down

1 shy 0
0 1 0
0 0 1
Inverse Transformation

• When we apply any transformation to point


P(x,y), we get a new point (x’ , y’).

• Sometimes it may require to get undo the applied


transformation.

• In this case we have to get original point ( x , y)


from (x’ , y’).

• This can be achieved by inverse transformation


• If the inverse of matrix T is T-1 then ,
TT-1=T-1T=I , Identity matrix
• The elements of inverse matrix can be
calculated from the elements of T as ,

tij -1 =[ (-1) i+j det Mij ] / det T

Determinant of a 2 x 2 matrix is ;
det t11 t12 = t11 t22 - t12 t21
t21 t22
• Inverse of homogeneous coordinate transformation matrix
can be given as ,

a d 0 -1 1 e -d 0
b e 0 = ------- -b a 0
c f 1 ae-bd bf-ce cd-af ae-bd

You might also like