Sei sulla pagina 1di 73

2D Transformations

2D Transformations
Introduction of Transformations
• Changing of an object after creation {in terms
of position or size}.
• Different types of transformation
1. Translation
2. Scaling
3. Rotating
4. Reflection
5. Shearing
Translation

• It will shift the object from one position to other


position.
• To translate a point from coordinate position (x,y) to
another (x1,y1), we add algebraically the translation
distances Tx & Ty to original coordinate
• X1=X+Tx , where Tx & Ty is called shift vectors
• Y1=Y+Ty , so
X1 X Tx
• = +
Y1 Y Ty
Translation

X1 X dx
• = +
Y1 Y dy

• p’=p+T , where T is translation


factor
Translation
• Example: a(2,2);b(10,2);c(5,5); translate the
triangle with dx=5, dy=6.
Translation
• Example: a(2,2);b(10,2);c(5,5); translate the
triangle with dx=5, dy=6.
2
• a’=a+T , ------- + 5
= 7

a’(7,8) 2 6 8

• B’=b+T ,------- 10
+ 5
= 15

b’(15,8) 2 6 8

• C’=c+T ,------- 5 + 5 = 10

• C’(10,11) 5 6 11
Rotation
• it is a process of changing the angle of the object.
• Rotation can be clockwise or anticlockwise.
• X=r*cos 
• Y=r*sin  , where  is the angle between x-axis &
point P r is the distance from origin to P
• X’=x*cos -y*sin 
• Y’=y*cos + x*sin 
X’ X
• So cos  -sin 
= sin  cos 
Y’ Y

• P’=r*p
Rotation

• Example: one triangle is given (2,2) (8,2) (5,5)


,Rotate the triangle 90o
Rotation

• Example: one triangle is given (2,2) (8,2) (5,5)


,Rotate the triangle 90o

• Here  =90. default counter clockwise (CCW)

cos 90 -sin 90 0 -1
• R= sin 90 cos 90 = 1 0

2 -2
0 -1
• A’= 1 0
2
= 2
8 -2
0 -1
• B’= 1 0
2 = 8
Rotation
5 -5
• C’= 0
1
-1
0
=
5 5
Scaling
• It is used to alter or change the size of objects.
• The change is done using scaling factors.
• There are two scaling factors, i.e. Sx in x
direction Sy in y-direction.
• Is multiplying with (s) scaling factor:
s(scaling) if s>1  scale up
s<1  scale down
Scaling
• X’=x. Sx
• Y’=Y.sy
• S= s x 0
0 sy

• P’ p s

X’ Y’ = X Y sx 0
0 sy
Scaling
• Scale triangle A (2,5) B(7,10) C(10,2) by 2 units
in x-axis and 2 units in y-axis
Scaling
• Scale triangle A (2,5) B(7,10) C(10,2) by 2 units
in x-axis and 2 units in y-axis
sx=2 sy =2

p’=p*s
4
A’= 2 5 2
0
0
2
=
10

14
B’= 7 10
2
0
0
2
20

20
2 0
c’= 10 2
0 2
4
Scaling

2 5 2 0 4 10

• 7
10
10
2
0 2 = 14
20
20
4
• Scaling  multiplication
• Rotation  multiplication
• Translation  addition

• Translation p(x,y,1)
p(x,y,1)=[x,y,1]. 1 0 0
0 1 0
tx ty 1
• Rotation p(x,y,1)
cos  sin  0
p(x’,y’,1)=[x,y,1]. -sin  cos  0
0 0 1

• Scaling p(x’,y’,1)
Sx 0 0
p(x’,y’,1)=[x,y,1]. 0 sy 0
0 0 1
• A (1,0) B(0,1) C(1,1) find the transformation by
rotating 45 counter about origin & then
translating 1 unit in x-axis and 1 unit in y-axis.
cos  sin  0 cos 45 sin 45 0
• R= -sin  cos  0 = -sin 45 cos 45 0
0 0 1 0 0 1

• T= 0
1

tx
1
0

ty
0
0
1
= 1
0
1
1
1
0 0
0
1

• P’=P.[R.T]
Reflection
• it is a transformation which evaluate the mirrors
image of the object.
• it is of two types:
1. Reflection w.r.t x-axis
2. Reflection w.r.t y-axis
p’ Re(x) p

X’ X
= 0
1
-1
0
Y’ Y
 p’=Re(x) *p
