2. Line generation Algorithm in Computer Graphics
• In any 2-Dimensional plane if
we connect two points (x1, y1)
and (x2, y2), we get a line
segment.
• But in the case of computer
graphics we can not directly join
any two coordinate points, for
that we should calculate
intermediate point’s coordinate
and put a pixel for each
intermediate point, of the
desired color with help of
functions like putpixel(x, y, K)
in C, where (x,y) is our co-
ordinate and K denotes some
color.
Examples:
Input: For line segment between (3, 2) and (6,
5) :
we need (3, 2),(4, 2) (4, 3) ….. (5, 5) as our
intermediate points.
3. Line generation Two-point form equation of
line Computer Graphics
• Let P(x,y) be the general point
on the line L which passes
through the
points A(x1,y1) and B(x2,y2)
4. Basic properties of line drawing in Computer
Graphics
The primary design criteria are as follows.
Straight lines appear as straight lines.
Straight lines start and end accurately.
Displayed lines should have constant brightness along their
length, independent of the line length and orientation.
Lines should be drawn rapidly.
5. Basic mathematics to draw line drawing in
Computer Graphics
Method-1 : Direct Method :
In this algorithm, we have two endpoints. We find the slope of the line by using
both the points, and we put the slope in the line equation y = mx + b.
6. Basic properties of line drawing ALGORITHMS
in Computer Graphics
An algorithm should be precise: Each step of the algorithm
must be adequately defined.
Finiteness: An algorithm must contain finiteness. It means the
algorithm stops after the execution of all steps.
Easy to understand: An algorithm must help learners to
understand the solution in a more natural way.
Correctness: An algorithm must be in the correct manner.
Effectiveness: Thesteps of an algorithm must be valid and
efficient.
Uniqueness: All steps of an algorithm should be clearly and
uniquely defined, and the result should be based on the given
input.
Input: A good algorithm must accept at least one or more input.
Output: An algorithm must generate at least one output.
8. DDA Line generation Two-point form equation
of line Computer Graphics
DDA Algorithm:
Step 1: Start Algorithm
Step 2: Declare x1,y1,x2,y2,dx,dy,x,y as
integer variables.
Step 3: Enter value of x1,y1,x2,y2.
Step 4: if ABS (x2-x1) > ABS (y2-y1) Then
step = abs (x2-x1)
else
step = abs (y2-y1)
Step 5: dx=(x2-x1)/step
dy=(y2-y1)/step
assign x = x1 + 0.5
assign y = y1 + 0.5
i=1
Step 6: Set pixel (x, y)
Step 7: while( i <= step )
x = x + dx
y = y + dy
i=i+1
Set pixels (Round (x), Round (y))
Step 8: End Algorithm
Example draw line from (0,0) to (4,6)
dx=0.7
dy=1 step=6
9. DDA Line generation Two-point form equation
of line Computer Graphics
DDA Algorithm:
Step 1: Start Algorithm
Step 2: Declare x1,y1,x2,y2,dx,dy,x,y as
integer variables.
Step 3: Enter value of x1,y1,x2,y2.
Step 4: if ABS (x2-x1) > ABS (y2-y1) Then
step = abs (x2-x1)
else
step = abs (y2-y1)
Step 5: dx=(x2-x1)/step
dy=(y2-y1)/step
assign x = x1 + 0.5
assign y = y1 + 0.5
i=1
Step 6: Set pixel (x, y)
Step 7: while( i <= step )
x = x + dx
y = y + dy
i=i+1
Set pixels (Round (x), Round (y))
Step 8: End Algorithm
Example draw line from p1(2,3) to p2(6,6)
i ( x , y ) x y
10. DDA Line generation Two-point form equation
of line Computer Graphics
Advantages :
i. It is simple and easy to implement algorithm.
ii. It avoid using multiple operations which have high time
complexities.
iii. It is faster than the direct use of the line equation because it
does not use any floating point multiplication and it calculates
points on the line.
Disadvantages :
i. It deals with the rounding off operation and floating point
arithmetic so it has high time complexity.
ii. As it is orientation dependent, so it has poor endpoint
accuracy.
iii. Due to the limited precision in the floating point representation
it produces cumulative error.
11. Basis of the algorithm:
A
B
Start position
From start position decide A or B next
• A more efficient approach
• It is suited for implementation on CRT device.
• The algorithm seeks to select optimum(accurate) raster location to draw
straight line.
• For this algorithm increments either x or y by one depending on slope of line.
12. Basis of the algorithm:
A
B
Start position
From start position decide A or B next
• The increment in other variable ,either 0 or 1is determined by
actual line and distance between the actual line and nearest grid
location.
• This distance is called error e
13. For a given value of x
• If the slope of line is greater than or equal to ½ then line intercept at x=1
is closer to y=1.
• If the slope of line is less than ½ then line intercept at x=1 is closer to y=0.
• Reason is,
one pixel lies at distance ti above the line, and one pixel lies at distance si
below theline
Trueline
ti
si
• The increment in other variable ,either 0 or 1is determined by actual line and
distance between the actual line and nearest grid location.
• This distance is called error e
1
2
≤
Δ𝑦
Δ𝑥
≤ 1 𝑒 ≥ 0 𝑝𝑙𝑜𝑡 1,1
0 ≤
Δ𝑦
Δ𝑥
<
1
2
𝑒 < 0 𝑝𝑙𝑜𝑡 1,0
1
2
Δ𝑦
Δ𝑥
1
0
14. For a given value of x
• If the slope of line is greater than or equal to ½ then line intercept at x=1
is closer to y=1.
• If the slope of line is less than ½ then line intercept at x=1 is closer to y=0.
• Reason is,
one pixel lies at distance ti above the line, and one pixel lies at distance si
below theline
Trueline
ti
si
• The increment in other variable ,either 0 or 1is determined by actual line and
distance between the actual line and nearest grid location.
• This distance is called error e
1
2
≤
Δ𝑦
Δ𝑥
≤ 1 𝑒 ≥ 0 𝑝𝑙𝑜𝑡 1,1
0 ≤
Δ𝑦
Δ𝑥
<
1
2
𝑒 < 0 𝑝𝑙𝑜𝑡 1,0
1
2
Δ𝑦
Δ𝑥
1
0
15. For a given value of x
• If the slope of line is greater than or equal to ½ then line intercept at x=1
is closer to y=1.
• If the slope of line is less than ½ then line intercept at x=1 is closer to y=0.
• Reason is,
one pixel lies at distance ti above the line, and one pixel lies at distance si
below theline
Trueline
ti
si
• The increment in other variable ,either 0 or 1is determined by actual line and
distance between the actual line and nearest grid location.
• This distance is called error e
1
2
≤
Δ𝑦
Δ𝑥
≤ 1 𝑒 ≥ 0 𝑝𝑙𝑜𝑡 1,1
0 ≤
Δ𝑦
Δ𝑥
<
1
2
𝑒 < 0 𝑝𝑙𝑜𝑡 1,0
1
2
Δ𝑦
Δ𝑥
1
0
16. Bresenham Line Algorithm
The algorithm start with error term with following error term equation,
e = m - ½
Subsequent increments in e will be e = e + m
17. LineBres(int x1, int y1, int x2, int y2) // line for |m| < 1
{
Step 1: Start Algorithm
Step 2: Declare x1, y1, x2, y2, dx, dy, x, y as integer variables.
Step 3: dx = x2 – x1, dy = y2 – y1,
x=x1, y=y1
m=dy /dx
e = m – ½
Step 4:
for i= 0 to dx
{
setpixel (x,y)
while(e>0)
{
y = y+1
e=e-1
}
x=x+1
e=e+m
next I
Setp 5: Finish
Floating point Bresenham’s Line Algorithm:
18. e = m – ½
e =
𝑑𝑦
𝑑𝑥
-
1
2
( where m=
𝑑𝑦
𝑑𝑥
)
e =
2 𝑑𝑦 − 𝑑𝑥
2 𝑑𝑥
2dx e = 2 dy - dx - ( I )
Here let, ê = 2dx e - ( II )
Hence,
ê = 2 dy - dx - ( III )
Integer Bresenham’s Line Algorithm:
e = e + m
e = e +
𝑑𝑦
𝑑𝑥
e =
e dx + dy
𝑑𝑥
e dx = e dx + dy
Multiply both side by 2
2e dx = 2e dx + 2 dy – (IV)
Use eqn ( III ) in ( IV )
ê = ê + 2 dy - ( V )
Convert following floating point equations to integer equation to run
algorithm fast,
e = m – ½ e=e+m e=e-1
19. e=e-1 - ( V )
Multiply both side of ( V ) by 2.dx
2 dx e = 2 dx e - 2dx - ( V )
As, ê = 2dx e - ( II )
Hence, ê = ê - 2dx - ( III )
Integer Bresenham’s Line Algorithm:
Convert following floating point equations to integer equation to run
algorithm fast,
e = m – ½ e=e+m e=e-1
20. LineBres(int x1, int y1, int x2, int y2) // line for |m| < 1
Step 1: Declare x1, y1, x2, y2, dx, dy, x, y as integer variables.
Step 2: dx = x2 – x1, dy = y2 – y1,
x = x1, y = y1
ê = 2 dy - dx
Step 3: for i= 0 to dx step i = i + 1
{
setpixel (x,y)
while( ê >0)
{
y = y+1
ê = ê - 2dx
}
x=x+1
ê = ê + 2 dy
}
Setp 5: Finish LineBres
Integer Bresenham’s Line Algorithm:
21. General Bresenham’s Line Algorithm:
Depending on quadrant the increment / decrement in x and y will be as above
24. Advantages / disadvantages of Bresenham Line Algorithm:
The advantages of Bresenham Line Drawing Algorithm are-
• It is easy to implement.
• It is fast and incremental.
• It executes fast but less faster than DDA Algorithm.
• The points generated by this algorithm are more accurate than
DDA Algorithm.
• It uses fixed points only.
The disadvantages of Bresenham Line Drawing Algorithm are-
• Though it improves the accuracy of generated points but still the
resulted line is not smooth.
• This algorithm is for the basic line drawing.
• It can not handle diminishing jaggies.
25. Basic Concepts in Circle Drawing
Circle is a symmetrical figure.
The shape of the circle is similar in each quadrant
It has eight-way symmetry
1) Plot (x,y)
2) Plot (y,x)
3) Plot (-x,-y)
4) Plot (-y,-x)
5) Plot (-x,y)
6) Plot (y, -x)
7) Plot (x,-y)
8) Plot (-y,x)
25
26. • Polynomial Method
• x2 + y2 = r2
• Trigonometric Method
• x= r cos Ө
• Y = r sin Ө
26
Methods to Represent a Circle
r
r
27. General Bresenham’s Circle Algorithm:
• Most efficient algorithm to draw circle is Bresenham’s Circle
Algorithm.
• The Bresenham’s circle drawing algorithm considers the eight
way of the symmetry of the circle to generate it.
28. General Bresenham’s Circle Algorithm:
• At the beginning only one octant of the
circle generation is needed.
• Other parts of circles are drawn by
successive reflections.
1) e.g. if circle has drawn in first octant (0
to 450 ccw)
2) The second octant is obtained by
reflection through the line y=x to yield
first quadrant.
3) The results(pixels) in first quadrant are
reflected through the line x=0 to obtain
the second quadrant pixels.
4) The combined results (pixels) of upper
semicircles are reflected through the
line y = 0 to complete the circle.
29. Bresenham’s Circle drawing Algorithm:
29
• It plots 1/8th part of the circle i.e. from 90ᵒto 45ᵒ.
• As circle is drawn from 90ᵒ to 45ᵒ, the x moves in positive e
direction and y moves in the negative direction.
32. Bresenham’s Circle drawing Algorithm
X i
Y i
Δ i
1) If Δ i < 0 then, diagonal point is inside the actual circle, either pixel at (xi +1,
yi) i.e. mH or that at (xi +1 , yi -1) i.e. mD must be chosen. To decide
which own calculate δA = mH - mD
A
---------- ( I )
----- ( II )
A
A
Δ 𝒊 = ( (𝒙𝒊 + 𝟏)𝟐 + 𝒚𝒊 − 𝟏 𝟐 − R 2 )
34. Bresenham’s Circle drawing Algorithm
X i
Y i
Δ i
2) If Δ i > 0 then, diagonal point is outside the actual circle, either pixel at
(xi +1 , yi -1) i.e. mD or that at i.e. (xi yi + 1) mV must be chosen.
To decide which own calculate δB = mD - mV
Δ 𝒊 = ( (𝒙𝒊 + 𝟏)𝟐 + 𝒚𝒊 − 𝟏 𝟐 − R 2 )
B
B
B
36. Bresenham’s Circle drawing Algorithm
X i
Y i
Δ i
3) If Δ i = 0 then, δA = mH – mD Here mD = Δ i = 0, hence δA = mH
which means δA >=0 hence diagonal pixel ((𝒙𝒊 + 𝟏) , 𝒚𝒊 − 𝟏 ) is
selected i.e movement is mD
OR
3) If Δ i = 0 then, δB = mD - mV Here mD = Δ i = 0, hence δB = - mV which
means δB < 0 hence diagonal pixel ((𝒙𝒊 + 𝟏) , 𝒚𝒊 − 𝟏 ) is
selected i.e movement is mD
Δ 𝒊 = ( (𝒙𝒊 + 𝟏)𝟐 + 𝒚𝒊 − 𝟏 𝟐 − R 2 )
38. Bresenham’s Circle drawing Algorithm
Letus make some simplification to obtain values for x, y, 𝜟 𝒊, δA, and
δB to increment or decrement during the loop of algorithm.
1) For Horizontal mH Pixel selection
39. Bresenham’s Circle drawing Algorithm
Letus make some simplification to obtain values for x, y, 𝜟 𝒊, δA, and
δB to increment or decrement during the loop of algorithm.
2) For Diagonal mD Pixel selection
3) For Diagonal mV Pixel selection
40. Bresenham’s Circle drawing Algorithm
Letus make some simplification to obtain values for x, y, 𝜟 𝒊, δA, and
δB to increment or decrement during the loop of algorithm.
4) Initial stage or pixel from where Bresenham’s circle algorithm
works
X=0
Y=R
Δ 𝒊 = ( (𝒙𝒊 + 𝟏)𝟐 + 𝒚𝒊 − 𝟏 𝟐 − R 2 )
Δ 𝒊 = ( 𝟎 + 𝟏)𝟐
+ 𝑹 − 𝟏 𝟐
− R 2 )
Δ 𝒊 = 𝟏 + 𝑹𝟐 − 𝟐𝑹 + 𝟏 − R 2
Δ 𝒊 = 𝟐 − 2R
𝜟 𝒊 = 𝟐(𝟏 − R )
r
(0,R)
45. Bresenham’s Circle drawing Algorithm
Advantages of Bresenham's Circle Drawing Algorithm
1) The Bresenhem’s circle drawing algorithm uses integer arithmetic
which makes the implementation less complex.
2) Due to its integer arithmetic, it is less time-consuming.
3) This algorithm is more accurate than any other circle drawing
algorithm as it avoids the use of round off function.
Disadvantages of Bresenham's Circle Drawing Algorithm
1) This algorithm does not produce smooth results due to its integer
arithmetic as it fails to diminish the zigzags completely.
2) The Bresenhem’s circle drawing algorithm is not accurate in the
case of drawing of complex graphical images.
46. Polygon
• Polyline is a chain of connected line segments.
It is specified by giving the vertices P0, P1,
P2..and so on.
• The first vertex is called initial point and last is
called terminal point.
P0 P2
46
P1
P3
P4
P5
P6
47. Polygon
• When initial point and terminal point of any
polyline is same (when polyline is closed)
then it is called polygon.
47
48. 48
• Polygon is a representation of the surface.
• It is primitive which is closed in nature.
• It is formed using a collection of lines.
• It is also called as many-sided figure.
• The lines combined to form polygon are called sides or edges.
The lines are obtained by combining two vertices.
About Polygon
50. Types of Polygon
1. Regular Polygon a regular polygon is a
polygon that is equiangular (all angles are equal
in measure) and equilateral (all sides have the
same length). Regular polygons may be either
convex or star.
50
51. Types of Polygon
2. Convex polygon is a polygon in which the line
segment joining any two points within the polygon
lies completely inside the polygon
51
52. 3. Concave polygon is a polygon in which the line
segment joining any two points within the polygon
may not lie completely inside the polygon.
52
Types of Polygon
53. 4. Complex polygon is a concave type polygon
with number of edges and the edges are
intersected.
53
Types of Polygon
54. Polygon Representation
54
The polygon can be represented by listing its n vertices
in an ordered list.
P = {(x1, y1), (x2, y2), ……., (xn, yn)}.
The polygon can be displayed by drawing a line
between (x1, y1), and (x2, y2), then a line between (x2,
y2), and (x3, y3), and so on until the end vertex. In
order to close up the polygon, a line between (xn, yn),
and (x1, y1) must be drawn.
One problem with this representation is that if we
wish to translate the polygon, it is necessary to apply
the translation transformation to each vertex in order
to obtain the translated polygon.
55. Polygon Filling Algorithm
• An ordered list of vertices forms a polygon.
• Polygon Filling :- The pixels that fall on the border of
the polygon are determined and the pixels that fall
inside are determined in order to color the polygon.
• Polygons are easier to fill since they have linear
boundaries.
• Filling the polygon means highlighting all the pixels
which lie inside the polygon with any color other than
the background color.
56. Point Inside Test – Even-Odd Method
• Once the polygon is entered, we can draw the outline of
the polygon using drawpoly() command in c/c++.
• To show polygon as a solid object, it is needed to set the
pixel inside the polygon as well as pixels on the
boundary of it.
• Now the question is, to determine whether the point
/pixel is inside or outside of a polygon.
57. Point Inside Test – Even-Odd Method
• One simple method of doing this is to draw a horizontal
line segment from left to the pixel and count how many
intersections of the line segment with the polygon
boundary occur.
• If there are an odd number of intersections, then the point
is inside, otherwise it is outside.
• This method is called the even-odd method of determining
polygon inside points.
• This inside test or Even-Odd method is used in scan line
method of polygon filling..
58. Types of Polygon Filling Algorithm
There are two basic approaches used to fill the polygon.
1. Ordered Edge List Algorithm
2. Edge Flag algorithm
3. Edge fill algorithm
4. Fence Fill algorithm
59. Scanline Polygon Filling Algorithm
• Scanline filling is basically filling up of polygons
using horizontal lines or scanlines.
• The purpose of the SLPF algorithm is to fill (color)
the interior pixels of a polygon for each scanline.
• This algorithm works by intersecting scanline with
polygon edges and fills the polygon between pairs of
intersections.
• These intersection points are then sorted from left to
right, and the corresponding positions between each
intersection pair are set to the specified fill color.
60. Requirements of all Scanline Fill Algorithm
Find Polygon Bounding box for,
selection number of scanlines for scanning polygon
Selection of boundry limit for x co-ordinate for each scanline
61. 1. Ordered Egde List Scanline Algorithm
1) Start with Ymax and move to Ymin or vice versa
2) For each scan line:
a. Find the intersections of the scan line with all edges
of the polygon.
b. Sort the intersections by increasing x coordinate.
c. Fill in all pixels between pairs of intersections
Note
For scan line number 8 the
sorted list of x-coordinates is
(2, 4, 9, 13) Therefore draw
line b/w (2,4) & (9,13)
Y max
Y min
62. 1. Ordered Egde List Scanline Fill Algorithm
Challenges in filling the polygon
selection number of scanlines for scanning polygon
Selection of boundry limit for x co-ordinate for each scanline
Scan line 7
Scan line 6
Scan line 3
Scan line 1
One intersection
Three intersections
Three intersections
Number of intersections
7
3
1
SL7: 1
SL6 : 1, 2, 8
SL4 : 1, 4, 6, 8
SL3 : 1, 5, 8
SL2 : 1, 8
SL1 : 1, 2,3,4,5,6,7, 8
Ordered edge list of X
for Scan Line
• It will no support or work if scan line intersects for odd number of times to polygon
• For horizontal line of polygon this algorithm give maximum no of intersections to scanline
hence fail
63. Scanline Fill Algorithm
Challenges in filling the polygon
selection number of scanlines for scanning polygon
Selection of boundry limit for x co-ordinate for each scanline
One intersection
One intersection
64. Scanline Fill Algorithm
Challenges in filling the polygon
We know that for every scan line we have to calculate x intersection
with every polygon side. We can determine the next x
intersection value as Bounding Box
(x1,y1)
(x2,y2)
Intersecting point
(x, y)
Scan line y
𝑑𝑦
𝑑𝑥
=
(𝑦2 − 𝑦1)
(𝑥2 − 𝑥1)
=
(𝑦 − 𝑦1)
(𝑥 − 𝑥1)
𝑥 − 𝑥1 =
𝑦 − 𝑦1
𝑦2 − 𝑦1
× 𝑥2 − 𝑥1
𝑥 =
𝑦−𝑦1
𝑦2−𝑦1
∗ 𝑥2 − 𝑥1 + 𝑥1
65. 2. Egde Flag Scanline Algorithm
Before Edge Flag Fill
After Edge Flag Fill
negate
66. 2. Egde Flag Scanline Algorithm
Y max
Y min
Xmin=0 Xmax
67. 3. Egde Fill Scanline Algorithm
1. For each Scan line intersecting a polygon edge at(x, y),
i. Complement all pixels to the right of (x, y).
2. Next Scan line go to step 1.
68. 4. Fence Fill Scanline Algorithm
1. For each Scan line intersecting a polygon edge at(x, y),
i. If the intersection is to the left of fence,
a) Complement all pixels to the right of (x, y) of scan line
and edge and to the left of fence.
ii. If the intersection is to the right of fence,
b) Complement all pixels to the left of (x, y) of scan line
and edge and to the right of fence.
2. Next Scan line go to step 1.
70. 5. Boundary Fill Algorithm
• Boundary Fill Algorithm starts at a pixel inside the polygon to
be filled and paints the interior proceeding outwards towards
the boundary.
• This algorithm works only if the color with which the region
has to be filled and the color of the boundary of the region are
different.
• If the boundary is of one single color, this approach proceeds
outwards pixel by pixel until it hits the boundary of the
region.
71. 5. Boundary Fill Algorithm
• Boundary Fill Algorithm is recursive in nature.
• It takes an interior point(x, y), a fill color, and a boundary color
as the input.
1. The algorithm starts by checking the color of (x, y).
i. If it’s color is not equal to the fill color and the boundary
color, then it is painted with the fill color and
ii. the function is called for all the neighbours of (x, y)
recursively.
2. This process continues until all points up to the boundary
color for the region have been tested.
72. 5. 4-connected pixels Boundary Fill Algorithm
4-connected pixels Boundary Fill Algorithm :
• After painting a pixel, the function is called for four neighboring
points.
• These are the pixel positions that are right, left, above and below
the current pixel.
• Areas filled by this method are called 4-connected.
void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}
73. 5. 8-connected pixels Boundary Fill Algorithm
8-connected pixels :
• More complex figures are filled using this approach.
• The pixels to be tested are the 8 neighboring pixels, the pixel on the
right, left, above, below and the 4 diagonal pixels.
• Areas filled by this method are called 8-connected.
74. 5. 8-connected pixels Boundary Fill Algorithm
Below given is the algorithm :
void boundaryFill8(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill8(x + 1, y, fill_color, boundary_color);
boundaryFill8(x, y + 1, fill_color, boundary_color);
boundaryFill8(x - 1, y, fill_color, boundary_color);
boundaryFill8(x, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y + 1, fill_color, boundary_color);
boundaryFill8(x + 1, y - 1, fill_color, boundary_color);
boundaryFill8(x + 1, y + 1, fill_color, boundary_color);
}
}
75. 6. Flood Fill Algorithm or Seed 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 neighboring 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 stop
through pixel positions until all interior point have been filled.
76. 6. Flood Fill Algorithm or Seed fill Algorithm
Recursive algorithm for seed fill methods have difficulty as -
• The first difficulty is that if some inside pixels are already
displayed in fill color then recursive branch terminates,
leaving further internal pixels unfilled.
• If the image size increases the complexity increases in
recurssion.
To avoid this difficulty, we have to first change the color of any
internal pixels that are initially set to the fill color before applying
the seed fill procedures
Disadvantage:
• Very slow algorithm
• May be fail for large polygons
• Initial pixel required more knowledge about surrounding pixels.
77. 6. Flood Fill Algorithm or Seed fill Algorithm
Procedure floodfill (x, y,fill_ color, old_color: integer)
If (getpixel (x, y)=old_color)
{
setpixel (x, y, fill_color);
fill (x+1, y, fill_color, old_color);
fill (x-1, y, fill_color, old_color);
fill (x, y+1, fill_color, old_color);
fill (x, y-1, fill_color, old_color);
}
}
78. Terminologies in Computer Graphics
1. Scree/Display Resolution: The number of horizontal and
vertical pixels on a display screen. Also known
as display mode.
OR
1. Screen resolution is the number of pixels a screen can show,
both horizontally and vertically.
• The more pixels, the more information is visible without
scrolling.
• Screen resolutions have a pixel count such as 1600x1200,
which means 1600 horizontal pixels & 1200 vertical pixels.
79. Terminologies in Computer Graphics
1. The aspect ratio of a display device is the proportional
relationship between the width and the height of the display. It
is expressed as two numbers separated by a colon (x:y).
Common aspect ratios for displays, past and present, include
5:4, 4:3, 16:10 and 16:9.
80. Frame Buffer
• A frame buffer is large contiguous piece of computer memory which is
used to store the display image.
• The diff kinds of memory used for frame buffers are disk, IC shift
registers, drums etc.
• To display a pixel on raster display, minimum 1 bit is used in frame
buffer for text to maximum 24 bit in a frame buffer for graphics.
• When 1 bit is used to generate a pixel, the picture will be Black and
white(0 & 1).
• A frame buffer stores information in digital form while raster display
requires voltage to generate pixel. A single bit frame buffer raster CRT
display is as following fig.
82. Frame Buffer Continued
• If the bits are increased from 1 to n then 2n intensity level can be
achieved, for this, all the n bits are checked and resulting value is
calculated.
• This value is given to DAC to generate appropriate voltage to set
intensity of the pixel on the raster
88. Frame Buffer Continued
Rotating memory Frame Buffer
• Drums and disks were widely used in frame buffers to store the image
information.
• It is required to be refreshed continuously. Thus, it is necessary to read
the disk or drum again and again to refresh display.
• For this the rotating speed is made to coincide with the refresh rate of
the screen.
• To generate a pixel of desired intensity or colour, it is first necessary to
read the disk or drum.
89. Frame Buffer Continued
Rotating memory Frame Buffer Continued
• The information stored in disk or drum is in digital form, hence it is
necessary to convert it into analog form using DAC and then this
analog signal is used to generate the pixel.
• If only one bit is used to generate the pixel then only black and white
picture is possible.
• Disadvantage:- 1) the cost of the memory is high. 2) It requires more
time due to latency problem.
90. Frame Buffer Continued
Shift register Frame Buffer
•It is IC, the problem with the rotating memory is that it is slow and
expensive while IC-shift register can perform the same task with better
speed and is less expensive.
•In this circuit, when pulse is applied, the content of memory are shifted
by one place removing the last bit and inserting it into the starting bit.
•It is rotating the information in a circular form.
91. Frame Buffer Continued
Shift register Frame Buffer
•In this, one bit of memory is used as an intensity value.
•For color or gray scale display more than one IC, shift register can be
used in parallel.
•Disadvantage: 1) It requires more time due to latency problem.
2)In shift-register, even small changes requires more time.
92. Frame Buffer Continued
Random Access Frame Buffer
• Frame buffers are made up of random access circuit, and the color or
gray scale of the pixel can be set by 1,2,4,8 or more bits.
• 1 bit is generally used in text generation and any simple 2-D graphics
figures like square, triangle.
• To fill up the graphics figure, 2 to 4 bits of information are required for
diff types of shading effects while 8 or more bits are used for high
quality graphics.
• In color display 3 guns are used for 3 primary colors .E.g.- Red, Green,
Blue, one for each.
94. Characters Generation in CG
In computer graphics character can be generated
using software.
In hardware implementation of character generation
limited faces of character can be generated.
A wide variety of faces of character can be
generated with software implementation.
There are three methods for generating
characters using software implementation:-
Stroke method
Vector method or bitmap method.
Star bust method
95. Stroke Method
In this method we use a sequence of line drawing function
and arc functions to generate characters.
We can generate a sequence of character by assigning starting
and end point of line or arc.
By using this method various faces of character can be
generated by changing the values (parameters) in line and arc
function.
We can build our own stroke method character generator by
calls to the line drawing algorithm.
Here it is necessary to decide which line segments are needed
for each character and then drawing these segments using line
drawing algorithm.
Eg:-
96. Starbust Method
In this method a fixed pattern of line is used to generate the
character.
In this method we use a combination of 24 bit line segment.
In 24 bit line segment code each bit represent a single line.
Out of these 24 line segments, segments required to display for
particular character are highlighted.
To highlight a line we put corresponding bit 1 in 24 bit line segment
code and 0 otherwise.
97. Representaion of Starbust Method:
• The starbust patterns for characters A and M. the patterns for
particular characters are stored in the form of 24 bit code, each
bit representing one line segment.
• The bit is set to one to highlight the line segment; otherwise it is
set to zero.
• For example, 24-bit code for Character A is 0011 0000 0011
1100 1110 0001 and for character M is 0000 0011 0000 1100
98. Representaion of Starbust Method:
• This method of character generation has some disadvantages. They are
1. The 24-bits are required to represent a character. Hence more memory is
required
2. Requires code conversion software to display character from its 24-bit code
3. Character quality is poor. It is worst for curve shaped characters.
4. In Starbust method, 24 bit segment code is required to put in memory for
generating character. Hence extra memory is required in this method .
99. Bitmap Method
This method is suitable for producing various character.
Font size of character can be increased by increasing the size of
array.
This method uses an array of 1’s & 0’s to represent pixels.
It is also called dot matrix because in this method characters are
represented by an array of dots in the matrix form.
It is a two dimensional array having columns and rows.
An 5x7 array is commonly used to represent characters.
However 7x9 and 9x13 arrays are also used.
Higher resolution devices such as inkjet printer or laser printer
may use character arrays that are over 100x100.
102. Polygon
Polyline is a chain of connected line segments. It is
specified by giving the vertices P0, P1, P2..and so on.
The first vertex is called initial point and last is called
terminal point.
P0 P2
102
P1
P3
P4
P5
P6
103. Polygon
When initial point and terminal point of any polyline
is same (when polyline is closed) then it is called
polygon.
103
104. 104
• Polygon is a representation of the surface.
• It is primitive which is closed in nature.
• It is formed using a collection of lines.
• It is also called as many-sided figure.
• The lines combined to form polygon are called sides or edges.
The lines are obtained by combining two vertices.
About Polygon
106. Types of Polygon
1. Regular Polygon a regular polygon is a polygon
that is equiangular (all angles are equal in measure)
and equilateral (all sides have the same length).
Regular polygons may be either convex or star.
106
107. Types of Polygon
2. Convex polygon is a polygon in which the line
segment joining any two points within the polygon lies
completely inside the polygon
107
108. 3. Concave polygon is a polygon in which the line
segment joining any two points within the polygon may
not lie completely inside the polygon.
108
Types of Polygon
109. 4. Complex polygon is a concave type polygon with
number of edges and the edges are intersected.
109
Types of Polygon
110. Polygon Representation
110
The polygon can be represented by listing its n
vertices in an ordered list.
P = {(x1, y1), (x2, y2), ……., (xn, yn)}.
The polygon can be displayed by drawing a line
between (x1, y1), and (x2, y2), then a line between
(x2, y2), and (x3, y3), and so on until the end vertex.
In order to close up the polygon, a line between (xn,
yn), and (x1, y1) must be drawn.
One problem with this representation is that if we
wish to translate the polygon, it is necessary to
apply the translation transformation to each vertex
in order to obtain the translated polygon.