0% found this document useful (0 votes)
14 views26 pages

CG Study Material Graphics-40-65

The document discusses various graphics primitives, focusing on integer evaluation of x-intercepts, polygon filling techniques, and methods for determining point locations relative to polygons using odd-even and nonzero winding number rules. It also covers scan-line fill algorithms for curved boundaries, boundary fill algorithms, flood-fill algorithms, and character generation methods including bitmap and outline fonts. Additionally, it describes stroke and starburst methods for character generation, emphasizing efficiency and storage considerations.

Uploaded by

Somnath Gunjal
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)
14 views26 pages

CG Study Material Graphics-40-65

The document discusses various graphics primitives, focusing on integer evaluation of x-intercepts, polygon filling techniques, and methods for determining point locations relative to polygons using odd-even and nonzero winding number rules. It also covers scan-line fill algorithms for curved boundaries, boundary fill algorithms, flood-fill algorithms, and character generation methods including bitmap and outline fonts. Additionally, it describes stroke and starburst methods for character generation, emphasizing efficiency and storage considerations.

Uploaded by

Somnath Gunjal
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

Unit-2 – Graphics Primitives

 Using this equation we can perform integer evaluation of 𝑥 intercept by initializing a counter to 0, then
incrementing counter by the value of ∆𝑥 each time we move up to a new scan line.
 When the counter value becomes equal to or greater than ∆𝑦, we increment the current 𝑥 intersection
value by 1 and decrease the counter by the value ∆𝑦.
 This procedure is seen by following figure.

Line with slope 7/3

Decerement 0
4
Decerement 1
5
Decerement 2
6
3
Y0 0 Y0

X0 X0

∆𝑥
Fig. 2.19: - line with slope 7/3 and its integer calculation using equation 𝑥𝑘+1 = 𝑥𝑘 + ∆𝑦.
 Steps for above procedure
1. Suppose m = 7/3
2. Initially, set counter to 0, and increment to 3 (which is 𝛥𝑥).
3. When move to next scan line, increment counter by adding ∆𝑥
4. When counter is equal or greater than 7 (which is 𝛥𝑦), increment the x-intercept (in other words, the 𝑥-
intercept for this scan line is one more than the previous scan line), and decrement counter by 7(which
is ∆𝑦).
 To efficiently perform a polygon fill, we can first store the polygon boundary in a sorted edge table that
contains all the information necessary to process the scan lines efficiently.
 We use bucket sort to store the edge sorted on the smallest 𝑦 value of each edge in the correct scan line
positions.
 Only the non-horizontal edges are entered into the sorted edge table.
 Figure below shows one example of storing edge table.

20
Unit-2 – Graphics Primitives
Scan-
Line
Number

Yc Yb Xc 1/mcb
B

Yd Yc Xd 1/mdb Ye Xd 1/mde

C Scan Line Yc
Ya Yb Xc 1/mcb Yb Xa 1/mab
C’ E .
Scan Line Yd .
.
Scan Line Ya D 1
0
A

Fig. 2.20: - A polygon and its sorted edge table.


 Each entry in the table for a particular scan line contains the maximum 𝑦 values for that edges, the 𝑥
intercept value for edge, and the inverse slope of the edge.
 For each scan line the edges are in sorted order from left to right.
 Than we process the scan line from the bottom to top for whole polygon and produce active edge list for
each scan line crossing the polygon boundaries.
 The active edge list for a scan line contains all edges crossed by that line, with iterative coherence
calculation used to obtain the edge intersections.

Inside-Outside Tests
 In area filling and other graphics operation often required to find particular point is inside or outside the
polygon.
 For finding which region is inside or which region is outside most graphics package use either odd even
rule or the nonzero winding number rule.

Odd Even Rule


 It is also called the odd parity rule or even odd rule.
 By conceptually drawing a line from any position 𝑝 to a distant point outside the coordinate extents of
the object and counting the number of edges crossing by this line is odd, than 𝑝 is an interior point.
Otherwise 𝑝 is exterior point.
 To obtain accurate edge count we must sure that line selected is does not pass from any vertices.
 This is shown in figure 2.21(a).