Reflection
• Re(y)
P’ Re(y) p
X’ X
= -1
0 1
0
Y’ Y
Reflection
• Example : A square a,b,c,d is given , the
coordinates are given as a(1,1) b(4,1) c(1,3)
d(4,3). Find the reflection with respect to both
x&y axis.
Reflection
• Example : A square a,b,c,d is given , the
coordinates are given as a(1,1) b(4,1) c(1,3)
d(4,3). Find the reflection with respect to both
x&y axis.
• 1)W.R.Tx
P’= 1 4 1 =
4 1 4 1 4
1 1 3 3 -1 -1 -3 -3
1 1 1 1 1 1 1 1
Reflection
2)W.R.Ty
P’= 1 4 1 4 = -1 -4 -1 - 4
1 1 3 3 1 1 3 3
1 1 1 1 1 1 1 1

3)W.R.Tx and W.R.Ty ???


Reflection
• Example: Triangle ABC is given,the coordinates
a,b,c and are given as a(3,4),b(6,4),c(4,8). Find
reflected position of triangle with respect to the
x-axis.
• The matrix for Re(x) is

=
• The ‘a’ pt coordinates after reflection
3 3
• (x’,y’,1)= 4 = -4
1 1
Reflection

• So

a (3, 4) becomes a’ [3, -4]


b (6, 4) becomes b’ [6, -4]
c (4, 8) becomes c’ [4, -8]
Shearing
• It is a transformation, which will change the
object in specific approach.
• The sliding of layers of object occur.
1.Shearing in the X-direction
2.Shearing in the Y-direction
3.Shearing in X-Y directions
Shearing
• Shearing in the X-direction
In this horizontal shearing sliding of layers
occur.

x X+Shx*y
Hx= y = y
1 1
Shearing
• Shearing in the Y-direction:
Here shearing is done by sliding along vertical
or y-axis.

x X
Hy= y = y +Shy*x
1 1
Shearing
• Shearing in X-Y directions: Here layers will be
slided in both x as well as y direction. The
sliding will be in horizontal as well as vertical
direction. The shape of the object will be
distorted. The matrix of shear in both
directions is given by:
Shearing
• Example : A square a,b,c,d is given , the
coordinates are given as a(0,0) b(3,0) c(3,3)
d(0,3). Find the square after shearing by 2
units along y-axis.
Shearing
• Example : A square a,b,c,d is given , the
coordinates are given as a(0,0) b(3,0) c(3,3)
d(0,3). Find the square after shearing by 2
units along y-axis.

• P’=
0 3 3 0
1
2
0
0
1
0
0
0
1
0 0 3 3 = 0
0
3
6
3
9 3
0

1 1 1 1 1 1 1 1
Composite Transformation

• A number of transformations or sequence of


transformations can be combined into single
one called as composition.
• The resulting matrix is called as composite
matrix.
Composite Transformation

• Ex: T1(tx1,ty1)
T2(tx2,ty2) applied on P

P’=T2(tx2,ty2).{T1(tx1,ty1).p}
P’’= T2(tx2,ty2).p’
P’={T2(tx2,ty2).T1(tx1,ty1)}.p
composite matrix
1
0
0
1
tx2
ty2
1
0
0
1
tx1
ty1 = 0
1 0
1
tx1+tx2
ty1+ty2
0 0 1 0 0 1 0 0 1
Composite Transformation

• Ex: scaling s1(tx1,ty1)


s2(tx2,ty2) applied on P
composite matrix
SX2
0
0
SY2
0
0
SX1
0
0
SY1
0
0
= SX2*SX1
0
0
SY2*SY1
0
0
0 0 1 0 0 1 0 0 1
Composite Transformation

1. Translate in original point


2. Rotate by 
3. Reverse back Translation

P’=[Translation].[Rotate].[ReversT].p

Composite Transformation

• P’= [Translation].[Rotate].[ReversT]
1 0 Xr cos  -sin  0 1 0 -xr

0
0 1
0
yr
1
sin 
0
cos 
0
0
1
0
0
1
0
-yr
1
.P
translate to point counter clockwise Rotation back to origin
Composite Transformation

• Example: let Triangle a b c , find the


transformation matrix if we first rotate 90
counter clockwise , scaling it 2 y-axis then
translating it by 4 unit along x-y axis.
Composite Transformation
cos  sin  0 cos 90 -sin 90 0
1.Rotate 90 sin  cos  0 sin 90 cos 90 0
0 0 1 0 0 1

