SlideShare a Scribd company logo
AMITY UNIVERSITY, HARYANA
COMPUTER GRAPHICS
AnkIT GARG
ASSISTAnT PROfESSOR
AMITy UnIvERSITy, HARyAnA
Module 1& 2
• Module I: Introduction to Graphics and Graphics Hardware System
• Application of computer graphics, Video Display Devices, Raster Scan
Display, Random Scan Display, Input Devices, Graphic Software and
graphics standards, Numerical based on Raster and Random scan display,
Frame buffer, Display processor.
• Module II: Output Primitives and Clipping operations
• Algorithms for drawing 2D Primitives lines (DDA and Bresenham‘s line
algorithm), circles (Bresenham‘s and midpoint circle algorithm), ellipses
(midpoint ellipse algorithm), Antialiasing (Supersampling method and
Area sampling method), Line clipping (cohen-sutherland algorithm), Curve
clipping algorithm, and polygon clipping with Sutherland Hodgeman
algorithm, Area fill algorithms for various graphics primitives: Scanline fill
algorithm, boundary fill algorithm, flood fill algorithm, Polygon
representation, various method of Polygon Inside test: Even-Odd method,
winding number method, Character generation techniques.
Module-II
Line Drawing Algorithms
Line Drawing Algorithm
• DDA Line drawing algorithm
• Breshenham’s Line drawing algorithm (Also
called Antialiasing Algorithm)
• These Line drawing algorithms are used for
scan conversion of graphic object i.e. Line.
Line Drawing Algorithm
• Scan conversion is a process to represent
graphics objects as a collection of pixels.
• Various algorithm and mathematical
computations are available for this purpose.
• Rasterization-Process of determining which
pixels give the best approximation to a desired
line on the screen.
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
Lines with slope magnitude |m| <1, ∆y = m ∆x
∆x> ∆y
Lines with slope magnitude |m| >1, ∆x = ∆y /m
∆y> ∆x
P1
P2
P2
Digital Differential Algorithm(DDA)
• Scan conversion algorithm based on
calculating either ∆x or ∆y.
• Sample the line at unit intervals in one
coordinate and determine the corresponding
integer values nearest the line path for the other
coordinate.
Case 1
Line with positive slope less than or equal to 1,
we sample at unit x intervals (∆x =1) and
determine the successive y value as
Yk+1= Yk + m ∆y=m ∆x
Yk+1- Yk =m ∆x
Yk+1- Yk =m (∆x =1)
• k takes integer values starting from 1 and
increases by 1 until the final point is reached.
• m can be any number between 0 and 1.
• Calculated y values must be rounded off to
the nearest integer.
• For lines with positive slope greater than 1,
sample at unit y intervals (∆y = 1) and
calculate each successive x value as
xk+1= xk + 1/m
Steps
P1 ( xa,ya) and P2 (xb,yb) are the two end points.
2. Horizontal and vertical differences between the
endpoint positions are computed & assigned to
two parameters namely dx and dy.
3. The difference with greater magnitude
determines the ‘value’ of increments to be done.
That means the number of times sampling has to
be done. This value is assigned to a parameter
called ‘steps’.
4. Starting from the 1st
pixel ,we determine the
offset needed at each step to generate the
next pixel position along the line path. Call
the offset value as xincrement and yincrement.
The starting points are xa and ya.
Assign x =xa and y=ya
x= x+ xincr & y= y+ yincr
5. Loop through the process steps times, till
the last point xb, yb is reached.
P1
(xa,ya)
P2
(xb,yb)
DDA Pseudo-code
// assume that slope is gentle
DDA(float x0, float x1, float y0, float y1) {
float x, y;
float xinc, yinc;
int numsteps;
numsteps = Round(x1) – Round(x0);
xinc = (x1 – x0) / numsteps;
yinc = (y1 – y0) / numsteps;
x = x0;
y = y0;
putpixel(Round(x),Round(y));
for (int i=0; i<numsteps; i++) {
x += xinc;
y += yinc;
putpixel(Round(x),Round(y));
}
}
DDA Example
• Suppose we want to draw a
line starting at pixel (2,3) and
ending at pixel (12,8). numsteps = 12 – 2 = 10
xinc = 10/10 = 1.0 X1-X0= 10
yinc = 5/10 = 0.5 Y1- y0= 5
Iteration x y Round(x) Round(y)
0 2 3 2 3
1 3 3.5 3 4
2 4 4 4 4
3 5 4.5 5 5
4 6 5 6 5
5 7 5.5 7 6
6 8 6 8 6
7 9 6.5 9 7
8 10 7 10 7
9 11 7.5 11 8
10 12 8 12 8
// assume that slope is gentle M<=1
DDA(float x0, float x1, float y0, float y1)
{
float x, y;
float xinc, yinc;
int numsteps;
numsteps = Round(x1) – Round(x0);
xinc = (x1 – x0) / numsteps;
yinc = (y1 – y0) / numsteps;
x = x0;
y = y0;
putpixel(Round(x),Round(y));
for (int i=0; i<numsteps; i++) {
x += xinc;
y += yinc;
putpixel(Round(x),Round(y));
}}
DDA Example
• Suppose we want to draw a
line starting at pixel (15,4) and
ending at pixel (20,17). numsteps =
xinc = X1-X0=
yinc = Y1- y0=
Iteration x y Round(x) Round(y)
0
1
2
3
4
5
6
7
8
9
10
// assume that slope is gentle M>1
DDA(float x0, float x1, float y0, float y1)
{
float x, y;
float xinc, yinc;
int numsteps;
numsteps = Round(y1) – Round(y0);
xinc = (x1 – x0) / numsteps;
yinc = (y1 – y0) / numsteps;
x = x0;
y = y0;
putpixel(Round(x),Round(y));
for (int i=0; i<numsteps; i++) {
x += xinc;
y += yinc;
putpixel(Round(x),Round(y));
}}
DDA Example
• Suppose we want to draw a
line starting at pixel (6,3) and
ending at pixel (8,10). numsteps = ?
xinc = ? X1-X0=
yinc = ? Y1- y0=
Iteration x y Round(x) Round(y)
0
1
2
3
4
5
6
7
8
9
10
// assume that slope is gentle M>1
DDA(float x0, float x1, float y0, float y1)
{
float x, y;
float xinc, yinc;
int numsteps;
numsteps = Round(y1) – Round(y0);
xinc = (x1 – x0) / numsteps;
yinc = (y1 – y0) / numsteps;
x = x0;
y = y0;
putpixel(Round(x),Round(y));
for (int i=0; i<numsteps; i++) {
x += xinc;
y += yinc;
putpixel(Round(x),Round(y));
}}
DDA Example
• Suppose we want to draw a
line starting at pixel (2,3) and
ending at pixel (5,12). numsteps = ?
xinc = ? X1-X0=
yinc = ? Y1- y0=
Iteration x y Round(x) Round(y)
0
1
2
3
4
5
6
7
8
9
10
DDA Algorithm (continued)
This DDA algorithm suffers from two reasons.
 Floating point calculations and rounding operations are expensive and time