21
Unit-2 – Graphics Primitives

Fig. 2.21: - Identifying interior and exterior region for a self-intersecting polygon.

Nonzero Winding Number Rule


 This method counts the number of times the polygon edges wind around a particular point in the
counterclockwise direction. This count is called the winding number, and the interior points of a two-
dimensional object are defined to be those that have a nonzero value for the winding number.
 We apply this rule by initializing winding number with 0 and then draw a line for any point 𝑝 to distant
point beyond the coordinate extents of the object.
 The line we choose must not pass through vertices.
 Then we move along that line we find number of intersecting edges and we add 1 to winding number if
edge cross our line from right to left and subtract 1 from winding number if edges cross from left to
right.
 The final value of winding number is nonzero then the point is interior and if winding number is zero the
point is exterior.
 This is shown in figure 2.21(b).
 One way to determine directional edge crossing is to take the vector cross product of a vector 𝑈 along
the line from 𝑝 to distant point with the edge vector 𝐸 for each edge that crosses the line.
 If 𝑧 component of the cross product𝑈 × 𝐸 for a particular edge is positive that edge is crosses from right
to left and we add 1 to winding number otherwise the edge is crossing from left to right and we subtract
1 from winding number.

Comparison between Odd Even Rule and Nonzero Winding Rule


 For standard polygons and simple object both rule gives same result but for more complicated shape
both rule gives different result which is illustrated in figure 2.21.

Scan-Line Fill of Curved Boundary Areas


 Scan-line fill of region with curved boundary is more time consuming as intersection calculation now
involves nonlinear boundaries.
 For simple curve such as circle or ellipse scan line fill process is straight forward process.
 We calculate the two scan line intersection on opposite side of the curve.
 This is same as generating pixel position along the curve boundary using standard equation of curve.
 Then we fill the color between two boundary intersections.
 Symmetry property is used to reduce the calculation.
 Similar method can be used for fill the curve section.

22
Unit-2 – Graphics Primitives
Boundary Fill Algorithm/ Edge Fill Algorithm
 In this method, edges of the polygons are drawn. Then starting with some seed, any point inside the
polygon we examine the neighbouring pixels to check whether the boundary pixel is reached.
 If boundary pixels are not reached, pixels are highlighted and the process is continued until boundary
pixels are reached.
 Boundary defined regions may be either 4-cormected or 8-connected. as shown in the Figure below

(a) Four connected region (b) Eight connected region

Fig. 2.22: - Neighbor pixel connected to one pixel.


 If a region is 4-connected, then every pixel in the region may be reached by a combination of moves in
only four directions: left, right, up and down.
 For an 8-connected region every pixel in the region may be reached by a combination of moves in the
two horizontal, two vertical, and four diagonal directions.
 In some cases, an 8-connected algorithm is more accurate than the 4-connected algorithm. This is
illustrated in Figure below. Here, a 4-connected algorithm produces the partial fill.

Seed

Fig. 2.23: - partial filling resulted due to using 4-connected algorithm.


 The following procedure illustrates the recursive method for filling a 4-connected region with color
specified in parameter fill color (f-color) up to a boundary color specified with parameter boundary color
(b-color).
 Procedure :
boundary-fill4(x, y, f-color, b-color)
{
if(getpixel (x,y) ! = b-color&&gepixel (x, y) ! = f-color)
{
putpixel (x, y, f-color)
boundary-fill4(x + 1, y, f-color, b-color);

23
Unit-2 – Graphics Primitives
boundary-fill4(x, y + 1, f-color, b-color);
boundary-fill4(x - 1, y, f-color, b-color);
boundary-fill4(x, y - l, f-color, b-color);
}
}
 Note: 'getpixel' function gives the color of .specified pixel and 'putpixel' function draws the pixel with
specified color.
 Same procedure can be modified according to 8 connected region algorithm by including four additional