Sx 0 0 1 0 0
2.Scale 2 – y axis 0 sy 0 0 2 0
0 0 1 0 0 1

3.T 4*4 1
0
0
1
tx
ty
1
0
0
1
4
4
0 0 1 0 0 1
Composite Transformation

• Example: find the transformation matrix to


calculate the Rotation of the reflection of
Triangle a b c about x,y-axis and 60o.
Composite Transformation

• Example: find the transformation matrix to


calculate the Rotation of the reflection of
Triangle a b c about x,y-axis and 60o.


-1 0 0
Reflection= 0 -1 0
0 0 1

• Rotation=
Rotation 60o
CCW
• Relative Scaling:
1) Translate object to D-distance between
reference point &origin.
2) Scale
3) Reverse translate
Tm=[T].[S].[RevT]
Note: Uniform scaling Sx=Sy
• Ex: let a(1,1) b(3,1) c(2,2) triangle, scale it
uniformly by 2 units with reference a as pivot
point.
• Ex: let a(1,1) b(3,1) c(2,2) triangle, scale it
uniformly by 2 units with reference a as pivot
point.
1) Reverse Translate Tx=-1 Ty=-1 to origin point
2) Scale Sx=2;Sy=2.
3) Translate back Tx=1;Ty=1
So P’=[T].[Sxy].[T Reverse ].P
Examples
Ex1: let square a(2,2) B(3,2) C(3,4) D(2,4)
A) Find the coordinates of square after Rotating
300 then shearing in the y-axis by 3 units.
B) Then find the coordinates after shearing 3
units y-axis then Rotating 300.
Examples
A) P’=[Sy].[RO].P
cos 30 -sin 30 0
1 0 0
P’= 3
0
1
0
0
1
. sin 30 cos 30 0
0 0 1
.P

B) P’=[RO]. [Sy].P

cos 30 -sin 30 0
P’= sin 30 cos 30 0 . 1
3
0
1
0
0 .P
0 0 1 0 0 1
Examples
EX2: Let square A(1,1) B(3,1) C(3,2) D(1,2)
Find the transformation matrix for Rotating
the square 450 CCW around D.
Step1: translate to original
Step2:Rotate
Step3:back translation
P’=TXY .R(450).TXYR .P
Step3 Step2 Step1
Examples
• P’=TXY .R(450).TXYR .P
cos 45 -sin 45 0
1 0 1 1 0 -1
0 1 2 sin 45 cos 45 0 0 1 -2
0 0 1 0 0 1 0 0 1
Examples
Ex3: Find the values of triangle A(4,4) and B(4,1)
C(7,1) after scaling along x-axis by 3 units and 1
unit to y-axis then reflecting it with respect to y-
axis.
P’=[Re].[S].P

P’= -1
0 1
0
0
0 3
0
0
1
0
0
4
4
4
1
7
1
0 0 1 0 0 1 1 1 1

p’= -3
0 1
0 0
0
4
4
4
1
7
1
0 0 1 1 1 1
Examples
Ex4: Find the transformation Matrix required for
scaling by 4 units in x-axis & 3 units in y-axis
,then rotating about centre point by 300
counter clock wise of square A(2,2) B(4,2)
C(4,4) D(2,4).

p’=[TXY] [R].[R Txy ] .[ Sxy ].P


First scale to find new centre point
• P’=
4 0 0 2 4 2 2
0 3 0 2 2 2 4
0 0 1 1 1 1 1

• ps
8 16 16 8
6 6 12 12
1 1 1 1

• P’= 1
0
0
1
12
9
cos 30 sin 30 0
-sin 30 cos 30 0
1
0
0
1
-12
-9
8 16
6 6
16
12 12
8

0 0 1 0 0 1 0 0 1 1 1 1 1
Examples
• Find the values of Triangle A(1,1) B(1,3) C(2,1)
after scaling two units in x-axis relative to C.