consuming.
• Due to limited precision and Rounding operations calculated points will not
be displayed at its original point.
Y_inc
X_inc
Bresenham’s Algorithm
• Uses only integer calculations
• Requires less time to generate line due to
elimination of floating point calculations.
Bresenham’s Algorithm m<=1
1. Input the two line endpoints and store left endpoint as (x0,y0)
2. Pre-calculate the values dx, dy
3. Color pixel (x0,y0)
4. Let p0 = 2dy –dx, Here P0 is decision parameter which tells us which next
pixel will glow.
5. At each xk along the line, starting with k=0:
6. Repeat Step-5 Until we does not reach up to final point.
Remember! The algorithm and derivation above assumes slopes are less
than or equal to 1. for other slopes we need to adjust the algorithm slightly.
If pk<0, then the next point to plot is (xk + 1,yk),
and pk+1 = pk + 2dy
Otherwise, the next point to plot is (xk + 1, yk + 1),
and pk+1 = pk + 2dy – 2dx
Bresenham’s Algorithm Example
Where m<=1
• Suppose we want to draw a line starting at
pixel (2,3) and ending at pixel (12,8).
dx = 12 – 2 = 10
dy = 8 – 3 = 5
p0 = 2dy – dx = 0
t p P(x) P(y)
0 0 2 3
1 -10 3 4
2 0 4 4
3 -10 5 5
4 0 6 5
5 -10 7 6
6 0 8 6
7 -10 9 7
8 0 10 7
9 -10 11 8
10 0 12 8
2dy = 10
2dy – 2dx = -10
Algorithm
1. Input the two line endpoints and
store left endpoint as (x0,y0)
2. Pre-calculate the values dx, dy,
2dy and 2dy -dx
3. Color pixel (x0,y0)
4. Let p0 = 2dy –dx
5. At each xk along the line,
starting with k=0:
6. Repeat Step-4 dx times
If pk<0, then the next point to plot is (xk + 1,yk),
and pk+1 = pk + 2dy (Down pixel will be selected)
Otherwise, the next point to plot is (xk + 1, yk + 1),
and pk+1 = pk + 2dy – 2dx (Upper pixel will be
selected)
Anti-aliasing and filtering
techniques
Anti-aliasing
• Anti-aliasing is a method of fooling the eye
that a jagged edge is really smooth.
• Due to low resolution aliasing effect will
occur, which can be removed by increasing
the screen resolution.
Circle after applying antialiasing
Jagged edges due to aliasing
Some more Examples
Reducing Aliasing
• By increasing Resolution
The aliasing effect can be minimized by
increasing resolution of the raster display.
Disadvantage of improving resolution
• More memory requirement (Size of frame buffer will become Large)
• More scan conversion time
Anti-aliasing Methods
• Super-sampling method or post filtering
• Area sampling or Pre filtering
Super-sampling Method
(Cont….)
• In this method every individual pixel is
subdivided in to sub-pixel.
• In this method we count the number of
pixel which are overlapped by the object.
• The intensity value of a pixel is the
average of the intensity values of all the
sampled sub-pixels with in that pixel.
• In this method every pixel on the screen
have different intensity.
Super-sampling for a line object
having Non-Zero width.
Super-sampling Method (Cont….)
• Pixel at upper right corner is assigned 7/9 because
seven of its nine-sub pixels are inside the object
area.
• Suppose the color of object is RED(1,0,0), and the
background color is light yellow (.5,.5,.5).
• At what intensity the pixel will glow?
(1 X 7/9 +.5 X 2/9, 0X7/9+ 0.5 X 2/9, 0X7/9+.5X2/9)
R G B
Blending of background color and object color will occur
only in area of pixel where object overlaps.
Question-
1. What will be the intensity of center pixel?
Answer- (1 X 1+.5X0, 0X1+.5X0, 0X1+.5X0)
2. What will be the intensity of lower right side pixel?
Answer- (1X1/9 + .5X8/9, 0X1/9+.5X8/9, 0X1/9+.5X8/9)
Intensity Variation on pixels after Super sampling method
Write Formula for Blending of Colors for following Conditions
1. Object Background is (.5,.5,.5)
2. Object Color is (1,1,0)
Ans:
Write Formula for Blending of Colors for following Conditions
1. Object Background is (.5,.5,.5)
2. Object Color is (1,1,1)
Area Sampling Method
• This figure shows how line with a non-Zero width have
different intensity value at each pixel on the screen
• In this Area sampling method intensity value is
determined according to area covered by the object.
90%
15%
65%
50%
Thank you!!