statements to test diagonal positions, such as (𝑥 + 1, 𝑦 + 1).
 This procedure requires considerable stacking of neighbouring points more, efficient methods are
generally employed.
 This method fill horizontal pixel spans across scan lines, instead of proceeding to 4 connected or 8
connected neighbouring points.
 Then we need only stack a beginning position for each horizontal pixel span, instead of stacking all
unprocessed neighbouring positions around the current position.
 Starting from the initial interior point with this method, we first fill in the contiguous span of pixels on
this starting scan line.
 Then we locate and stack starting positions for spans on the adjacent scan lines, where spans are defined
as the contiguous horizontal string of positions bounded by pixels displayed in the area border color.
 At each subsequent step, we unstack the next start position and repeat the process.
 An example of how pixel spans could be filled using this approach is illustrated for the 4-connected fill
region in Figure below.

2
(a)
1
2

3
(b)
1
3

5 6
6
4
(c) 5
1
4

24
Unit-2 – Graphics Primitives

4
(d) 5
1
4

Fig. 2.24: - Boundary fill across pixel spans for a 4-connected area.

Flood-Fill Algorithm
 Sometimes it is required to fill in an area that is not defined within a single color boundary.
 In such cases we can fill areas by replacing a specified interior color instead of searching for a boundary
color.
 This approach is called a flood-fill algorithm. Like boundary fill algorithm, here we start with some seed
and examine the neighbouring pixels.
 However, here pixels are checked for a specified interior color instead of boundary color and they are
replaced by new color.
 Using either a 4-connected or 8-connected approach, we can step through pixel positions until all
interior point have been filled.
 The following procedure illustrates the recursive method for filling 4-connected region using flood-fill
algorithm.
 Procedure :
flood-fill4(x, y, new-color, old-color)
{
if(getpixel (x,y) = = old-color)
{
putpixel (x, y, new-color)
flood-fill4 (x + 1, y, new-color, old -color);
flood-fill4 (x, y + 1, new -color, old -color);
flood-fill4 (x - 1, y, new -color, old -color);
flood-fill4 (x, y - l, new -color, old-color);
}
}
 Note: 'getpixel' function gives the color of .specified pixel and 'putpixel' function draws the pixel with
specified color.

Character Generation
 We can display letters and numbers in variety of size and style.
 The overall design style for the set of character is called typeface.
 Today large numbers of typefaces are available for computer application for example Helvetica, New
York platino etc.
 Originally, the term font referred to a set of cast metal character forms in a particular size and format,
such as 10-point Courier Italic or 12- point Palatino Bold. Now, the terms font and typeface are often
used interchangeably, since printing is no longer done with cast metal forms.
 Two different representations are used for storing computer fonts.

25
Unit-2 – Graphics Primitives
Bitmap Font/ Bitmapped Font
 A simple method for representing the character shapes in a particular typeface is to use rectangular grid
patterns.
 Figure below shows pattern for particular letter.
1 1 1 1 1 1 0
0 1 1 0 0 1 1
0 1 1 0 0 1 1
0 1 1 1 1 1 0
0 1 1 0 0 1 1
0 1 1 0 0 1 1
1 1 1 1 1 1 0

Fig. 2.25: - Grid pattern for letter B.


 When the pattern in figure 2.25 is copied to the area of frame buffer, the 1 bits designate which pixel
positions are to be displayed on the monitor.
 Bitmap fonts are the simplest to define and display as character grid only need to be mapped to a frame-
buffer position.
 Bitmap fonts require more space because each variation (size and format) must be stored in a font
cache.
 It is possible to generate different size and other variation from one set but this usually does not
produce good result.

Outline Font
 In this method character is generated using curve section and straight line as combine assembly.
 Figure below shows how it is generated.

Fig. 2.26: - outline for letter B.


 To display the character shown in figure 2.26 we need to fill interior region of the character.
 This method requires less storage since each variation does not required a distinct font cache.
 We can produce boldface, italic, or different sizes by manipulating the curve definitions for the character
outlines.
 But this will take more time to process the outline fonts, because they must be scan converted into the
