0% found this document useful (0 votes)
24 views38 pages

Unit 3 Readings

The document outlines various geometric transformations including translation, rotation, and scaling, along with their mathematical representations and examples. It explains the use of matrix representation and homogeneous coordinates for efficient processing of transformation sequences. Key concepts such as fixed point scaling and composite transformations are also discussed.

Uploaded by

21bcs008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views38 pages

Unit 3 Readings

The document outlines various geometric transformations including translation, rotation, and scaling, along with their mathematical representations and examples. It explains the use of matrix representation and homogeneous coordinates for efficient processing of transformation sequences. Key concepts such as fixed point scaling and composite transformations are also discussed.

Uploaded by

21bcs008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

9/18/2023

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')

 Adding translation distance 𝒕𝒙 and 𝒕𝒚 to


ty
the original coordinate position (𝒙, 𝒚) (x,y)
respectively we move point at new
tx
position (𝒙 , 𝒚 ).
 𝒙 = 𝒙 + 𝒕𝒙 & 𝒚 = 𝒚 + 𝒕𝒚
 Translation distance pair (𝒕𝒙, 𝒕𝒚 ) is called a (x',y')
Translation Vector or Shift Vector.
ty
 It is rigid body transformation so we need (x,y)
to translate whole object.
tx

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)
θ

 +ve value of rotation angle defines counter clockwise rotation.


 -ve value of rotation angle defines clockwise rotation.

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

Rotation about arbitrary point


 Transformation equation for rotation of a point about pivot point
(𝒙𝒓, 𝒚𝒓 ) is:
 𝒙 = 𝒙𝒓 + (𝒙 − 𝒙𝒓 ) 𝒄𝒐𝒔 𝜽 − (𝒚 − 𝒚𝒓 ) 𝒔𝒊𝒏 𝜽
 𝒚 = 𝒚𝒓 + 𝒙 − 𝒙𝒓 𝒔𝒊𝒏 𝜽 + (𝒚 − 𝒚𝒓 ) 𝒄𝒐𝒔 𝜽
 These equations are differing from rotation about origin and its
matrix representation is also different.
 Its matrix equation can be obtained by
simple method. (x',y')

 Rotation is also rigid body transformation (x,y)


so we need to rotate each point of θ

object.
(xr,yr)

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 Scaling


 We can control the position of object after scaling by keeping one
position fixed called Fix point (𝒙𝒇 , 𝒚𝒇 ).

Fixed Point

16

Fixed Point Scaling Equation


 Equation for scaling with fixed point position as (𝒙𝒇 , 𝒚𝒇 ) is:
 𝒙 = 𝒙𝒇 + (𝒙 − 𝒙𝒇 )𝒔𝒙 𝒚 = 𝒚𝒇 + (𝒚 − 𝒚𝒇 )𝒔𝒚
 𝒙 = 𝒙𝒇 + 𝒙𝒔𝒙 − 𝒙𝒇 𝒔𝒙 𝒚 = 𝒚𝒇 + 𝒚𝒔𝒚 − 𝒚𝒇 𝒔𝒚
 𝒙 = 𝒙𝒔𝒙 + 𝒙𝒇 (𝟏 − 𝒔𝒙 ) 𝒚 = 𝒚𝒔𝒚 + 𝒚𝒇 (𝟏 − 𝒔𝒚 )
 Polygons are scaled by applying scaling at coordinates and
redrawing.
 Other body like circle and ellipse will scale using its defining
parameters.
 For example ellipse will scale using its semi major axis, semi minor
axis and center point scaling and redrawing at that position.

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

Matrix Representation and Homogeneous


Coordinates
 Many graphics application involves sequence of geometric
transformations.
 For example in design and picture construction application we
perform Translation, Rotation, and scaling to fit the picture
components into their proper positions.
 For efficient processing we will reformulate transformation
sequences.

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

Homogeneous Matrix for


Translation
 Let’s see each representation with 𝒉 = 𝟏
𝑷 = 𝑻(𝒕𝒙 ,𝒕𝒚 ) 𝑷
𝒙 𝟏 𝟎 𝒕𝒙 𝒙
𝒚 = 𝟎 𝟏 𝒕𝒚 𝒚
𝟏 𝟎 𝟎 𝟏 𝟏
 Inverse of translation matrix is obtain by putting −𝒕𝒙 & − 𝒕𝒚
instead of 𝒕𝒙 & 𝒕𝒚 .

23

11
9/18/2023

Homogeneous Matrix for


Rotation
𝑷 = 𝑹(𝜽) 𝑷
𝒙 𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝟎 𝒙
𝒚 = 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝟎 𝒚
𝟏 𝟎 𝟎 𝟏 𝟏
 Inverse of rotation matrix is obtained by replacing 𝜽 by −𝜽.

24

Homogeneous Matrix for


Scaling
𝑷 = 𝑺(𝒔𝒙 ,𝒔𝒚 ) 𝑷
𝒙 𝒔𝒙 𝟎 𝟎 𝒙
𝒚 = 𝟎 𝒔𝒚 𝟎 𝒚
𝟏 𝟎 𝟎 𝟏 𝟏
 Inverse of scaling matrix is obtained by replacing 𝒔𝒙 & 𝒔𝒚