More Related Content

PPTX
Graphics_3D viewing
Rabin BK
 
PDF
Unit 3
ypnrao
 
PPTX
Mid-Point Cirle Drawing Algorithm
Neha Kaurav
 
PPTX
Output primitives in Computer Graphics
Kamal Acharya
 
PPT
2D transformation (Computer Graphics)
Timbal Mayank
 
PPTX
BRESENHAM’S LINE DRAWING ALGORITHM
St Mary's College,Thrissur,Kerala
 
PPT
COMPOSITE TRANSFORMATION COMPUTER GRAPHICDS.ppt
urvashipundir04
 
PPTX
Polygons - Computer Graphics - Notes
Omprakash Chauhan
 
Graphics_3D viewing
Rabin BK
 
Unit 3
ypnrao
 
Mid-Point Cirle Drawing Algorithm
Neha Kaurav
 
Output primitives in Computer Graphics
Kamal Acharya
 
2D transformation (Computer Graphics)
Timbal Mayank
 
BRESENHAM’S LINE DRAWING ALGORITHM
St Mary's College,Thrissur,Kerala
 
COMPOSITE TRANSFORMATION COMPUTER GRAPHICDS.ppt
urvashipundir04
 
Polygons - Computer Graphics - Notes
Omprakash Chauhan
 