frame buffer.

26
Unit-2 – Graphics Primitives
Stroke Method

Start

Fig. 2.27: - Stroke Method for Letter A.


 It uses small line segments to generate a character.
 The small series of line segments are drawn like a stroke of a pen to form a character as shown in figure.
 We can generate our own stroke method by calling line drawing algorithm.
 Here it is necessary to decide which line segments are needs for each character and then draw that line
to display character.
 It support scaling by changing length of line segment.

Starbust Method

03 04 03 04
13 14 13 14
02 23 05 02 23 05
17 18 17
18
01 06 01 06
21 21
12 22 07 12 22 07
20 20
24 19 24 19
11 08 11 08
16 15 16 15
10 09 10 09

(a) (b)

Fig. 2.28: - (a) Starbust Method. (b) Letter V using starbust method
 In this method a fix pattern of line segments are used to generate characters.
 As shown in figure 2.28 there are 24 line segments.
 We highlight those lines which are necessary to draw a particular character.
 Pattern for particular character is stored in the form of 24 bit code. In which each bit represents
corresponding line having that number.
 That code contains 0 or 1 based on line segment need to highlight. We put bit value 1 for highlighted line
and 0 for other line.
 Code for letter V is
110011100001001100000000
 This technique is not used now a days because:
1. It requires more memory to store 24 bit code for single character.

27
Unit-2 – Graphics Primitives
2. It requires conversion from code to character.
3. It doesn’t provide curve shapes.

Line Attributes
 Basic attributes of a straight line segment are its type, its dimension, and its color. In some graphics
packages, lines can also be displayed using selected pen or brush option.

Line Type

Fig. 2.29: - Line type

 Possible selection for the line-type attribute includes solid lines, dashed lines, and dotted lines etc.
 We modify a line –drawing algorithm to generate such lines by setting the length and spacing of
displayed solid sections along the line path.
 A dashed line could be displayed by generating an inter dash spacing that is equal to the length of the
solid sections. Both the length of the dashes and the inter dash spacing are often specified as user
options.
 To set line type attributes in a PHIGS application program, a user invokes the function:
setLinetype(It)
 Where parameter lt is assigned a positive integer value of 1, 2, 3, 4… etc. to generate lines that are,
respectively solid, dashed, dotted, or dash-dotted etc.
 Other values for the line-type parameter It could be used to display variations in the dot-dash patterns.
Once the line-type parameter has been set in a PHIGS application program, all subsequent line-drawing
commands produce lines with this Line type.
 Raster graphics generates these types by plotting some pixel and some pixel is off along the line path.
We can generate different patterns by specifying 1 for on pixel and 0 for off pixel then we can generate
1010101 patter as a dotted line.
 It is used in many application for example comparing data in graphical form.

Line Width
 Implementation of line-width options depends on the capabilities of the output device.
 A heavy line on a video monitor could be displayed as adjacent parallel lines, while a pen plotter might
require pen changes.
 To set line width attributes in a PHIGS application program, a user invokes the function:
setLinewidthScalFactor (lw)
 Line-width parameter lw is assigned a positive number to indicate the relative width of the line to be
displayed.
 Values greater than 1 produce lines thicker than the standard line width and values less than the 1
produce line thinner than the standard line width.

28
Unit-2 – Graphics Primitives
 In raster graphics we generate thick line by plotting above and below pixel of line path when slope
|𝑚| < 1 and by plotting left and right pixel of line path when slope |𝑚| > 1 which is illustrated in below
figure.

Fig. 2.30: - Double-wide raster line with slope |𝑚| < 1 generated with vertical pixel spans.

Fig. 2.31: - Raster line with slope |𝑚| > 1 and line-width parameter 𝑙𝑤 = 4 plotted with horizontal pixel
spans.
 As we change width of the line we can also change line end which are shown below which illustrate all
three types of ends.

Fig. 2.32: - Thick lines drew with (a) butt caps, (b) projecting square caps, and (c) round caps.
 Similarly we generates join of two lines of modified width are shown in figure below which illustrate all
