0% found this document useful (0 votes)
21 views21 pages

Bca 203 CG Unit 3

Basic information about computer graphics such as pixels, interactive devices, uses, applications, etc.

Uploaded by

awwyan9368
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)
21 views21 pages

Bca 203 CG Unit 3

Basic information about computer graphics such as pixels, interactive devices, uses, applications, etc.

Uploaded by

awwyan9368
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/ 21

COMPUTER GRAPHICS UNIT 3

Polygon:
Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with
particular colors, you need to determine the pixels falling on the border of the polygon and those
which fall inside the polygon. In this chapter, we will see how we can fill polygons using different
techniques.

Scan Line Algorithm


This algorithm works by intersecting scanline with polygon edges and fills the polygon between
pairs of intersections. The following steps depict how this algorithm works.

Step 1 − Find out the Ymin and Ymax from the given polygon.

Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3.

Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0, p1, p1, p2, and
p2, p3.

Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.

Flood Fill Algorithm


Sometimes we come across an object where we want to fill the area and its boundary with
different colors. We can paint such objects with a specified interior color instead of searching for
particular boundary color as in boundary filling algorithm.

Instead of relying on the boundary of the object, it relies on the fill color. In other words, it replaces
the interior color of the object with the fill color. When no more pixels of the original interior color
exist, the algorithm is completed.

Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in the
pixels. But instead of looking for the boundary color, it is looking for all adjacent pixels that are a
part of the interior.

Boundary Fill Algorithm


The boundary fill algorithm works as its name. This algorithm picks a point inside an object and
starts to fill until it hits the boundary of the object. The color of the boundary and the color that we
fill should be different for this algorithm to work.

In this algorithm, we assume that color of the boundary is same for the entire object. The boundary
fill algorithm can be implemented by 4-connected pixels or 8-connected pixels.

4-Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We are putting the pixels
above, below, to the right, and to the left side of the current pixels and this process will continue
until we find a boundary with different color.
Algorithm
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.

Step 2 − Define the boundary values of the polygon.

Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the
boundary pixels reached.

If getpixel(x, y) = dcol then repeat step 4 and 5

Step 4 − Change the default color with the fill color at the seed point.

setPixel(seedx, seedy, fcol)

Step 5 − Recursively follow the procedure with four neighborhood points.

FloodFill (seedx – 1, seedy, fcol, dcol)


FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)

Step 6 − Exit

There is a problem with this technique. Consider the case as shown below where we tried to fill the
entire region. Here, the image is filled only partially. In such cases, 4-connected pixels technique
cannot be used.

8-Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We are putting pixels above,
below, right and left side of the current pixels as we were doing in 4-connected technique.

In addition to this, we are also putting pixels in diagonals so that entire area of the current pixel is
covered. This process will continue until we find a boundary with different color.
Algorithm
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.

Step 2 − Define the boundary values of the polygon.

Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the
boundary pixels reached

If getpixel(x,y) = dcol then repeat step 4 and 5

Step 4 − Change the default color with the fill color at the seed point.

setPixel(seedx, seedy, fcol)

Step 5 − Recursively follow the procedure with four neighbourhood points

FloodFill (seedx – 1, seedy, fcol, dcol)


FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)

Step 6 − Exit

The 4-connected pixel technique failed to fill the area as marked in the following figure which
won’t happen with the 8-connected technique.

Inside-outside Test
This method is also known as counting number method. While filling an object, we often need to
identify whether particular point is inside the object or outside it. There are two methods by which
we can identify whether particular point is inside an object or outside.

Odd-Even Rule
Nonzero winding number rule

Odd-Even Rule
In this technique, we will count the edge crossing along the line from any point x, y to infinity. If the
number of interactions is odd, then the point x, y is an interior point; and if the number of
interactions is even, then the point x, y is an exterior point. The following example depicts this
concept.

From the above figure, we can see that from the point x, y, the number of interactions point on the
left side is 5 and on the right side is 3. From both ends, the number of interaction points is odd, so
the point is considered within the object.

Nonzero Winding Number Rule


This method is also used with the simple polygons to test the given point is interior or not. It can be
simply understood with the help of a pin and a rubber band. Fix up the pin on one of the edge of
the polygon and tie-up the rubber band in it and then stretch the rubber band along the edges of
the polygon.

