Unit 3 Readings
Unit 3 Readings
Outline
Transformation
Basic transformation
Matrix representation and homogeneous coordinates
Composite transformation
Other transformation
The viewing pipeline
Viewing coordinate reference frame
Window-to-viewport coordinate transformation
Point clipping
Line clipping
Polygon clipping
Transformation
Changing Position, shape, size, or orientation of an object is
known as transformation.
1
9/18/2023
Basic Transformation
includes three transformations
• Translation,
• Rotation
• Scaling.
These are known as basic transformation because with
combination of them we can obtain any transformation.
Translation
Transformation that used to reposition the
object along the straight line path. (x',y')
2
9/18/2023
Contd.
We can represent it into single matrix equation in column vector
as;
𝑷 = 𝑷+𝑻
𝒙 𝒙 𝒕𝒙
= 𝒚 + 𝒕
𝒚 𝒚
We can also represent it in row vector form as:
𝑷 = 𝑷+𝑻
𝒙 𝒚 = 𝒙 𝒚 + [𝒕𝒙 𝒕𝒚 ]
Since column vector representation is standard mathematical
notation and also many graphics package like GKS and PHIGS uses
column vector we will also follow column vector representation.
Translation Example
Example: - Translate the triangle [A (10, 10), B (15, 15), C(20, 10)]
2 unit in 𝑥 direction and 1 unit in 𝑦 direction.
𝑡
We know that 𝑃 = 𝑃 + 𝑇 = 𝑃 + 𝑡
10 2 12
For point (10, 10) 𝐴 = + =
10 1 11
15 2 17
For point (15, 15) 𝐵 = + =
15 1 16
20 2 22
For point (10, 10) 𝐶 = + =
10 1 11
Final coordinates after translation are:
[A’ (12, 11), B’ (17, 16), C ’ (22, 11)]
3
9/18/2023
Rotation
It is a transformation that used to reposition the object along the
circular path in the 𝑥𝑦 − 𝑝𝑙𝑎𝑛𝑒.
(x',y')
To generate a rotation we specify a,
• Rotation angle 𝜽.
• Rotation Point (Pivot Point) (𝒙𝒓, 𝒚𝒓 ). (x,y)
θ
Rotation Equation
We first find the equation of rotation when pivot point is at
coordinate origin(0,0).
From figure we can write.
(x',y')
𝒙 = 𝒓 𝒄𝒐𝒔 ∅
𝒚 = 𝒓 𝒔𝒊𝒏 ∅
(x,y)
θ
&
𝒙 = 𝒓 𝒄𝒐𝒔 𝜽 + ∅ = 𝒓 𝒄𝒐𝒔 ∅ 𝒄𝒐𝒔 𝜽 − 𝒓 𝒔𝒊𝒏 ∅ 𝒔𝒊𝒏 𝜽
𝒚 = 𝒓 𝒔𝒊𝒏(∅ + 𝜽) = 𝒓 𝒄𝒐𝒔 ∅ 𝒔𝒊𝒏 𝜽 + 𝒓 𝒔𝒊𝒏 ∅ 𝒄𝒐𝒔 𝜽
4
9/18/2023
Contd.
Now replace 𝒓 𝒄𝒐𝒔 ∅ with 𝒙 and 𝒓 𝒔𝒊𝒏 ∅ with 𝒚 in above equation.
𝒙 = 𝒙 𝒄𝒐𝒔 𝜽 − 𝒚 𝒔𝒊𝒏 𝜽
𝒚 = 𝒙 𝒔𝒊𝒏 𝜽 + 𝒚 𝒄𝒐𝒔 𝜽 (x',y')
(x,y)
θ
∅
column vector matrix equation are,
𝑷 =𝑹 𝑷
𝒙 𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝒙
= 𝒚
𝒚 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽
10
11
5
9/18/2023
Rotation Example
Example: - Locate the new position of the triangle
[A (5, 4), B (8, 3), C (8, 8)] after its rotation by 90o clockwise about
the origin.
As rotation is clockwise we will take 𝜃 = −90° .
𝑃 =𝑅 𝑃
cos(−90) − sin(−90) 5 8 8
𝑃 =
sin(−90) cos(−90) 4 3 8
0 1 5 8 8
𝑃 =
−1 0 4 3 8
4 3 8
𝑃 =
−5 −8 −8
Final coordinates after rotation are: [A’ (4, -5), B’ (3, -8), C ’ (8, -8)]
12
Scaling
Transformation that used to alter the size of an object is known as
scaling.
This operation is carried out by multiplying coordinate value (𝒙, 𝒚)
with scale factors (𝒔𝒙 , 𝒔𝒚 ) respectively.
Equation for scaling is given by,
𝒙 = 𝒙 𝒔𝒙 & 𝒚 = 𝒚 𝒔𝒚
These equation can be represented in column vector matrix
equation as:
𝑷 =𝑺 𝑷
𝒙 𝒔𝒙 𝟎 𝒙
= 𝟎 𝒔𝒚 𝒚
𝒚
Any positive value can be assigned to(𝒔𝒙 , 𝒔𝒚 ).
13
6
9/18/2023
Contd.
Normal scaling will scale as well as reposition the object.
Scale factors less than 1 reduce the size and move object closer to
origin.
Scale factors greater than 1 enlarge the size of object and move
object away from origin
Example scale square with opposite corner coordinate point are
(1, 1) and (2, 2) by scale factor (3, 3)
𝑷 =𝑺 𝑷
𝑥 ′ 𝑥 ′ 3 0 1 2 3 6 3
= =
𝑦 ′ 𝑦 ′ 0 3 1 2 3 6
1
1 3
14
Contd.
Same values of 𝒔𝒙 and 𝒔𝒚 will produce Uniform Scaling.
Different values of 𝒔𝒙 and 𝒔𝒚 will produce Differential (Non
Uniform) Scaling.
Uniform Differential
Scaling Scaling
15
7
9/18/2023
Fixed Point
16
17
8
9/18/2023
Scaling Example
Example: - Consider square with left-bottom corner at (2, 2) and
right-top corner at (6, 6) apply the transformation which makes its
size half.
As we want size half so value of scale factor are 𝑠 = 0.5, 𝑠 = 0.5
and Coordinates of square are [A (2, 2), B (6, 2), C (6, 6), D (2, 6)].
𝑃 =𝑆 𝑃
𝑠 0 2 6 6 2 0.5 0 2 6 6 2
𝑃 = 0 𝑠 =
2 2 6 6 0 0.5 2 2 6 6
1 3 3 1
𝑃 =
1 1 3 3
Final coordinate after scaling are:
[A’ (1, 1), B’ (3, 1), C ’ (3, 3), D’ (1, 3)]
18
19
9
9/18/2023
Contd.
We have matrix representation of basic transformation and we
can express it in the general matrix form as:
𝑷 = 𝑴𝟏 𝑷 + 𝑴𝟐
Where
𝑷 and 𝑷 are initial and final point position,
𝑴𝟏 contains rotation and scaling terms and
𝑴𝟐 contains translational terms associated with pivot point,
fixed point and reposition.
20
Contd.
For efficient utilization we must calculate all sequence of
transformation in one step.
For that reason we reformulate above equation to eliminate the
matrix addition associated with translation terms in matrix 𝑴𝟐 .
We can combine that thing by expanding 2X2 matrix
representation into 3X3 matrices.
It will allows us to convert all transformation into matrix
multiplication.
We need to represent vertex position 𝒙, 𝒚 with homogeneous
coordinate triple 𝒙𝒉 , 𝒚𝒉 , 𝒉 .
𝒙𝒉 𝒚𝒉
Where 𝒙 = ,𝒚= thus we can also write triple as
𝒉 𝒉
(𝒉 𝒙, 𝒉 𝒚, 𝒉).
21
10
9/18/2023
Contd.
For two dimensional geometric transformation we can take value
of 𝒉 is any positive number.
We can get infinite homogeneous representation for coordinate
value (𝒙, 𝒚).
But convenient choice is set 𝒉 = 𝟏 as it is multiplicative identity,
than (𝒙, 𝒚) is represented as (𝒙, 𝒚, 𝟏).
Expressing coordinates in homogeneous coordinates form allows
us to represent all geometric transformation equations as matrix
multiplication.
22
23
11
9/18/2023
24
25
12
9/18/2023
Composite Transformation
In practice we need to apply more than one transformations to get
desired result.
It is time consuming to apply transformation one by one on each
point of object.
So first we multiply all matrix of required transformations which is
known as composite transformation matrix.
Than we use composite transformation matrix to transform object.
For column matrix representation, we form composite
transformations by multiplying matrices from right to left.
26
Multiple Translations
Two successive translations are performed as:
𝑷 = 𝑻 𝒕𝒙𝟐 , 𝒕𝒚𝟐 {𝑻(𝒕𝒙𝟏 , 𝒕𝒚𝟏 ) 𝑷}
𝑷 = {𝑻 𝒕𝒙𝟐 , 𝒕𝒚𝟐 𝑻(𝒕𝒙𝟏 , 𝒕𝒚𝟏 )} 𝑷
𝟏 𝟎 𝒕𝒙𝟐 𝟏 𝟎 𝒕𝒙𝟏
𝑷 = 𝟎 𝟏 𝒕𝒚𝟐 𝟎 𝟏 𝒕𝒚𝟏 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
27
13
9/18/2023
Contd.
𝟏 𝟎 𝒕𝒙𝟐 𝟏 𝟎 𝒕𝒙𝟏
𝑷 = 𝟎 𝟏 𝒕𝒚𝟐 𝟎 𝟏 𝒕𝒚𝟏 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝟏 𝟎 𝒕𝒙𝟏 + 𝒕𝒙𝟐
𝑷 = 𝟎 𝟏 𝒕𝒚𝟏 + 𝒕𝒚𝟐 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑻 𝒕𝒙𝟏 + 𝒕𝒙𝟐 , 𝒕𝒚𝟏 + 𝒕𝒚𝟐 𝑷
Here 𝑷 and 𝑷 are column vector of final and initial point
coordinate respectively.
This concept can be extended for any number of successive
translations.
28
1 0 𝑡 +𝑡 1 0 4 + (−1) 2
𝑃 = 0 1 𝑡 +𝑡 𝑃= 0 1 3+2 3
0 0 1 0 0 1 1
1 0 3 2 5
𝑃 = 0 1 5 3 = 8
0 0 1 1 1
Final Coordinates after translations are 𝑝, (5, 8).
29
14
9/18/2023
Multiple Rotations
Two successive Rotations are performed as:
𝑷 = 𝑹(𝜽𝟐 ) {𝑹(𝜽𝟏 ) 𝑷}
𝑷 = {𝑹 𝜽𝟐 𝑹 𝜽𝟏 } 𝑷
30
Contd.
𝒄𝒐𝒔(𝜽𝟏 +𝜽𝟐 ) −𝒔𝒊𝒏(𝜽𝟏 +𝜽𝟐 ) 𝟎
𝑷 = 𝒔𝒊𝒏(𝜽𝟏 +𝜽𝟐 ) 𝒄𝒐𝒔(𝜽𝟏 +𝜽𝟐 ) 𝟎 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑹(𝜽𝟏 +𝜽𝟐 ) 𝑷
Here 𝑷 and 𝑷 are column vector of final and initial point
coordinate respectively.
This concept can be extended for any number of successive
rotations.
31
15
9/18/2023
𝑐𝑜𝑠(𝜃 +𝜃 ) −𝑠𝑖𝑛(𝜃 +𝜃 ) 0
𝑃 = 𝑠𝑖𝑛(𝜃 +𝜃 ) 𝑐𝑜𝑠(𝜃 +𝜃 ) 0 𝑃
0 0 1
𝑐𝑜𝑠(30 + 60) −𝑠𝑖𝑛(30 + 60) 0
𝑃 = 𝑠𝑖𝑛(30 + 60) 𝑐𝑜𝑠(30 + 60) 0 𝑃
0 0 1
0 −1 0 6 −9
𝑃 = 1 0 0 9 = 6
0 0 1 1 1
Final Coordinates after rotations are 𝑝, (−9, 6).
32
Multiple Scaling
Two successive scaling are performed as:
𝑷 = 𝑺 𝒔𝒙𝟐 , 𝒔𝒚𝟐 {𝑺(𝒔𝒙𝟏 , 𝒔𝒚𝟏 ) 𝑷}
𝑷 = {𝑺 𝒔𝒙𝟐 , 𝒔𝒚𝟐 𝑺 𝒔𝒙𝟏 , 𝒔𝒚𝟏 } 𝑷
𝒔𝒙𝟐 𝟎 𝟎 𝒔𝒙𝟏 𝟎 𝟎
𝑷 = 𝟎 𝒔𝒚𝟐 𝟎 𝟎 𝒔𝒚𝟏 𝟎 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝒔𝒙𝟏 𝒔𝒙𝟐 𝟎 𝟎
𝑷 = 𝟎 𝒔𝒚𝟏 𝒔𝒚𝟐 𝟎 𝑷
𝟎 𝟎 𝟏
33
16
9/18/2023
Contd.
𝒔𝒙𝟏 𝒔𝒙𝟐 𝟎 𝟎
𝑷 = 𝟎 𝒔𝒚𝟏 𝒔𝒚𝟐 𝟎 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑺 𝒔𝒙𝟏 𝒔𝒙𝟐 , 𝒔𝒚𝟏 𝒔𝒚𝟐 𝑷
Here 𝑷 and 𝑷 are column vector of final and initial point
coordinate respectively.
This concept can be extended for any number of successive
scaling.
34
𝑠 𝑠 0 0 2 3 0 0
𝑃 = 0 𝑠 𝑠 0 𝑃= 0 2 3 0 𝑃
0 0 1 0 0 1
6 0 0 2 8 12 48
𝑃 = 0 6 0 2 8 = 12 48
0 0 1 1 1 1 1
Final Coordinates after rotations are 𝑝, (12, 12) and 𝑞 , 48, 48 .
35
17
9/18/2023
36
37
18
9/18/2023
Contd.
𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝒙𝒓 (𝟏 − 𝒄𝒐𝒔 𝜽) + 𝒚𝒓 𝒔𝒊𝒏 𝜽
𝑷 = 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝒚𝒓 (𝟏 − 𝒄𝒐𝒔 𝜽) − 𝒙𝒓 𝒔𝒊𝒏 𝜽 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑹 𝒙𝒓 , 𝒚𝒓 , 𝜽 𝑷
Here 𝑷 and 𝑷 are column vector of final and initial point
coordinate respectively and 𝒙𝒓 , 𝒚𝒓 are the coordinates of pivot-
point.
38
𝑥 = = 7, 𝑦 = =5
As rotation is clockwise we will take 𝜃 = −90° .
𝑃 = 𝑅( , , ) 𝑃
39
19
9/18/2023
Contd.
𝑃 =
cos(−90) − sin(−90) 7(1 − cos(−90)) + 5 sin(−90) 5 8 8
sin(−90) cos(−90) 5(1 − cos(−90)) − 7 sin(−90) 4 3 8
0 0 1 1 1 1
0 1 7(1 − 0) − 5(1) 5 8 8
𝑃 = −1 0 5(1 − 0) + 7(1) 4 3 8
0 0 1 1 1 1
0 1 2 5 8 8
𝑃 = −1 0 12 4 3 8
0 0 1 1 1 1
40
Contd.
0 1 2 5 8 8
𝑃 = −1 0 12 4 3 8
0 0 1 1 1 1
6 5 10
𝑃 = 7 4 4
1 1 1
Final coordinates after rotation are [A’ (6, 7), B’ (5, 4), C ’ (10, 4)].
41
20
9/18/2023
42
𝟏 𝟎 𝒙𝒇 𝒔𝒙 𝟎 𝟎 𝟏 𝟎 −𝒙𝒇
𝑷 = 𝟎 𝟏 𝒚𝒇 𝟎 𝒔𝒚 𝟎 𝟎 𝟏 −𝒚𝒇 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝒔𝒙 𝟎 𝒙𝒇 (𝟏 − 𝒔𝒙 )
𝑷 = 𝟎 𝒔𝒚 𝒚𝒇 (𝟏 − 𝒔𝒚 ) 𝑷
𝟎 𝟎 𝟏
43
21
9/18/2023
Contd.
𝒔𝒙 𝟎 𝒙𝒇 (𝟏 − 𝒔𝒙 )
𝑷 = 𝟎 𝒔𝒚 𝒚𝒇 (𝟏 − 𝒔𝒚 ) 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑺 𝒙𝒇 , 𝒚𝒇 , 𝒔𝒙 , 𝒔𝒚 𝑷
Here 𝑷 and 𝑷 are column vector of final and initial point
coordinate respectively and 𝒙𝒇 , 𝒚𝒇 are the coordinates of fixed-
point.
44
𝑥 = , 𝑦 =
As we want size half so value of scale factor are 𝑠 = 0.5, 𝑠 = 0.5
and Coordinates of square are [A (2, 2), B (6, 2), C (6, 6), D (2, 6)].
𝑃 = 𝑆 𝑥 ,𝑦 ,𝑠 ,𝑠 𝑃
45
22
9/18/2023
Contd.
𝑃 = 𝑆 𝑥 ,𝑦 ,𝑠 ,𝑠 𝑃
𝑠 0 𝑥 (1 − 𝑠 ) 2 6 6 2
𝑃 = 0 𝑠 𝑦 (1 − 𝑠 ) 2 2 6 6
0 0 1 1 1 1 1
0.5 0 2 2 6 6 2
𝑃 = 0 0.5 2 2 2 6 6
0 0 1 1 1 1 1
46
Contd.
0.5 0 2 2 6 6 2
𝑃 = 0 0.5 2 2 2 6 6
0 0 1 1 1 1 1
3 5 5 3
𝑃 = 3 3 5 5
1 1 1 1
Final coordinate after scaling are:
[A’ (3, 3), B’ (5, 3), C ’ (5, 5), D’ (3, 5)]
47
23
9/18/2023
48
Contd.
Suppose we apply scaling factor 𝒔𝟏 and 𝒔𝟐 in direction shown in
figure than we will apply following transformations.
1. Perform a rotation so that the direction for 𝒔𝟏 and 𝒔𝟐 coincide with 𝒙 and
𝒚 axes.
2. Scale the object with specified scale factors.
3. Perform opposite rotation to return points to their original orientations.
(i.e. Inverse of step-1).
49
24
9/18/2023
50
Other Transformation
Some package provides few additional transformations which are
useful in certain applications.
Two such transformations are:
1. Reflection
2. Shear.
51
25
9/18/2023
1. Reflection
A reflection is a transformation that produces a mirror image of an
object.
The mirror image for a two –dimensional reflection is generated
relative to an axis of reflection by rotating the object 180o about
the reflection axis.
Reflection gives image based on position of axis of reflection.
Transformation matrix for few positions are discussed here.
52
1 0 0 x
2’ 3’
𝑅𝑒𝑓 = 0 −1 0
Reflected
0 0 1 Position
1’
This transformation keeps 𝑥 values are same, but flips (Change the
sign) 𝑦 values of coordinate positions.
53
26
9/18/2023
3’ 2’ 2 3
54
−1 0 0
𝑅𝑒𝑓 = 0 −1 0 𝑥
0 0 1
Reflected
Position
55
27
9/18/2023
0 1 0
𝑅𝑒𝑓 = 1 0 0
0 0 1
Original
Position
56
Transformation matrix:
0 −1 0 Original
Position
𝑅𝑒𝑓 = −1 0 0
0 0 1
Reflected
Position
57
28
9/18/2023
Reflection Example
Example: - Find the coordinates after reflection of the triangle
[A (10, 10), B (15, 15), C (20, 10)] about 𝑥 axis.
1 0 0 10 15 20
𝑃 = 0 −1 0 10 15 10
0 0 1 1 1 1
10 15 20
𝑃 = −10 −15 −10
1 1 1
Final coordinate after reflection are:
[A’ (10, -10), B’ (15, -15), C ’ (20, -10)]
58
2. Shear
A transformation that distorts the shape of an object such that the
transformed shape appears as if the object were composed of
internal layers that had been caused to slide over each other is
called shear.
Two common shearing transformations are those that shift
coordinate 𝑥 values and those that shift 𝑦 values.
59
29
9/18/2023
Shear in
Shear relative to 𝑥 − 𝑎𝑥𝑖𝑠 that is 𝑦 = 0 line can be produced by
following equation:
𝒙 = 𝒙 + 𝒔𝒉𝒙 𝒚 , 𝒚 =𝒚
Transformation matrix for that is:
𝟏 𝒔𝒉𝒙 𝟎
𝑺𝒉𝒆𝒂𝒓𝒙 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 = 𝟎 𝟏 𝟎
𝟎 𝟎 𝟏
Here 𝒔𝒉𝒙 is shear parameter.
We can assign any real value to 𝒔𝒉𝒙 .
Before After
𝑦 Shear 𝑦 Shear
𝑥 𝑥
60
Contd.
We can generate 𝑥 − 𝑑𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 shear relative to other reference
line 𝑦 = 𝑦 with following equation:
𝒙 = 𝒙 + 𝒔𝒉𝒙 (𝒚 − 𝒚𝒓𝒆𝒇) , 𝒚 =𝒚
Transformation matrix for that is:
𝟏 𝒔𝒉𝒙 −𝒔𝒉𝒙 𝒚𝒓𝒆𝒇
𝑺𝒉𝒆𝒂𝒓𝒙 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 = 𝟎 𝟏 𝟎
𝟎 𝟎 𝟏
Before After
𝑦 Shear 𝑦 Shear
𝑦𝑟𝑒𝑓 𝑥 𝑦𝑟𝑒𝑓 𝑥
61
30
9/18/2023
Shear in
Example: - Shear the unit square in 𝑥 direction with shear
parameter ½ relative to line 𝑦 = −1.
Here 𝑦 = −1 and 𝑠ℎ = 0.5
Coordinates of unit square are: [A (0, 0), B (1, 0), C (1, 1), D (0, 1)].
1 𝑠ℎ −𝑠ℎ 𝑦 0 1 1 0
𝑃 = 0 1 0 0 0 1 1
0 0 1 1 1 1 1
62
Contd.
1 0.5 −0.5 (−1) 0 1 1 0
𝑃 = 0 1 0 0 0 1 1
0 0 1 1 1 1 1
1 0.5 0.5 0 1 1 0
𝑃 = 0 1 0 0 0 1 1
0 0 1 1 1 1 1
0.5 1.5 2 1
𝑃 = 0 0 1 1
1 1 1 1
Final coordinate after shear are:
[A’ (0.5, 0), B’ (1.5, 0), C ’ (2, 1), D’ (1, 1)]
63
31
9/18/2023
Shear in
Shear relative to 𝑦 − 𝑎𝑥𝑖𝑠 that is 𝑥 = 0 line can be produced by
following equation:
𝒙 =𝒙, 𝒚 = 𝒚 + 𝒔𝒉𝒚 𝒙
Transformation matrix for that is:
𝟏 𝟎 𝟎
𝑺𝒉𝒆𝒂𝒓𝒚 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 = 𝒔𝒉𝒚 𝟏 𝟎
𝟎 𝟎 𝟏
Here 𝒔𝒉𝒚 is shear parameter.
We can assign any real value to 𝒔𝒉𝒚 .
Before After
𝑦 Shear 𝑦 Shear
𝑥 𝑥
64
Contd.
We can generate 𝑦 − 𝑑𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 shear relative to other reference
line 𝑥 = 𝑥 with following equation:
𝒙 = 𝒙, 𝒚 = 𝒚 + 𝒔𝒉𝒚 (𝒙 − 𝒙𝒓𝒆𝒇)
Transformation matrix for that is:
𝟏 𝟎 𝟎
𝑺𝒉𝒆𝒂𝒓𝒚 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 = 𝒔𝒉𝒚 𝟏 −𝒔𝒉𝒚 𝒙𝒓𝒆𝒇
𝟎 𝟎 𝟏
Before After
𝑦 Shear 𝑦 Shear
𝑥𝑟𝑒𝑓 𝑥 𝑥𝑟𝑒𝑓 𝑥
65
32
9/18/2023
Shear in
Example: - Shear the unit square in 𝑦 direction with shear
parameter ½ relative to line 𝑥 = −1.
Here 𝑥 = −1 and 𝑠ℎ = 0.5
Coordinates of unit square are [A (0, 0), B (1, 0), C (1, 1), D (0, 1)].
1 0 0 0 1 1 0
𝑃 = 𝑠ℎ 1 −𝑠ℎ 𝑥 0 0 1 1
0 0 1 1 1 1 1
1 0 0 0 1 1 0
𝑃 = 0.5 1 −0.5 (−1) 0 0 1 1
0 0 1 1 1 1 1
66
Contd.
1 0 0 0 1 1 0
𝑃 = 0.5 1 −0.5 (−1) 0 0 1 1
0 0 1 1 1 1 1
1 0 0 0 1 1 0
𝑃 = 0.5 1 0.5 0 0 1 1
0 0 1 1 1 1 1
0 1 1 0
𝑃 = 0.5 1 2 1.5
1 1 1 1
Final coordinate after shear are:
[A’ (0, 0.5), B’ (1, 1), C ’ (1, 2), D’ (0, 1.5)]
67
33
9/18/2023
Window
YWmax
Viewport
YVmax
YWmin YVmin
68
69
34
9/18/2023
Contd.
Construct World- Convert
Coordinate Scene World-
MC Using Modeling- WC Coordinate to
Coordinate Viewing
Transformations Coordinates
VC
Map Viewing
Map
Coordinate to
Normalized
Normalized Viewing
NVC Viewport to DC
Coordinates using
Device
Window-Viewport
Coordinates
Specifications
70
71
35
9/18/2023
Window-To-Viewport Coordinate
Transformation
Mapping of window coordinate to viewport is called window to
viewport transformation.
We do this using transformation that maintains relative position of
window coordinate into viewport.
That means center coordinates in window must be remains at
center position in viewport.
Window
YWmax
YW Viewport
YVmax YV
XW
XV
YWmin YVmin
XWmin XWmax XVmin XVmax
72
Contd.
We find relative position by equation as follow:
𝑥 −𝑥 𝑥 −𝑥
=
𝑥 −𝑥 𝑥 −𝑥
Similarly
𝑦 −𝑦 𝑦 −𝑦
=
𝑦 −𝑦 𝑦 −𝑦
Window
YWmax
YW Viewport
YVmax YV
XW
XV
YWmin YVmin
XWmin XWmax XVmin XVmax
73
36
9/18/2023
Contd.
Solving for 𝑥 direction by making viewport position as subject we
obtain:
𝑥 −𝑥 𝑥 −𝑥
=
𝑥 −𝑥 𝑥 −𝑥
𝑥 −𝑥
𝑥 =𝑥 + 𝑥 −𝑥
𝑥 −𝑥
𝑥 =𝑥 + (𝑥 − 𝑥 )𝑠
Where
𝑥 −𝑥
𝑠 =
𝑥 −𝑥
74
Contd.
Similarly Solving for 𝑦 direction by making viewport position as
subject we obtain:
𝑦 −𝑦 𝑦 −𝑦
=
𝑦 −𝑦 𝑦 −𝑦
𝑦 −𝑦
𝑦 =𝑦 + 𝑦 −𝑦
𝑦 −𝑦
𝑦 =𝑦 + 𝑦 −𝑦 𝑠
Where
𝑦 −𝑦
𝑠 =
𝑦 −𝑦
75
37
9/18/2023
Contd.
We can also map window to viewport with the set of
transformation:
• Perform a scaling transformation using a fixed-point position of
(𝑥𝑤𝑚𝑖𝑛, 𝑦𝑤𝑚𝑖𝑛) that scales the window area to the size of the viewport.
• Translate the scaled window area to the position of the viewport.
For maintaining relative proportions we take (𝑠𝑥 = 𝑠𝑦).
If both are not equal then we get stretched or contracted in either
the 𝑥 or 𝑦 direction when displayed on the output device.
Characters are handle in two different way
• One way is simply maintain relative position like other primitive.
• Other is to maintain standard character size even though viewport size is
enlarged or reduce.
76
Contd.
For each display device we can use different window to viewport
transformation. This mapping is known as workstation
transformation.
Also we can use two different displays devices and we map
different window-to-viewport on each one.
Normalized Space
WS1 Viewport WS2 Viewport
Viewport
Monitor 1 Monitor 2
WS1 Window WS2 Window
77
38