three type of joins.

Fig. 2.33: - Thick lines segments connected with (a) miter join, (b) round join, and (c) bevel join.

Line Color
 The name itself suggests that it is defining color of line displayed on the screen.
 By default system produce line with current color but we can change this color by following function in
PHIGS package as follows:
setPolylineColorIndex (lc)
 In this lc is constant specifying particular color to be set.

29
Unit-2 – Graphics Primitives
Pen and Brush Options
 In some graphics packages line is displayed with pen and brush selections.
 Options in this category include shape, size, and pattern.
 Some possible pen or brush are shown in below figure.

Fig. 2.34: - Pen and brush shapes for line display.


 These shapes can be stored in a pixel mask that identifies the array of pixel positions that are to be set
along the line path.
 Lines generated with pen (or brush) shapes can be displayed in various widths by changing the size of
the mask.
 Also, lines can be displayed with selected patterns by superimposing the pattern values onto the pen or
brush mask.

Color and Greyscale Levels


 Various color and intensity-level options can be made available to a user, depending on the capabilities
and design objectives of a particular system.
 General purpose raster-scan systems, for example, usually provide a wide range of colors, while random-
scan monitors typically offer only a few color choices, if any.
 In a color raster system, the number of color choices available depends on the amount of storage
provided per pixel in the frame buffer
 Also, color-information can be stored in the frame buffer in two ways: We can store color codes directly
in the frame buffer, or we can put the color codes in a separate table and use pixel values as an index
into this table
 With direct storage scheme we required large memory for frame buffer when we display more color.
 While in case of table it is reduced and we call it color table or color lookup table.

30
Unit-2 – Graphics Primitives
Color Lookup Table
 Color values of 24 bit is stored in lookup table and in frame buffer we store only 8 bit index which gives
index of required color stored into lookup table. So that size of frame buffer is reduced and we can
display more color.
 When we display picture using this technique on output screen we look into frame buffer where index of
the color is stored and take 24 bit color value from look up table corresponding to frame buffer index
value and display that color on particular pixel.
Color
Lookup
Frame Buffer Table
0 To Red Gun
To Green Gun
To Blue Gun

196 2081 00000000 00001000 00100001


196

255

Fig. 2.35: - color lookup table.

Greyscale
 With monitors that have no color capability, color function can be used in an application program to set
the shades of grey, or greyscale for display primitives.
 Numeric values between 0-to-1 can be used to specify greyscale levels.
 This numeric values is converted in binary code for store in raster system.
 Table below shows specification for intensity codes for a four level greyscale system.

Intensity Code Stored Intensity Values In The Displayed Greyscale


Frame Buffer Binary Code
0.0 0 00 Black
0.33 1 01 Dark grey
0.67 2 10 Light grey
1.0 3 11 White
Table 2.1: - Intensity codes for a four level greyscale system.
 In this example, any intensity input value near 0.33 would be stored as the binary value 01 in the frame
buffer, and pixels with this value would be displayed as dark grey.
 If more bits are available per pixel we can obtain more levels of grey scale for example with 3 bit per
pixel we can achieve 8 levels of greyscale.

Area-Fill Attributes
 For filling any area we have choice between solid colors or pattern to fill all these are include in area fill
attributes.
 Area can be painted by various burses and style.
31
Unit-2 – Graphics Primitives
Fill Styles
 Area are generally displayed with three basic style hollow with color border, filled with solid color, or
filled with some design.
 In PHIGS package fill style is selected by following function.
setInteriorStyle (fs)
 Value of fs include hollow, solid, pattern etc.
 Another values for fill style is hatch, which is patterns of line like parallel line or crossed line.
 Figure bellow shows different style of filling area.

Fig. 2.36: - Different style of area filling.


 For setting interior color in PHIGS package we use:
setInteriorColorIndex (fc)
 Where fc specify the fill color.

Pattern Fill
 We select the pattern with