What's hot (20)

PPTX
2 d viewing computer graphics
KALESHWAR KUMAR
 
PPTX
Composite transformation
Pooja Dixit
 
PPTX
Window to viewport transformation&amp;matrix representation of homogeneous co...
Mani Kanth
 
PDF
4. THREE DIMENSIONAL DISPLAY METHODS
SanthiNivas
 
PPT
3 d geometric transformations
Mohd Arif
 
PPT
Intro to scan conversion
Mohd Arif
 
PPTX
Raster scan system & random scan system
shalinikarunakaran1
 
PPT
Line drawing algo.
Mohd Arif
 
PPT
Liang barsky Line Clipping Algorithm
Arvind Kumar
 
PPTX
Attributes of output primitives( curve attributes & area fill attributes)
shalinikarunakaran1
 
PPT
Z buffer
AmitBiswas99
 
PDF
3D Transformation
SwatiHans10
 
PPTX
Mid point circle algorithm
Mani Kanth
 
PPT
Polygon clipping
Mohd Arif
 
PPTX
2d-transformation
Pooja Dixit
 
PDF
Computer graphics - colour crt and flat-panel displays
Vishnupriya T H
 
PPT
2 d geometric transformations
Mohd Arif
 
PPTX
2D viewing & clipping
MdAlAmin187
 
PPTX
unit 4.pptx
PrabinNeupane8
 
2 d viewing computer graphics
KALESHWAR KUMAR
 
Composite transformation
Pooja Dixit
 
Window to viewport transformation&amp;matrix representation of homogeneous co...
Mani Kanth
 
4. THREE DIMENSIONAL DISPLAY METHODS
SanthiNivas
 
3 d geometric transformations
Mohd Arif
 
Intro to scan conversion
Mohd Arif
 
Raster scan system & random scan system
shalinikarunakaran1
 
Line drawing algo.
Mohd Arif
 
Liang barsky Line Clipping Algorithm
Arvind Kumar
 
Attributes of output primitives( curve attributes & area fill attributes)
shalinikarunakaran1
 
Z buffer
AmitBiswas99
 
3D Transformation
SwatiHans10
 
Mid point circle algorithm
Mani Kanth
 
Polygon clipping
Mohd Arif
 
2d-transformation
Pooja Dixit
 
Computer graphics - colour crt and flat-panel displays
Vishnupriya T H
 
2 d geometric transformations
Mohd Arif
 
2D viewing & clipping
MdAlAmin187
 
unit 4.pptx
PrabinNeupane8
 
Ad

Viewers also liked (8)

PPT
Polygon clipping
Ankit Garg
 
PPT
3 d transformations
Ankit Garg
 
PPT
Polygon filling
Ankit Garg
 
PPT
Line clipping
Ankit Garg
 
PPT
Projection ppt
Ankit Garg
 
PPTX
Digital image processing &amp; computer graphics
Ankit Garg
 
DOCX
Curve clipping
Ankit Garg
 