When all the edges of the polygon are covered by the rubber band, check out the pin which has
been fixed up at the point to be test. If we find at least one wind at the point consider it within the
polygon, else we can say that the point is not inside the polygon.
In another alternative method, give directions to all the edges of the polygon. Draw a scan line
from the point to be test towards the left most of X direction.

Give the value 1 to all the edges which are going to upward direction and all other -1 as
direction values.

Check the edge direction values from which the scan line is passing and sum up them.

If the total sum of this direction value is non-zero, then this point to be tested is an interior
point, otherwise it is an exterior point.

In the above figure, we sum up the direction values from which the scan line is passing then
the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior point.
Loading [MathJax]/jax/output/HTML-CSS/jax.js
Transformation
Changing Position, shape, size, or orientation of an object on display is known as transformation.

Basic 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.


• It is a transformation that used to reposition the object along the straight line path from one coordinate
location to another.
• It is rigid body transformation so we need to translate whole object.
• We translate two dimensional point by adding translation distance 𝒕𝒙 and 𝒕𝒚 to the original coordinate
position (𝒙, 𝒚) to move at new position (𝒙′, 𝒚′) as:
𝒙′ = 𝒙 + 𝒕𝒙 & 𝒚′ = 𝒚 + 𝒕𝒚
• Translation distance pair (𝒕𝒙,𝒕𝒚) is called a Translation Vector or Shift Vector.
• 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 since many graphics package
like GKS and PHIGS uses column vector we will also follow column vector representation.
• 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
𝑃′ = 𝑃 + 𝑇
𝑡𝑥
𝑃′ = [𝑃] + [ ]
𝑡𝑦
For point (10, 10)
10 2
𝐴′ = [ ] + [ ]
10 1
12
𝐴 =[ ]

11
For point (15, 15)
15 2
𝐵′ = [ ] + [ ]
15 1
17
𝐵 =[ ]

16
For point (10, 10)
20 2
𝐶′ = [ ] + [ ]
10 1
22
𝐶′ = [ ]
11
• 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.


• From figure we can write.
𝒙 = 𝒓 𝐜𝐨𝐬 ∅
𝒚 = 𝒓 𝐬𝐢𝐧 ∅
and
𝒙′ = 𝒓 𝐜𝐨𝐬(𝜽 + ∅) = 𝒓 𝐜𝐨𝐬 ∅ 𝐜𝐨𝐬 𝜽 − 𝒓 𝐬𝐢𝐧 ∅ 𝐬𝐢𝐧 𝜽
𝒚′ = 𝒓 𝐬𝐢𝐧(∅ + 𝜽) = 𝒓 𝐜𝐨𝐬 ∅ 𝐬𝐢𝐧 𝜽 + 𝒓 𝐬𝐢𝐧 ∅ 𝐜𝐨𝐬 𝜽
• Now replace 𝒓 𝐜𝐨𝐬 ∅ with 𝒙 and 𝒓 𝐬𝐢𝐧 ∅ with 𝒚 in above equation.
𝒙′ = 𝒙 𝐜𝐨𝐬 𝜽 − 𝒚 𝐬𝐢𝐧 𝜽
𝒚′ = 𝒙 𝐬𝐢𝐧 𝜽 + 𝒚 𝐜𝐨𝐬 𝜽
• We can write it in the form of column vector matrix equation as;
𝑷′ = 𝑹 ∙ 𝑷
𝒙′ 𝒙
= 𝐜𝐨𝐬 𝜽 − 𝐬𝐢𝐧 𝜽 ∙
[𝒚′ ] [ ] [ 𝒚]
𝐬𝐢𝐧 𝜽 𝐜𝐨𝐬 𝜽
• Rotation about arbitrary point is illustrated in below figure.

(𝒙′, 𝒚′)

(𝒙, 𝒚)
𝜽


(𝒙𝒓, 𝒚𝒓)

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 90 o
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)].

Scaling

Fig. 3.4: - Scaling.