𝟏 𝟏
by & respectively.
𝒔𝒙 𝒔𝒚

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

Multiple Translations Example


 Example: Obtain the final coordinates after two translations on
point 𝑝(2,3) with translation vector (4, 3) and
(−1, 2) respectively.
 𝑃 =𝑇 𝑡 +𝑡 ,𝑡 +𝑡 𝑃

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

Multiple Rotations Example


 Example: Obtain the final coordinates after two rotations on point
𝑝(6,9) with rotation angles are 30 and 60 respectively.
 𝑃 = 𝑅(𝜃 +𝜃 ) 𝑃

𝑐𝑜𝑠(𝜃 +𝜃 ) −𝑠𝑖𝑛(𝜃 +𝜃 ) 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

Multiple Scaling Example


 Example: Obtain the final coordinates after two scaling on line 𝑝𝑞
[𝑝 2,2 , 𝑞(8, 8)] with scaling factors are 2, 2 and
(3, 3) respectively.
 𝑃 =𝑆 𝑠 𝑠 ,𝑠 𝑠 𝑃

𝑠 𝑠 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

General Pivot-Point Rotation


 For rotating object about arbitrary point called pivot point we
need to apply following sequence of transformation.
1. Translate the object so that the pivot-point coincides with the coordinate
origin.
2. Rotate the object about the coordinate origin with specified angle.
3. Translate the object so that the pivot-point is returned to its original
position (i.e. Inverse of step-1).

36

General Pivot-Point Rotation


Equation
 Let’s find matrix equation for this
 𝑷 = 𝑻 𝒙𝒓 , 𝒚𝒓 𝑹 𝜽 𝑻 −𝒙𝒓 , −𝒚𝒓 𝑷
 𝑷 = {𝑻 𝒙𝒓 , 𝒚𝒓 𝑹 𝜽 𝑻 −𝒙𝒓 , −𝒚𝒓 } 𝑷

𝟏 𝟎 𝒙𝒓 𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝟎 𝟏 𝟎 −𝒙𝒓


 𝑷 = 𝟎 𝟏 𝒚𝒓 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝟎 𝟎 𝟏 −𝒚𝒓 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝒙𝒓 (𝟏 − 𝒄𝒐𝒔 𝜽) + 𝒚𝒓 𝒔𝒊𝒏 𝜽
 𝑷 = 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝒚𝒓 (𝟏 − 𝒄𝒐𝒔 𝜽) − 𝒙𝒓 𝒔𝒊𝒏 𝜽 𝑷
𝟎 𝟎 𝟏

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

General Pivot-Point Rotation


Example
 Example: - Locate the new position of the triangle ABC
[A (5, 4), B (8, 3), C (8, 8)] after its rotation by 90o clockwise about
the centroid.
 Pivot point is centroid of the triangle so:

 𝑥 = = 7, 𝑦 = =5
 As rotation is clockwise we will take 𝜃 = −90° .
 𝑃 = 𝑅( , , ) 𝑃

cos 𝜃 − sin 𝜃 𝑥 (1 − cos 𝜃) + 𝑦 sin 𝜃 5 8 8


 𝑃 = sin 𝜃 cos 𝜃 𝑦 (1 − cos 𝜃) − 𝑥 sin 𝜃 4 3 8
0 0 1 1 1 1

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

General Fixed-Point Scaling


 For scaling object with position of one point called fixed point will
remains same, we need to apply following sequence of
transformation.
1. Translate the object so that the fixed-point coincides with the coordinate
origin.
2. Scale the object with respect to the coordinate origin with specified scale
factors.
3. Translate the object so that the fixed-point is returned to its original
position (i.e. Inverse of step-1).

42

General Fixed-Point Scaling


Equation
 Let’s find matrix equation for this
 𝑷 = 𝑻 𝒙𝒇 , 𝒚𝒇 𝑺 𝒔𝒙 , 𝒔𝒚 𝑻 −𝒙𝒇 , −𝒚𝒇 𝑷
 𝑷 = {𝑻 𝒙𝒇 , 𝒚𝒇 𝑺 𝒔𝒙 , 𝒔𝒚 𝑻 −𝒙𝒇 , −𝒚𝒇 } 𝑷

𝟏 𝟎 𝒙𝒇 𝒔𝒙 𝟎 𝟎 𝟏 𝟎 −𝒙𝒇
 𝑷 = 𝟎 𝟏 𝒚𝒇 𝟎 𝒔𝒚 𝟎 𝟎 𝟏 −𝒚𝒇 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏

𝒔𝒙 𝟎 𝒙𝒇 (𝟏 − 𝒔𝒙 )
 𝑷 = 𝟎 𝒔𝒚 𝒚𝒇 (𝟏 − 𝒔𝒚 ) 𝑷
𝟎 𝟎 𝟏

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