PPT
Character generation
Ankit Garg
 
Polygon clipping
Ankit Garg
 
3 d transformations
Ankit Garg
 
Polygon filling
Ankit Garg
 
Line clipping
Ankit Garg
 
Projection ppt
Ankit Garg
 
Digital image processing &amp; computer graphics
Ankit Garg
 
Curve clipping
Ankit Garg
 
Character generation
Ankit Garg
 
Ad

Similar to Line drawing algorithm and antialiasing techniques (20)

PPTX
Chapter 3 Output Primitives
PrathimaBaliga
 
PDF
raster algorithm.pdf
Mattupallipardhu
 
PPTX
Chapter 3 - Part 1 [Autosaved].pptx
Kokebe2
 
PPT
1536 graphics &amp; graphical programming
Dr Fereidoun Dejahang
 
PPT
Lect14 lines+circles
Siddharth Maloo
 
DOCX
Unit 2 notes
Balamurugan M
 
PDF
Line drawing Algorithm DDA in computer Graphics.pdf
RAJARATNAS
 
PPTX
Study on Fundamentals of Raster Scan Graphics
Dr. Chandrakant Divate
 
PPT
Bresenham circlesandpolygons
aa11bb11
 
PPT
Bresenham circles and polygons derication
Kumar
 
PDF
Computer Graphics Unit 2
SanthiNivas
 
PDF
Computer graphics notes 2 tutorials duniya
TutorialsDuniya.com
 
PPTX
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Vishal Butkar
 
PPTX
4 CG_U1_M3_PPT_4 DDA.pptx
ssuser255bf1
 
PPTX
Computer Graphics Unit 1
aravindangc
 
PPT
03.Scan Conversion.ppt
RobinAhmedSaikat
 
PPTX
L-5 (Line Drawing Algorithms Computer graphics).pptx
JatinSareen6
 
PPT
1 linedrawing
SakshiNailwal
 
PPT
computer_graphics_line_algorithm in Computer Graphics
bsse20142018
 
Chapter 3 Output Primitives
PrathimaBaliga
 
raster algorithm.pdf
Mattupallipardhu
 
Chapter 3 - Part 1 [Autosaved].pptx
Kokebe2
 
1536 graphics &amp; graphical programming
Dr Fereidoun Dejahang
 
Lect14 lines+circles
Siddharth Maloo
 
Unit 2 notes
Balamurugan M
 
Line drawing Algorithm DDA in computer Graphics.pdf
RAJARATNAS
 
Study on Fundamentals of Raster Scan Graphics
Dr. Chandrakant Divate
 
Bresenham circlesandpolygons
aa11bb11
 
Bresenham circles and polygons derication
Kumar
 
Computer Graphics Unit 2
SanthiNivas
 
Computer graphics notes 2 tutorials duniya
TutorialsDuniya.com
 
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Vishal Butkar
 
4 CG_U1_M3_PPT_4 DDA.pptx
ssuser255bf1
 
Computer Graphics Unit 1
aravindangc
 
03.Scan Conversion.ppt
RobinAhmedSaikat
 
L-5 (Line Drawing Algorithms Computer graphics).pptx
JatinSareen6
 
1 linedrawing
SakshiNailwal
 
computer_graphics_line_algorithm in Computer Graphics
bsse20142018
 

More from Ankit Garg (12)

PPT
Introduction to computer graphics part 2
Ankit Garg
 
PPT
Introduction to computer graphics part 1
Ankit Garg
 
PPT
Window to viewport transformation
Ankit Garg
 
PPT
Unit 1
Ankit Garg
 
PPTX
Numerical unit 1
Ankit Garg
 
PPTX
Hidden surface removal
Ankit Garg
 
PPTX
Graphics software standards
Ankit Garg
 
PPTX
Fractal introduction and applications modified version
Ankit Garg
 
PPTX
Concept of basic illumination model
Ankit Garg
 
PPTX
Circle generation algorithm
Ankit Garg
 
PPT
Applications of cg
Ankit Garg
 