• It is a transformation that used to alter the size of an object.
• This operation is carried out by multiplying coordinate value (𝒙, 𝒚) with scaling factor (𝒔𝒙, 𝒔𝒚)
respectively.
• So equation for scaling is given by:
𝒙′ = 𝒙 ∙ 𝒔𝒙
𝒚′ = 𝒚 ∙ 𝒔𝒚
• These equation can be represented in column vector matrix equation as:
𝑷′ = 𝑺 ∙ 𝑷
′ 𝒙
[𝒙 ] = [𝒔𝒙 𝟎 ∙
[ ]
𝒚′ 𝟎 𝒔𝒚] 𝒚
• Any positive value can be assigned to(𝒔𝒙, 𝒔𝒚).
• Values less than 1 reduce the size while values greater than 1 enlarge the size of object, and object
remains unchanged when values of both factor is 1.
• Same values of 𝒔𝒙 and 𝒔𝒚 will produce Uniform Scaling. And different values of 𝒔𝒙 and 𝒔𝒚 will produce
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.


• 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)].
𝑃′ = 𝑆 ∙ 𝑃
𝑠𝑥 0 2 6 6 2
𝑃′ = [ ][ ]
0 𝑠𝑦 2 2 6 6

𝑃 =[ 0.5 0 ] [2 6 6 2]
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)].

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.
• 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 translation al terms associated with pivot point, fixed point and reposition.
• For efficient utilization we must calculate all sequence of transformation in one step and 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 but we need to represent vertex
position (𝒙, 𝒚) with homogeneous coordinate triple (𝒙𝒉, 𝒚𝒉, 𝒉) Where 𝒙 = 𝒙𝒉 , 𝒚 = 𝒚𝒉 thus we can also
𝒉 𝒉
write triple as (𝒉 ∙ 𝒙, 𝒉 ∙ 𝒚, 𝒉).
• 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

𝑷′ = 𝑻(𝒕 ,𝒕𝒙 𝒚) ∙ 𝑷
𝒙′ 𝟏 𝟎 𝒕𝒙 𝒙
[𝒚′] = [𝟎 𝟏 𝒕𝒚] [𝒚]
𝟏 𝟎 𝟎 𝟏 𝟏
NOTE: - Inverse of translation matrix is obtain by putting −𝒕𝒙 & − 𝒕𝒚 instead of 𝒕𝒙 & 𝒕𝒚.
Rotation

𝑷′ = 𝑹(𝜽) ∙ 𝑷
𝒙′ 𝐜𝐨𝐬 𝜽 − 𝐬𝐢𝐧 𝜽 𝟎 𝒙
[𝒚′] = [𝐬𝐢𝐧 𝜽 𝐜𝐨𝐬 𝜽 𝟎] [𝒚]
𝟏 𝟎 𝟎 𝟏 𝟏
NOTE: - Inverse of rotation matrix is obtained by replacing 𝜽 by −𝜽.
Scaling

𝑷′ = 𝑺(𝒔𝒙,𝒔𝒚) ∙ 𝑷
𝒙′ 𝒔𝒙 𝟎 𝟎 𝒙
[𝒚′] = [ 𝟎 𝒔𝒚 𝟎] [𝒚]
𝟏 𝟎 𝟎 𝟏 𝟏
NOTE: - Inverse of scaling matrix is obtained by replacing 𝒔𝒙 & 𝒔𝒚 by 𝟏 & 𝟏 respectively.
𝒔𝒙 𝒔𝒚

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.
• This concept can be extended for any number of successive translations.
Example: Obtain the final coordinates after two translations on point 𝑝(2,3) with translation vector
(4, 3) and (−1, 2) respectively.

𝑃′ = 𝑇(𝑡𝑥1 + 𝑡𝑥2, 𝑡𝑦1 + 𝑡𝑦2) ∙ 𝑃

1 0 𝑡𝑥1 + 𝑡𝑥2 1 0 4 + (−1) 2


𝑃′ = [0 1 𝑡𝑦1 + 𝑡𝑦2] ∙ 𝑃 = [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).