setInteriorStyleIndex (pi)
 Where pattern index parameter pi specifies position in pattern table entry.
 Figure below shows pattern table.

Index(pi) Pattern(cp)
1 4 0
[ ]
0 4
2 2 1 2
[1 2 1]
2 1 2
Table 2.2: - Pattern table.
 For example, the following set of statements would fill the area defined in the fillArea command with
the second pattern type stored in the pattern table:
SetInteriorStyle( pattern ) ;
setInteriorStyleIndex ( 2 ) ;
fillArea (n, points);
 Separate table can be maintain for hatch pattern and we can generate our own table with required
pattern.
 Other function used for setting other style as follows
setpatternsize (dx, dy)
setPaternReferencePoint (positicn)
 We can create our own pattern by setting and resetting group of pixel and then map it into the color
matrix.

32
Unit-2 – Graphics Primitives
Soft Fill
 Soft fill is modified boundary fill and flood fill algorithm in which we are fill layer of color on back ground
color so that we can obtain the combination of both color.
 It is used to recolor or repaint so that we can obtain layer of multiple color and get new color
combination.
 One use of this algorithm is soften the fill at boundary so that blurred effect will reduce the aliasing
effect.
 For example if we fill t amount of foreground color then pixel color is obtain as:
𝑝 = 𝑡𝐹 + (1 − 𝑡)𝐵
 Where F is foreground color and B is background color
 If we see this color in RGB component then:
𝑝 = (𝑝𝑟, 𝑝𝑔, 𝑝𝑏) 𝑓 = (𝑓𝑟, 𝑓𝑔, 𝑓𝑏) 𝑏 = (𝑏𝑟, 𝑏𝑔, 𝑏𝑏)
 Then we can calculate 𝑡 as follows:
𝑃𝑘 − 𝐵 𝑘
𝑡=
𝐹𝑘 − 𝐵𝑘
 If we use more than two color say three at that time equation becomes as follow:
𝑝 = 𝑡0𝐹 + 𝑡1𝐵1 + (1 − 𝑡0 − 𝑡1)𝐵2
 Where the sum of coefficient 𝑡0, 𝑡1, and (1 − 𝑡0 − 𝑡1) is 1.

Character Attributes
 The appearance of displayed characters is controlled by attributes such as font, size, color, and
orientation.
 Attributes can be set for entire string or may be individually.

Text Attributes
 In text we are having so many style and design like italic fonts, bold fonts etc.
 For setting the font style in PHIGS package we have one function which is:
setTextFont (tf)
 Where tf is used to specify text font
 It will set specified font as a current character.
 For setting color of character in PHIGS we have function:
setTextColorIndex (tc)
 Where text color parameter tc specifies an allowable color code.
 For setting the size of the text we use function.
setCharacterheight (ch)
 For scaling the character we use function.
setCharacterExpansionFacter (cw)
 Where character width parameter cw is set to a positive real number that scale the character body
width.
 Spacing between character is controlled by function
setCharacterSpacing (cs)
 Where character spacing parameter cs can be assigned any real value.
 The orientation for a displayed character string is set according to the direction of the character up
vector:
setCharacterUpVector (upvect)
 Parameter upvect in this function is assigned two values that specify the 𝑥 and 𝑦 vector components.
33
Unit-2 – Graphics Primitives
 Text is then displayed so that the orientation of characters from baseline to cap line is in the direction of
the up vector.
 For setting the path of the character we use function:
setTextPath (tp)
 Where the text path parameter tp can be assigned the value: right, left, up, or down.
 It will set the direction in which we are writing.
 For setting the alignment of the text we use function.
setTextAlignment (h, v)
 Where parameter h and v control horizontal and vertical alignment respectively.
 For specifying precision for text display is given with function.
setTextPrecision (tpr)
 Where text precision parameter tpr is assigned one of the values: string, char, or stroke.
 The highest-quality text is produced when the parameter is set to the value stroke.

Marker Attributes
 A marker symbol display single character in different color and in different sizes.
 For marker attributes implementation by procedure that load the chosen character into the raster at