P’= 1
0
0
0
2
1
2
0
0
0
0
0
1
0
0
1
-2
-1 .P
0 0 1 0 0 1 0 0 1
3D Transformation
• The three-dimensional transformations are
extensions of two-dimensional transformation. In
2D two coordinates are used, i.e., x and y whereas
in 3D three co-ordinates x, y, and z are used.
• For three dimensional images and objects, three-
dimensional transformations are needed. These are
translations, scaling, and rotation. These are also
called as basic transformations are represented
using matrix. More complex transformations are
handled using matrix in 3D.
3D Transformation
• P= x
y
Z
1
3D Transformation
• Translation
It is the movement of an object from one
position to another position. Translation is
done using translation vectors. There are
three vectors in 3D instead of two.
Translation in the x-direction is represented
using Tx. The translation is y-direction is
represented using Ty. The translation in the z-
direction is represented using Tz.
Translation
• If P is a point having co-ordinates in three
directions (x, y, z) is translated, then after
translation its coordinates will be (x1 y1 z1)
after translation. Tx Ty Tz are translation
vectors in x, y, and z directions respectively.
x1=x+ Tx
y1=y+Ty
z1=z+ Tz
Translation
• Matrix for translation

• Matrix representation of point translation


Translation
• Example : let point a(5,6,7) and
plain a(1,1,1) b(1,2,2) c(4,2,1) d(4,4,4) find the
coordinates after translate by 3 units x-axis, 2
units in y-axis and 4 units in z axis.
• P’=T.P
1 0 0 3 5 8
0 1 0 2 6 8
0
0
0
0
1
0
4
1
7 = 11
1 1
Translation
• P’=T.P

1 0 0 3 1 1 4 4
0 1 0 2 1 2 2 4
0 0 1 4 1 2 1 4
0 0 0 1 1 1 1 1
Scaling

• Scaling is used to change the size of an object.


The size can be increased or decreased. The
scaling three factors are required Sx Sy and Sz.

• P’=S.P NOTE : uniform scaling sx=sy=sz

• P’=
Scaling
• Scaling of the object relative to a fixed point
Following are steps performed when scaling of
objects with fixed point (a, b, c). It can be
represented as below:
1. Translate fixed point to the origin
2. Scale the object relative to the origin
3. Translate object back to its original position.
Scaling
• Ex: point(3,6,5) x-axis=2;y-axis=1;z-axis=4.
3 6
2 0 0 0
• P’= 0
0
1
0
0
4
0
0
6
5 = 6
20
0 0 0 1 1 1
Reflection
• Reflection W.R.T xy plain (Rexy)
P’= Rexy .P

1 0 0 0

P’= 0
0
1
0
0
-1
0
0
0 0 0 1

• Reflection W.R.T yz plain (Reyz)


-1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Reflection
• Reflection W.R.T xz plain (Rexz)
P’= Rexz .P

1 0 0 0

P’= 0
0
-1
0 1
0
0
0

0 0 0 1
Reflection
• Example: let point A(3,4,6) B(2,4,8) find the
reflection of these point W.R.T xy plain.
3 2 3 2
1 0 0 0
P’= 0
0
1
0
0
-1
0
0
4 4
6 8
= 4 4
-6 -8
0 0 0 1 1 1 1 1
Shearing

• It is change in the shape of the object. It is


also called as deformation. Change can be in
the x -direction or y -direction or both
directions in case of 2D. If shear occurs in both
directions, the object will be distorted. But in
3D shear can occur in three directions.
Shearing
• Shz=

x
• Shx= = Y+ax
Z+bx
1

x+ay
• Shy= = Y
Z+by
1
Shearing
• Ex: apply on point (4,4,4) shearing by 2 units
in y direction over the xz plain & 3 units over
the xy plain.
4 12
• P’=
1 2 0 0
0
0
1
3
0
1
0
0
4
4
= 4
16
0 0 0 1 1 1
Rotation

Rz
• X’=xcos-ysin 
• Y’=xsin -ycos
• Z’=Z
Rotation

Rx
• y’=ycos-zsin 
• z’=ysin -zcos
• x’=x
Rotation

Ry
• z’=zcos-xsin 
• x’=zsin -xcos
• y’=y
Rotation
• Let plain A(1,1,4) b(4,1,4) d(4,4,4) d(1,4,4)
Rotate the square 600 around the line passing
from r(5,5,1) to f(5,5,3)

1 0 0 -5 1 0 0 5 1 4 4 1
0 1 0 -5 0 1 0 5 1 1 4 4
0 0 1 0 0 0 1 0 4 4 4 4
0 0 0 1 0 0 0 1 0 0 0 1

Potrebbero piacerti anche