PPT
2 d transformation
Ankit Garg
 
Introduction to computer graphics part 2
Ankit Garg
 
Introduction to computer graphics part 1
Ankit Garg
 
Window to viewport transformation
Ankit Garg
 
Unit 1
Ankit Garg
 
Numerical unit 1
Ankit Garg
 
Hidden surface removal
Ankit Garg
 
Graphics software standards
Ankit Garg
 
Fractal introduction and applications modified version
Ankit Garg
 
Concept of basic illumination model
Ankit Garg
 
Circle generation algorithm
Ankit Garg
 
Applications of cg
Ankit Garg
 
2 d transformation
Ankit Garg
 

Recently uploaded (20)

PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PDF
JUAL EFIX C5 IMU GNSS GEODETIC PERFECT BASE OR ROVER
Budi Minds
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
Software Testing Tools - names and explanation
shruti533256
 
JUAL EFIX C5 IMU GNSS GEODETIC PERFECT BASE OR ROVER
Budi Minds
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Zero Carbon Building Performance standard
BassemOsman1
 
Information Retrieval and Extraction - Module 7
premSankar19
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 

Line drawing algorithm and antialiasing techniques

  • 1. AMITY UNIVERSITY, HARYANA COMPUTER GRAPHICS AnkIT GARG ASSISTAnT PROfESSOR AMITy UnIvERSITy, HARyAnA
  • 2. Module 1& 2 • Module I: Introduction to Graphics and Graphics Hardware System • Application of computer graphics, Video Display Devices, Raster Scan Display, Random Scan Display, Input Devices, Graphic Software and graphics standards, Numerical based on Raster and Random scan display, Frame buffer, Display processor. • Module II: Output Primitives and Clipping operations • Algorithms for drawing 2D Primitives lines (DDA and Bresenham‘s line algorithm), circles (Bresenham‘s and midpoint circle algorithm), ellipses (midpoint ellipse algorithm), Antialiasing (Supersampling method and Area sampling method), Line clipping (cohen-sutherland algorithm), Curve clipping algorithm, and polygon clipping with Sutherland Hodgeman algorithm, Area fill algorithms for various graphics primitives: Scanline fill algorithm, boundary fill algorithm, flood fill algorithm, Polygon representation, various method of Polygon Inside test: Even-Odd method, winding number method, Character generation techniques.
  • 4. Line Drawing Algorithm • DDA Line drawing algorithm • Breshenham’s Line drawing algorithm (Also called Antialiasing Algorithm) • These Line drawing algorithms are used for scan conversion of graphic object i.e. Line.
  • 5. Line Drawing Algorithm • Scan conversion is a process to represent graphics objects as a collection of pixels. • Various algorithm and mathematical computations are available for this purpose. • Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen.
  • 8. Lines with slope magnitude |m| <1, ∆y = m ∆x ∆x> ∆y Lines with slope magnitude |m| >1, ∆x = ∆y /m ∆y> ∆x P1 P2 P2
  • 9. Digital Differential Algorithm(DDA) • Scan conversion algorithm based on calculating either ∆x or ∆y. • Sample the line at unit intervals in one coordinate and determine the corresponding integer values nearest the line path for the other coordinate. Case 1 Line with positive slope less than or equal to 1, we sample at unit x intervals (∆x =1) and determine the successive y value as Yk+1= Yk + m ∆y=m ∆x Yk+1- Yk =m ∆x Yk+1- Yk =m (∆x =1)
  • 10. • k takes integer values starting from 1 and increases by 1 until the final point is reached. • m can be any number between 0 and 1. • Calculated y values must be rounded off to the nearest integer. • For lines with positive slope greater than 1, sample at unit y intervals (∆y = 1) and calculate each successive x value as xk+1= xk + 1/m
  • 11. Steps P1 ( xa,ya) and P2 (xb,yb) are the two end points. 2. Horizontal and vertical differences between the endpoint positions are computed & assigned to two parameters namely dx and dy. 3. The difference with greater magnitude determines the ‘value’ of increments to be done. That means the number of times sampling has to be done. This value is assigned to a parameter called ‘steps’.
  • 12. 4. Starting from the 1st pixel ,we determine the offset needed at each step to generate the next pixel position along the line path. Call the offset value as xincrement and yincrement. The starting points are xa and ya. Assign x =xa and y=ya x= x+ xincr & y= y+ yincr 5. Loop through the process steps times, till the last point xb, yb is reached. P1 (xa,ya) P2 (xb,yb)
  • 13. DDA Pseudo-code // assume that slope is gentle DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(x1) – Round(x0); xinc = (x1 – x0) / numsteps; yinc = (y1 – y0) / numsteps; x = x0; y = y0; putpixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; putpixel(Round(x),Round(y)); } }
  • 14. DDA Example • Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). numsteps = 12 – 2 = 10 xinc = 10/10 = 1.0 X1-X0= 10 yinc = 5/10 = 0.5 Y1- y0= 5 Iteration x y Round(x) Round(y) 0 2 3 2 3 1 3 3.5 3 4 2 4 4 4 4 3 5 4.5 5 5 4 6 5 6 5 5 7 5.5 7 6 6 8 6 8 6 7 9 6.5 9 7 8 10 7 10 7 9 11 7.5 11 8 10 12 8 12 8 // assume that slope is gentle M<=1 DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(x1) – Round(x0); xinc = (x1 – x0) / numsteps; yinc = (y1 – y0) / numsteps; x = x0; y = y0; putpixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; putpixel(Round(x),Round(y)); }}
  • 15. DDA Example • Suppose we want to draw a line starting at pixel (15,4) and ending at pixel (20,17). numsteps = xinc = X1-X0= yinc = Y1- y0= Iteration x y Round(x) Round(y) 0 1 2 3 4 5 6 7 8 9 10 // assume that slope is gentle M>1 DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(y1) – Round(y0); xinc = (x1 – x0) / numsteps; yinc = (y1 – y0) / numsteps; x = x0; y = y0; putpixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; putpixel(Round(x),Round(y)); }}
  • 16. DDA Example • Suppose we want to draw a line starting at pixel (6,3) and ending at pixel (8,10). numsteps = ? xinc = ? X1-X0= yinc = ? Y1- y0= Iteration x y Round(x) Round(y) 0 1 2 3 4 5 6 7 8 9 10 // assume that slope is gentle M>1 DDA(float x0, float x1, float y0, float y1) { float x, y; float xinc, yinc; int numsteps; numsteps = Round(y1) – Round(y0); xinc = (x1 – x0) / numsteps; yinc = (y1 – y0) / numsteps; x = x0; y = y0; putpixel(Round(x),Round(y)); for (int i=0; i<numsteps; i++) { x += xinc; y += yinc; putpixel(Round(x),Round(y)); }}
  • 17. DDA Example • Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (5,12). numsteps = ? xinc = ? X1-X0= yinc = ? Y1- y0= Iteration x y Round(x) Round(y) 0 1 2 3 4 5 6 7 8 9 10
  • 18. DDA Algorithm (continued) This DDA algorithm suffers from two reasons.  Floating point calculations and rounding operations are expensive and time consuming. • Due to limited precision and Rounding operations calculated points will not be displayed at its original point. Y_inc X_inc
  • 19. Bresenham’s Algorithm • Uses only integer calculations • Requires less time to generate line due to elimination of floating point calculations.
  • 20. Bresenham’s Algorithm m<=1 1. Input the two line endpoints and store left endpoint as (x0,y0) 2. Pre-calculate the values dx, dy 3. Color pixel (x0,y0) 4. Let p0 = 2dy –dx, Here P0 is decision parameter which tells us which next pixel will glow. 5. At each xk along the line, starting with k=0: 6. Repeat Step-5 Until we does not reach up to final point. Remember! The algorithm and derivation above assumes slopes are less than or equal to 1. for other slopes we need to adjust the algorithm slightly. If pk<0, then the next point to plot is (xk + 1,yk), and pk+1 = pk + 2dy Otherwise, the next point to plot is (xk + 1, yk + 1), and pk+1 = pk + 2dy – 2dx
  • 21. Bresenham’s Algorithm Example Where m<=1 • Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). dx = 12 – 2 = 10 dy = 8 – 3 = 5 p0 = 2dy – dx = 0 t p P(x) P(y) 0 0 2 3 1 -10 3 4 2 0 4 4 3 -10 5 5 4 0 6 5 5 -10 7 6 6 0 8 6 7 -10 9 7 8 0 10 7 9 -10 11 8 10 0 12 8 2dy = 10 2dy – 2dx = -10 Algorithm 1. Input the two line endpoints and store left endpoint as (x0,y0) 2. Pre-calculate the values dx, dy, 2dy and 2dy -dx 3. Color pixel (x0,y0) 4. Let p0 = 2dy –dx 5. At each xk along the line, starting with k=0: 6. Repeat Step-4 dx times If pk<0, then the next point to plot is (xk + 1,yk), and pk+1 = pk + 2dy (Down pixel will be selected) Otherwise, the next point to plot is (xk + 1, yk + 1), and pk+1 = pk + 2dy – 2dx (Upper pixel will be selected)
  • 23. Anti-aliasing • Anti-aliasing is a method of fooling the eye that a jagged edge is really smooth. • Due to low resolution aliasing effect will occur, which can be removed by increasing the screen resolution. Circle after applying antialiasing Jagged edges due to aliasing
  • 25. Reducing Aliasing • By increasing Resolution The aliasing effect can be minimized by increasing resolution of the raster display.
  • 26. Disadvantage of improving resolution • More memory requirement (Size of frame buffer will become Large) • More scan conversion time
  • 27. Anti-aliasing Methods • Super-sampling method or post filtering • Area sampling or Pre filtering
  • 28. Super-sampling Method (Cont….) • In this method every individual pixel is subdivided in to sub-pixel. • In this method we count the number of pixel which are overlapped by the object. • The intensity value of a pixel is the average of the intensity values of all the sampled sub-pixels with in that pixel. • In this method every pixel on the screen have different intensity.
  • 29. Super-sampling for a line object having Non-Zero width.
  • 30. Super-sampling Method (Cont….) • Pixel at upper right corner is assigned 7/9 because seven of its nine-sub pixels are inside the object area. • Suppose the color of object is RED(1,0,0), and the background color is light yellow (.5,.5,.5). • At what intensity the pixel will glow? (1 X 7/9 +.5 X 2/9, 0X7/9+ 0.5 X 2/9, 0X7/9+.5X2/9) R G B Blending of background color and object color will occur only in area of pixel where object overlaps. Question- 1. What will be the intensity of center pixel? Answer- (1 X 1+.5X0, 0X1+.5X0, 0X1+.5X0) 2. What will be the intensity of lower right side pixel? Answer- (1X1/9 + .5X8/9, 0X1/9+.5X8/9, 0X1/9+.5X8/9)
  • 31. Intensity Variation on pixels after Super sampling method
  • 32. Write Formula for Blending of Colors for following Conditions 1. Object Background is (.5,.5,.5) 2. Object Color is (1,1,0) Ans: Write Formula for Blending of Colors for following Conditions 1. Object Background is (.5,.5,.5) 2. Object Color is (1,1,1)
  • 33. Area Sampling Method • This figure shows how line with a non-Zero width have different intensity value at each pixel on the screen • In this Area sampling method intensity value is determined according to area covered by the object. 90% 15% 65% 50%

Editor's Notes

  • #32: Animation is important on this slide. Allows detailed description of process for calculating % coverage for first four pixels, with numerical values displayed to side of diagram. After the first four pixels the animated process will continue automatically.
  • #34: Animation is important on this slide. Allows detailed description of process for calculating % coverage for first four pixels, with numerical values displayed to side of diagram. After the first four pixels the animated process will continue automatically.