Rotations
• Two successive Rotations are performed as:
𝑷′ = 𝑹(𝜽𝟐) ∙ {𝑹(𝜽𝟏) ∙ 𝑷}
𝑷′ = {𝑹(𝜽𝟐) ∙ 𝑹(𝜽𝟏)} ∙ 𝑷
𝐜𝐨𝐬 𝜽𝟐 − 𝐬𝐢𝐧 𝜽𝟐 𝟎 𝐜𝐨𝐬 𝜽𝟏 −𝐬𝐢𝐧 𝜽𝟏 𝟎
𝑷 = [𝐬𝐢𝐧 𝜽𝟐
′ 𝐜𝐨𝐬 𝜽𝟐 𝟎] [𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟏 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝐜𝐨𝐬 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟐 𝐬𝐢𝐧 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 − 𝐬𝐢𝐧 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 𝟎
𝑷′ = [𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 + 𝐬𝐢𝐧 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟐 𝐬𝐢𝐧 𝜽𝟏 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏
𝐜𝐨𝐬(𝜽𝟏 + 𝜽𝟐) −𝐬𝐢𝐧(𝜽𝟏 + 𝜽𝟐) 𝟎
𝑷′ = [𝐬𝐢𝐧(𝜽𝟏 + 𝜽𝟐) 𝐜𝐨𝐬(𝜽𝟏 + 𝜽𝟐) 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏
𝑷′ = 𝑹(𝜽𝟏 + 𝜽𝟐) ∙ 𝑷
Here 𝑷′ and 𝑷 are column vector of final and initial point coordinate respectively.
• 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.
𝑃′ = 𝑅(𝜃1 + 𝜃2) ∙ 𝑃
𝑐𝑜𝑠(𝜃1 + 𝜃2) −𝑠𝑖𝑛(𝜃1 + 𝜃2) 0
𝑃′ = [𝑠𝑖𝑛(𝜃1 + 𝜃2) 𝑐𝑜𝑠(𝜃1 + 𝜃2) 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).

Scaling
• Two successive scaling are performed as:
𝑷′ = 𝑺(𝒔𝒙𝟐, 𝒔𝒚𝟐) ∙ {𝑺(𝒔𝒙𝟏, 𝒔𝒚𝟏) ∙ 𝑷}
𝑷′ = {𝑺(𝒔𝒙𝟐, 𝒔𝒚𝟐) ∙ 𝑺(𝒔𝒙𝟏, 𝒔𝒚𝟏)} ∙ 𝑷
𝒔𝒙𝟐 𝟎 𝟎 𝒔𝒙𝟏 𝟎 𝟎
𝑷′ = [ 𝟎 𝒔𝒚𝟐 𝟎] [ 𝟎 𝒔𝒚𝟏 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝒔𝒙𝟏 ∙ 𝒔𝒙𝟐 𝟎 𝟎
𝑷′ = [ 𝟎 𝒔𝒚𝟏 ∙ 𝒔𝒚𝟐 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏
𝑷′ = 𝑺(𝒔𝒙𝟏 ∙ 𝒔𝒙𝟐, 𝒔𝒚𝟏 ∙ 𝒔𝒚𝟐) ∙ 𝑷
Here 𝑷′ and 𝑷 are column vector of final and initial point coordinate respectively.
• This concept can be extended for any number of successive scaling.
Example: Obtain the final coordinates after two scaling on line 𝑝𝑞 [𝑝(2,2), 𝑞(8, 8)] with scaling factors are
(2, 2) and (3, 3) respectively.

𝑃′ = 𝑆(𝑠𝑥1 ∙ 𝑠𝑥2, 𝑠𝑦1 ∙ 𝑠𝑦2) ∙ 𝑃

𝑠𝑥1 ∙ 𝑠𝑥2 0 0 2∙3 0 0


𝑃′ = [ 0 𝑠𝑦1 ∙ 𝑠𝑦2 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).

General Pivot-Point Rotation


(𝒙𝒓, 𝒚𝒓) (𝒙𝒓, 𝒚𝒓)

(a) (b) (c) (d)


Original Position Translation of Object Rotation Translation of Object so
of Object and so that Pivot Point about that Pivot Point is Return
Pivot Point. (𝒙𝒓, 𝒚𝒓) is at Origin. Origin. to Position (𝒙𝒓, 𝒚𝒓) .

Fig. 3.6: - 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).
• Let’s find matrix equation for this
𝑷′ = 𝑻(𝒙𝒓, 𝒚𝒓) ∙ [𝑹(𝜽) ∙ {𝑻(−𝒙𝒓, −𝒚𝒓) ∙ 𝑷}]
𝑷′ = {𝑻(𝒙𝒓, 𝒚𝒓) ∙ 𝑹(𝜽) ∙ 𝑻(−𝒙𝒓, −𝒚𝒓)} ∙ 𝑷
𝟏 𝟎 𝒙𝒓 𝐜𝐨𝐬 𝜽 − 𝐬𝐢𝐧 𝜽 𝟎 𝟏 𝟎 −𝒙𝒓
𝑷 = [𝟎 𝟏 𝒚𝒓] [𝐬𝐢𝐧 𝜽
′ 𝐜𝐨𝐬 𝜽 𝟎] [𝟎 𝟏 −𝒚𝒓] ∙ 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝐜𝐨𝐬 𝜽 − 𝐬𝐢𝐧 𝜽 𝒙𝒓(𝟏 − 𝐜𝐨𝐬 𝜽) + 𝒚𝒓 𝐬𝐢𝐧 𝜽
𝑷′ = [𝐬𝐢𝐧 𝜽 𝐜𝐨𝐬 𝜽 𝒚𝒓(𝟏 − 𝐜𝐨𝐬 𝜽) − 𝒙𝒓 𝐬𝐢𝐧 𝜽] ∙ 𝑷
𝟎 𝟎 𝟏
𝑷′ = 𝑹(𝒙𝒓, 𝒚𝒓𝜽) ∙ 𝑷
Here 𝑷′ and 𝑷 are column vector of final and initial point coordinate respectively and (𝒙𝒓, 𝒚𝒓) are the
coordinates of pivot-point.
• Example: - Locate the new position of the triangle [A (5, 4), B (8, 3), C (8, 8)] after its rotation by 90 o
clockwise about the centroid.
Pivot point is centroid of the triangle so:
5+8+8
𝑥 = = 7, 𝑦 4+3+8
𝑟 𝑟 = =5
3 3
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
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
11 13 18
𝑃′ = [ 7 4 4]
1 1 1
• Final coordinates after rotation are [A’ (11, 7), B’ (13, 4), C’ (18, 4)].

General Fixed-Point Scaling

(𝒙𝒇, 𝒚𝒇) (𝒙𝒇, 𝒚𝒇)

(c) (d)
(a) (b)
Scale Object with Translate Object so that
Original Position Translate Object so
Respect to Origin Fixed Point is Return to
of Object and that Fixed Point
Position (𝒙𝒇, 𝒚𝒇) .
Fixed Point (𝒙𝒇, 𝒚𝒇) is at Origin

Fig. 3.7: - 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).
• Let’s find matrix equation for this
𝑷′ = 𝑻(𝒙𝒇, 𝒚𝒇) ∙ [𝑺(𝒔𝒙, 𝒔𝒚) ∙ {𝑻(−𝒙𝒇, −𝒚𝒇) ∙ 𝑷}]
𝑷′ = {𝑻(𝒙𝒇, 𝒚𝒇) ∙ 𝑺(𝒔𝒙, 𝒔𝒚) ∙ 𝑻(−𝒙𝒇, −𝒚𝒇)} ∙ 𝑷
𝟏 𝟎 𝒙𝒇 𝒔𝒙 𝟎 𝟎 𝟏 𝟎 −𝒙𝒇
𝑷 = [𝟎 𝟏 𝒚𝒇] [ 𝟎 𝒔𝒚 𝟎] [𝟎 𝟏 −𝒚𝒇] ∙ 𝑷

𝟎 𝟎 𝟏 𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝒔𝒙 𝟎 𝒙𝒇(𝟏 − 𝒔𝒙)
𝑷′ = [ 𝟎 𝒔𝒚 𝒚𝒇(𝟏 − 𝒔𝒚)] ∙ 𝑷
𝟎 𝟎 𝟏
𝑷 = 𝑺(𝒙𝒇, 𝒚𝒇, 𝒔𝒙, 𝒔𝒚) ∙ 𝑷

Here 𝑷′ and 𝑷 are column vector of final and initial point coordinate respectively and (𝒙𝒇, 𝒚𝒇) are the
coordinates of fixed-point.
• 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:
6− 2
𝑥 =2+ , 𝑦 6−2
𝑓 𝑓 =2+
2 2
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 𝑥𝑓(1 − 𝑠𝑥) 2 6 6 2
𝑃 = [ 0 𝑠𝑦 𝑦𝑓(1 − 𝑠𝑦)] [2 2 6 6]

0 0 1 1 1 11
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
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)]

General Scaling Directions


𝒔𝟐

𝒔𝟏

Fig. 3.8: - General scaling direction.


• Parameter 𝒔𝒙 and 𝒔𝒚 scale the object along 𝒙 and 𝒚 directions. We can scale an object in other directions
by rotating the object to align the desired scaling directions with the coordinate axes before applying the
scaling transformation.
• 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).
• 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.


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 𝒚 = 𝟎 , 𝒕𝒉𝒆 𝒙 𝒂𝒙𝒊𝒔.

