Matrix Representation of Transformation
Matrix Representation of Transformation
𝑥 𝑡𝑥 𝑥′ 𝑥 𝑡𝑥
′
P’ = P+T, 𝑃 = [𝑦], 𝑇 = [𝑡 ] −−→ 𝑃 = [ ′ ] = [ 𝑦] + [𝑡𝑦 ]
𝑦 𝑦
12
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
2- Scaling matrix
𝑥
If a point P [𝑦] is being a 2x1 vector. If we multiply it by 2x2
𝑆 0
matrix S=[ 0𝑥 𝑆 ]. We will obtain another 2x1 vector which we
𝑦
can interpret as another point:
P’= S . P
𝑥′ 𝑆𝑥 0 𝑥
[ ′ ]= [ 0 𝑆𝑦 𝑦 ]
] . [
𝑦
P’= (S1S2). P
2 0 0.5 0 1 0 𝑥
S1S2=[ ][ ]= [ ].[ ] identity matrix then no
0 2 0 0.5 0 1 𝑦
change
13
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
P’= (S1S2). P
2 0 1 0 2 0 𝑥
(S1S2 ) . P=[ ][ ]. P −−→ [ ]. [ ]
0 1 0 2 0 2 𝑦
2- Rotation matrix
If a line segment have two endpoints (0,0) and (x,y), and length
𝐿 = √𝑥 2 + 𝑦 2 :
- The ratio of the height of the (x,y) endpoint with x-axis have
the y coordinates value and the length of the segment will be
𝑦
the Sin of the angle: Sin(𝜃 ) = 2 2
√𝑥 +𝑦
- The ratio of the distance of the (x,y) endpoint with y-axis have
the x coordinates value and the length of the segment will be
𝑥
the Cosine of the angle: Cos(𝜃 ) = 2 2
√𝑥 +𝑦
- If L=1 then Sin(𝜃)=y and Cos(𝜃)=x
- If we rotate the point (1,0) in counterclockwise by an angle 𝜃, it
becomes (Cos(𝜃), Sin(𝜃)) so:
cos(𝜃 ) 𝑎 𝑏 1 𝑎
[ ]= [ ] [ ]=[ ]
sin(𝜃) 𝑐 𝑑 0 𝑐
14
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
Notes:
- We can rotate an entire line segment by rotating both
endpoints which specify it.
15
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
16
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
𝑥
plin
paff = [ ] = [𝑦]
1
1
Applying an affine transformation gives another affine point.
A point (x, y) can be re-written in homogeneous coordinates as
(xw, yw,w)
- The homogeneous parameter w is a non-
zero value such that x and y coordinates can easily be
recovered by dividing the first and second numbers by the
third.
𝑥𝑤 𝑦𝑤
𝑥= 𝑦=
𝑤 𝑤
𝑆𝑥 0 0 𝑥𝑤 𝑆𝑥 𝑥𝑤
𝑆𝑥 𝑥
[0 𝑆𝑦 0] [𝑦𝑤]=[ 𝑆𝑦 𝑦𝑤 ] divide by w then [ 𝑆 𝑦] is
𝑦
0 0 1 𝑤 𝑤
the correctly scaled point.
The counterclockwise rotation matrix is
𝐶𝑜𝑠(𝜃 ) − 𝑆𝑖𝑛(𝜃)
[ ]
𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃)
17
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0
Using homogeneous coordinates we get: [ 𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0]
0 0 1
Applying it to the point (x,y) with homogeneous (xw,yw,w) gives:
𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0 𝑥𝑤
𝑅. 𝑃 = [ 𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0] [𝑦𝑤]
0 0 1 𝑤
𝑥 + 𝑡𝑥
divide by w then we get the point P=[ 𝑦 + 𝑡𝑦 ] is the correctly
translated point.
In general:
1- Translation
𝑥̅ 1 0 𝑡𝑥 𝑥
[𝑦̅] = [ 0 1 𝑡𝑦 ] [𝑦]
1 0 0 1 1
2- Rotation
𝑥̅ 𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0 𝑥
[𝑦̅] = [ 𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0] [𝑦]
1 0 0 1 1
18
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
3- Scaling
𝑥̅ 𝑆𝑥 0 0 𝑥
[𝑦̅] = [ 0 𝑆𝑦 0] [𝑦]
1 0 0 1 1
Rotation about an arbitrary point
- The homogeneous coordinate transformation matrix for
counterclockwise rotation about point (𝑥𝑐 , 𝑦𝑐 ) is done by three
steps as follows:
1- Translation to the origin
1 0 −𝑥𝑐
𝑇1 =[0 1 −𝑦𝑐 ],
0 0 1
𝑥̅ 1 0 −𝑥𝑐 𝑥
[𝑦̅] = [ 0 1 −𝑦𝑐 ] [𝑦]
1 0 0 1 1
2- Rotation about the origin
𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0
R=[ 𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0]
0 0 1
𝑥̿ 𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0 𝑥̅
[ 𝑦̿] = [ 𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0] [𝑦̅]
1 0 0 1 1
3- Translation back to its correct position
1 0 𝑥𝑐
𝑇2 =[ 0 1 𝑦𝑐 ]
0 0 1
𝑥̅̿ 1 0 𝑥𝑐 𝑥̿
[ 𝑦̿̅] = [ 0 1 𝑦𝑐 ] [ 𝑦̿]
1 0 0 1 1
19
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
Composite Transformations
- Matrices are a convenient and efficient way to represent a
sequence of transformations.
- Matrix multiplication is not commutative so that the order of
transformations is important.
- What if we want to rotate and translate?
𝑥𝑤
To rotate a point (𝑇2 (R (𝑇1 [𝑦𝑤])) )
𝑤
- Now we must form an overall transformation matrix as
follows:-
𝑥𝑤
(𝑇2 (R 𝑇1 )) [𝑦𝑤]
𝑤
1 0 𝑥𝑐 𝐶𝑜𝑠(𝜃) −𝑆𝑖𝑛(𝜃) 0 1 0 −𝑥𝑐
𝑇2 R 𝑇1 = [0 1 𝑦𝑐 ] [𝑆𝑖𝑛(𝜃) 𝐶𝑜𝑠(𝜃) 0] [0 1 −𝑦𝑐 ]
0 0 1 0 0 1 0 0 1
Order of transformations
20
Computer Graphics Mustansiriyah university
Third stage 2020-2021 Education college
Computer science department
21
Computer graphics 2018-2019 2D Viewing and Clipping
Viewport:
1
Computer graphics 2018-2019 2D Viewing and Clipping
2
Computer graphics 2018-2019 2D Viewing and Clipping
3
Computer graphics 2018-2019 2D Viewing and Clipping
Example1:
Solution
u=
c1= =300/0.1=3000
c2=umin-c1xmin
u=3000x+400
v=d1y+d2
=300/0.1=3000
d2=vmin-d1ymin
=100-3000(0.1)
=-200
v=3000y-200
4
Computer graphics 2018-2019 2D Viewing and Clipping
Example2:
u=
c1 =75-25/50-10
c1=50/40=1.25
c2=umin-c1xmin
=25-1.25*10
= 25-12.5=12.5
u=1.25x+12.5
v=d1y+d2
=75-25/30-5
d1=50/25=2
d2= vmin-d1ymin
=25-2*5
=25-10=15
v=2y+15
5
Computer graphics 2018-2019 2D Viewing and Clipping
(translate-scale-translate)
[ ] [ ]
N=T2ST1
[ ]
[ ]
[ ]
6
Computer graphics 2018-2019 2D Viewing and Clipping
Example1:
Solution N=T2ST1
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ][ ][ ]
7
Computer graphics 2018-2019 2D Viewing and Clipping
Example 2
Solution N=T2ST1
[ ]
[ ]
[ ]
[ ]
[ ]
8
Computer graphics 2018-2019 2D Viewing and Clipping
[ ]
[ ]
[ ][ ][ ]