Chapter Three 2D Transformation & Viewing, Assignments of Compiler Design

Transformation 2  Changing Position, shape, size, or orientation of an object on display is known as transformation.  Basic transformation includes three transformations Translation, Rotation, and Scaling.  These three transformations are known as basic transformation because with combination of these three transformations we can obtain any transformation.

Typology: Assignments

2020/2021

Uploaded on 05/27/2021

esku-lulu
esku-lulu 🇬🇧

9 documents

1 / 51

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Samara University
College of Engineering and Technology
Department of Computer Science
Computer Graphics(CoSc3121)
Chapter Three
2D Transformation & Viewing
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Chapter Three 2D Transformation & Viewing and more Assignments Compiler Design in PDF only on Docsity!

Samara University

College of Engineering and Technology

Department of Computer Science

Computer Graphics(CoSc3121)

Chapter Three

2D Transformation & Viewing

Transformation

 Changing Position, shape, size, or orientation of an object on display is known as transformation.

 Basic transformation includes three transformations Translation , Rotation , and Scaling.  These three transformations are known as basic transformation because with combination of these three transformations we can obtain any transformation.

Translation

(𝒙′, 𝒚′)

𝒕𝒚 (𝒙, 𝒚)

Fig. 3.1: - Translation.

Translation…

Example : - Translate the triangle [A (10, 10), B (15, 15), C (20, 10)] 2 unit in x direction and 1 unit in y direction. We know that

 Final coordinates after translation are [A’^ (12, 11), B’^ (17, 16), C’^ (22, 11)].

Rotation

 It is a transformation that used to reposition the object along the circular path in the XY - plane.  To generate a rotation we specify a rotation angle 𝜽 and the position of the Rotation Point ( Pivot Point ) (𝒙𝒓,𝒚𝒓) about which the object is to be rotated.  Positive value of rotation angle defines counter clockwise rotation and negative value of rotation angle defines clockwise rotation.  We first find the equation of rotation when pivot point is at coordinate origin(𝟎, 𝟎).

(𝒙′, 𝒚′)

(𝒙, 𝒚)

𝜽

Fig. 3.2: - Rotation.

Rotation…

Fig. 3.3: - Rotation about pivot 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 that we will discuss later in this chapter.  Rotation is also rigid body transformation so we need to rotate each point of object.  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°.

Rotation…

 Final coordinates after rotation are [A’^ (4, -5), B’^ (3, -8), C’^ (8, -8)].

Scaling…

Fig. 3.4: - Scaling.

Scaling…

Differential Scaling.

 Objects transformed with above equation are both scale and repositioned.  Scaling factor with value less than 1 will move object closer to origin, while scaling factor with value greater than 1 will move object away from origin.  We can control the position of object after scaling by keeping one position fixed called Fix point (𝒙𝒇, 𝒚𝒇) that point will remain unchanged after the scaling transformation.

Fixed Point

Fig. 3.5: - Fixed point scaling.

Scaling…

 Equation for scaling with fixed point position as (𝒙𝒇, 𝒚𝒇) is: 𝒙′^ = 𝒙𝒇 + (𝒙 − 𝒙𝒇)𝒔𝒙 𝒚′^ = 𝒚𝒇 + (𝒚 − 𝒚𝒇)𝒔𝒚 𝒙′^ = 𝒙𝒇 + 𝒙𝒔𝒙 − 𝒙𝒇𝒔𝒙 𝒚′^ = 𝒚𝒇 + 𝒚𝒔𝒚 − 𝒚𝒇𝒔𝒚 𝒙′^ = 𝒙𝒔𝒙 + 𝒙𝒇(𝟏 − 𝒔𝒙) 𝒚′^ = 𝒚𝒔𝒚 + 𝒚𝒇(𝟏 − 𝒔𝒚)  Matrix equation for the same will discuss in later section.  Polygons are scaled by applying scaling at coordinates and redrawing while 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.  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)]. 𝑃′^ = 𝑆 ∙ 𝑃

 Final coordinate after scaling are [A’^ (1, 1), B’^ (3, 1), C’^ (3, 3), D’^ (1, 3)].

Matrix Representation and homogeneous coordinates…

 For two dimensional geometric transformation we can take value of 𝒉 is any positive number so 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.  Let’s see each representation with 𝒉 = 𝟏

Translation

Rotation

Scaling

Composite Transformation

 We can set up a matrix for any sequence of transformations as a composite transformation matrix by calculating the matrix product of individual transformation.  For column matrix representation of coordinate positions, we form composite transformations by multiplying matrices in order from right to left.

Translations

 Two successive translations are performed as:

 Here 𝑷′^ and 𝑷 are column vector of final and initial point coordinate respectively.

Composite Transformation…

Rotations

 Two successive Rotations are performed as:

 Here 𝑷′^ and 𝑷 are column vector of final and initial point coordinate respectively.

Composite Transformation…

Rotations

 This concept can be extended for any number of successive rotations.  Example: Obtain the final coordinates after two rotations on point 𝑝(6,9) with rotation angles are 30𝑜^ and 60𝑜^ respectively.

 Final Coordinates after rotations are 𝑝,(−9, 6).

Composite Transformation…

Scaling

 Final Coordinates after rotations are 𝑝,(12, 12) and 𝑞,(48, 48).

General Pivot-Point Rotation

Other Transformation

 Some package provides few additional transformations which are useful in certain applications. Two such transformations are reflection and shear.

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.

Transformation matrix for reflection about the line 𝒚 = 𝟎 , 𝒕𝒉𝒆 𝒙 𝒂𝒙𝒊𝒔.

Fig. 3.9: - Reflection about x - axis.