y
1 Original
Position
2 3

x
2’ 3’
Reflected
1’ Position

Fig. 3.9: - Reflection about x - axis.


• This transformation keeps x values are same, but flips (Change the sign) y values of coordinate
positions.

1 0 0
[0 −1 0]
0 0 1

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

y
1’ 1 Original
Reflected
Position Position
3’ 2’ 2 3

Fig. 3.10: - Reflection about y - axis.


• This transformation keeps y values are same, but flips (Change the sign) x values of coordinate
positions.

−1 0 0
[ 0 1 0]
0 0 1

Transformation matrix for reflection about the 𝑶𝒓𝒊𝒈𝒊𝒏.


y
Original
3 Position

1 2

1’ x
3’
Reflected 2’
Position

Fig. 3.11: - Reflection about origin.


• This transformation flips (Change the sign) x and y both values of coordinate positions.

−1 0 0
[ 0 −1 0]
0 0 1

Transformation matrix for reflection about the line 𝒙 = 𝒚 .

y
Original x=y line
Position
3
2 1
1’
3’
Reflected
2’ Position

Fig. 3.12: - Reflection about x=y line.


• This transformation interchange x and y values of coordinate positions.

0 1 0
[1 0 0]
0 0 1
Transformation matrix for reflection about the line 𝒙 = −𝒚 .