General Fixed-Point 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 such that its center remains same.
 Fixed point is center of square so:

 𝑥 = , 𝑦 =
 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 4(1 − 0.5) 2 6 6 2


 𝑃 = 0 0.5 4(1 − 0.5) 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

General Scaling Directions


 Parameter 𝒔𝒙 and 𝒔𝒚 scale the object along 𝒙 and 𝒚 directions.
 We can scale an object in other directions also.
 By rotating the object to align the desired scaling directions with
the coordinate axes before applying the scaling transformation.

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

General Scaling Directions


Equation
 Let’s find matrix equation for this
𝟏
 𝑷 =𝑹 𝜽 𝑺 𝒔𝟏 , 𝒔𝟐 𝑹 𝜽 𝑷
𝟏
 𝑷 = {𝑹 𝜽 𝑺 𝒔𝟏 , 𝒔𝟐 𝑹 𝜽 } 𝑷

𝒄𝒐𝒔 𝜽 𝒔𝒊𝒏 𝜽 𝟎 𝒔𝒙 𝟎 𝟎 𝒄𝒐𝒔 𝜽 − 𝒔𝒊𝒏 𝜽 𝟎


 𝑷 = − 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝟎 𝟎 𝒔𝒚 𝟎 𝒔𝒊𝒏 𝜽 𝒄𝒐𝒔 𝜽 𝟎 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏

𝒔𝟏 𝒄𝒐𝒔𝟐 𝜽 + 𝒔𝟐 𝒔𝒊𝒏𝟐 𝜽 (𝒔𝟐 − 𝒔𝟏 ) 𝒄𝒐𝒔 𝜽 𝒔𝒊𝒏 𝜽 𝟎


 𝑷 = (𝒔𝟐 − 𝒔𝟏 ) 𝒄𝒐𝒔 𝜽 𝒔𝒊𝒏 𝜽 𝒔𝟏 𝒔𝒊𝒏𝟐 𝜽 + 𝒔𝟐 𝒄𝒐𝒔𝟐 𝜽 𝟎 𝑷
𝟎 𝟎 𝟏
 Here 𝑷 and 𝑷 are column vector of final and initial point coordinate
respectively and 𝜽 is the angle between actual scaling direction and our
standard coordinate axes.

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

Reflection About X-Axis


 For reflection about the line y
1 Original
 𝒚 = 𝟎 , 𝒕𝒉𝒆 𝒙 𝒂𝒙𝒊𝒔 Position
 Transformation matrix: 2 3

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

Reflection About Y-Axis


 For reflection about the line 𝒙 = 𝟎 , 𝒕𝒉𝒆 𝒚 𝒂𝒙𝒊𝒔
−1 0 0
 Transformation matrix: 𝑅𝑒𝑓 = 0 1 0
0 0 1
 This transformation keeps 𝑦 values are same, but flips (Change the
sign) 𝑥 values of coordinate positions.
𝑦
1’ 1 Original
Reflected
Position
Position

3’ 2’ 2 3

54

Reflection About Origin


 For reflection about the 𝑶𝒓𝒊𝒈𝒊𝒏. 𝑦 Original
Position
 Transformation matrix:

−1 0 0
 𝑅𝑒𝑓 = 0 −1 0 𝑥
0 0 1

Reflected
Position

 This transformation flips (Change the sign) 𝑥 and 𝑦 both values of


coordinate positions.

55

27
9/18/2023

Reflection About X = Y Line


 For reflection about the line 𝒙 = 𝒚. 𝑦 Reflected
Position
 Transformation matrix:

0 1 0
 𝑅𝑒𝑓 = 1 0 0
0 0 1
Original
Position

 This transformation interchange 𝑥 and 𝑦 values of coordinate


positions.

56

Reflection About X = - Y Line


 For reflection about the line 𝒙 = −𝒚. 𝑦

 Transformation matrix:

0 −1 0 Original
Position
 𝑅𝑒𝑓 = −1 0 0
0 0 1
Reflected
Position

 This transformation interchange 𝑥 and 𝑦 values of coordinate


positions.

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

1 0.5 −0.5 (−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 and Viewport


 Window: Area selected in world-coordinate for display is called
window. It defines what is to be viewed.
 Viewport: Area on a display device in which window image is
display (mapped) is called viewport. It defines where to display.

Window
YWmax

Viewport
YVmax

YWmin YVmin

XWmin XWmax XVmin XVmax

68

The Viewing Pipeline


 In many case window and viewport are rectangle, also other
shape may be used as window and viewport.
 In general finding device coordinates of viewport from word
coordinates of window is called as viewing transformation.
 Sometimes we consider this viewing transformation as window-to-
viewport transformation but in general it involves more steps.
 Let’s see steps involved in viewing pipeline.

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

Viewing Coordinate Reference


Frame
 We can obtain reference frame in any
direction and at any position.
 For handling such condition
• first of all we translate reference frame origin
to standard reference frame origin.
• Then we rotate it to align it to standard axis.

 In this way we can adjust window in any reference frame.


 It is illustrate by following transformation matrix: 𝑀 , = 𝑅𝑇
 Where T is translation matrix and R is rotation matrix.

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

You might also like