defined position with the specified color and size.
 We select marker type using function.
setMarkerType (mt)
 Where marker type parameter mt is set to an integer code.
 Typical codes for marker type are the integers 1 through 5, specifying, respectively, a dot (.), a vertical
cross (+), an asterisk (*), a circle (o), and a diagonal cross (x). Displayed marker types are centred on the
marker coordinates.
 We set the marker size with function.
SetMarkerSizeScaleFactor (ms)
 Where parameter marker size ms assigned a positive number according to need for scaling.
 For setting marker color we use function.
setPolymarkerColorIndex (mc)
 Where parameter mc specify the color of the marker symbol.

34
Unit-3 – 2D Transformation & Viewing
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
𝑃′ = 𝑃 + 𝑇
𝑡𝑥
𝑃′ = [𝑃] + [ ]
𝑡𝑦

1
Unit-3 – 2D Transformation & Viewing
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;
𝑷′ = 𝑹 ∙ 𝑷

2
Unit-3 – 2D Transformation & Viewing
𝒙′ 𝒙
= 𝐜𝐨𝐬 𝜽 − 𝐬𝐢𝐧 𝜽 ∙
[ ′] [ ] [ 𝒚]
𝒚 𝐬𝐢𝐧 𝜽 𝐜𝐨𝐬 𝜽
 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.


3
Unit-3 – 2D Transformation & Viewing
 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)].
𝑃′ = 𝑆 ∙ 𝑃

4
Unit-3 – 2D Transformation & Viewing
𝑠𝑥 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

𝑷′ = 𝑺(𝒔𝒙,𝒔𝒚) ∙ 𝑷

5
Unit-3 – 2D Transformation & Viewing
𝒙′ 𝒔𝒙 𝟎 𝟎 𝒙
[𝒚′] = [ 𝟎 𝒔𝒚 𝟎] [𝒚]
𝟏 𝟎 𝟎 𝟏 𝟏
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:
𝑷′ = 𝑹(𝜽𝟐) ∙ {𝑹(𝜽𝟏) ∙ 𝑷}
𝑷′ = {𝑹(𝜽𝟐) ∙ 𝑹(𝜽𝟏)} ∙ 𝑷
𝐜𝐨𝐬 𝜽𝟐 − 𝐬𝐢𝐧 𝜽𝟐 𝟎 𝐜𝐨𝐬 𝜽𝟏 −𝐬𝐢𝐧 𝜽𝟏 𝟎
𝑷′ = [𝐬𝐢𝐧 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟐 𝟎] [𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟏 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏 𝟎 𝟎 𝟏
𝐜𝐨𝐬 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟐 𝐬𝐢𝐧 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 − 𝐬𝐢𝐧 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 𝟎
𝑷′ = [𝐬𝐢𝐧 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 + 𝐬𝐢𝐧 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 𝐜𝐨𝐬 𝜽𝟐 𝐜𝐨𝐬 𝜽𝟏 − 𝐬𝐢𝐧 𝜽𝟐 𝐬𝐢𝐧 𝜽𝟏 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏

6
Unit-3 – 2D Transformation & Viewing
𝐜𝐨𝐬(𝜽𝟏 + 𝜽𝟐) −𝐬𝐢𝐧(𝜽𝟏 + 𝜽𝟐) 𝟎
𝑷′ = [𝐬𝐢𝐧(𝜽𝟏 + 𝜽𝟐) 𝐜𝐨𝐬(𝜽𝟏 + 𝜽𝟐) 𝟎] ∙ 𝑷
𝟎 𝟎 𝟏
𝑷′ = 𝑹(𝜽𝟏 + 𝜽𝟐) ∙ 𝑷
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

7
Unit-3 – 2D Transformation & Viewing

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

(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

8
Unit-3 – 2D Transformation & Viewing
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 1 1

9
Unit-3 – 2D Transformation & Viewing
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.

10
Unit-3 – 2D Transformation & Viewing
 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 𝑶𝒓𝒊𝒈𝒊𝒏.

11

You might also like