x=-y line 3 y

1 2

Original
’ 1’
3 Position
2’
Reflected
Position
x

Fig. 3.12: - Reflection about x=-y line.


• This transformation interchange x and y values of coordinate positions.

0 −1 0
[−1 0 0]
0 0 1

• Example: - Find the coordinates after reflection of the triangle [A (10, 10), B (15, 15), C (20, 10)] about x
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)]

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 x values and those that shift y
values.

Shear in 𝒙 − 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 .

Before After
Y Shear Shear
Y

X X

Fig. 3.13: - Shear in x-direction.


• 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 𝒔𝒉𝒙.
• We can generate 𝑥 − 𝑑𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 shear relative to other reference line 𝑦 = 𝑦𝑟𝑒𝑓 with following equation:
𝒙′ = 𝒙 + 𝒔𝒉𝒙 ∙ (𝒚 − 𝒚𝒓𝒆𝒇) , 𝒚′ = 𝒚
• Transformation matrix for that is:
𝟏 𝒔𝒉𝒙 −𝒔𝒉𝒙 ∙ 𝒚𝒓𝒆𝒇
[𝟎 𝟏 𝟎 ]
𝟎 𝟎 𝟏
• Example: - Shear the unit square in x 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
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)]

Shear in 𝒚 − 𝒅𝒊𝒓𝒆𝒄𝒕𝒊𝒐𝒏 .

Before
Y Shear After
Y
Shear

X X

Fig. 3.14: - Shear in y-direction.


• 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 𝒔𝒉𝒚.
• We can generate 𝑦 − 𝑑𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛 shear relative to other reference line 𝑥 = 𝑥𝑟𝑒𝑓 with following equation:
𝒙′ = 𝒙, 𝒚′ = 𝒚 + 𝒔𝒉𝒚 ∙ (𝒙 − 𝒙𝒓𝒆𝒇)
• Transformation matrix for that is:
𝟏 𝟎 𝟎
[𝒔𝒉𝒚 𝟏 −𝒔𝒉𝒚 ∙ 𝒙𝒓𝒆𝒇]
𝟎 𝟎 𝟏
• Example: - Shear the unit square in y 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 10
𝑃 = [𝑠ℎ𝑦
′ 1 −𝑠ℎ 𝑦 ∙ 𝑥 𝑟𝑒𝑓] [0 0 1 1]
0 0 1 1 1 11
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 10
𝑃′ = [0.5 1 0.5] [0 0 1 1]
0 0 1 1 1 11
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)]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy