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

PPT
Intro to scan conversion
PPTX
Output primitives in Computer Graphics
PPT
Line drawing algo.
PPTX
Point to-point protocol (ppp)
PPTX
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
PPTX
Segments in Graphics
PPT
Window to viewport transformation
PPSX
Edge Detection and Segmentation
Intro to scan conversion
Output primitives in Computer Graphics
Line drawing algo.
Point to-point protocol (ppp)
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
Segments in Graphics
Window to viewport transformation
Edge Detection and Segmentation

What's hot (20)

PPTX
Bresenham's line drawing algorithm
PPTX
Random scan displays and raster scan displays
PDF
Pixel Relationships Examples
PPTX
Computer Graphics
PPTX
HDLC(High level Data Link Control)
PPTX
Computer graphics basic transformation
PPT
Seed filling algorithm
PPTX
Composite transformation
PPTX
Cyrus beck line clipping algorithm
PPTX
Dda algorithm
PPTX
Polygons - Computer Graphics - Notes
PDF
2D Transformation in Computer Graphics
PPTX
Overview of the graphics system
PPT
PPTX
Lossless predictive coding in Digital Image Processing
PPTX
Back face detection
PDF
Unit 3
PPTX
Line Drawing Algorithms - Computer Graphics - Notes
PPTX
Chapter 3 Output Primitives
PPTX
BRESENHAM’S LINE DRAWING ALGORITHM
Bresenham's line drawing algorithm
Random scan displays and raster scan displays
Pixel Relationships Examples
Computer Graphics
HDLC(High level Data Link Control)
Computer graphics basic transformation
Seed filling algorithm
Composite transformation
Cyrus beck line clipping algorithm
Dda algorithm
Polygons - Computer Graphics - Notes
2D Transformation in Computer Graphics
Overview of the graphics system
Lossless predictive coding in Digital Image Processing
Back face detection
Unit 3
Line Drawing Algorithms - Computer Graphics - Notes
Chapter 3 Output Primitives
BRESENHAM’S LINE DRAWING ALGORITHM
Ad

Viewers also liked (8)

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

Similar to Line drawing algorithm and antialiasing techniques (20)

PDF
raster algorithm.pdf
PPTX
Chapter 3 - Part 1 [Autosaved].pptx
PPT
1536 graphics &amp; graphical programming
PPT
Lect14 lines+circles
DOCX
Unit 2 notes
PDF
Line drawing Algorithm DDA in computer Graphics.pdf
PPTX
Study on Fundamentals of Raster Scan Graphics
PPT
Bresenham circles and polygons derication
PPT
Bresenham circlesandpolygons
PDF
Computer Graphics Unit 2
PDF
Computer graphics notes 2 tutorials duniya
PPTX
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
PPTX
4 CG_U1_M3_PPT_4 DDA.pptx
PPTX
Computer Graphics Unit 1
PPT
03.Scan Conversion.ppt
PPTX
L-5 (Line Drawing Algorithms Computer graphics).pptx
PPT
1 linedrawing
PPT
computer_graphics_line_algorithm in Computer Graphics
PDF
Chapter 2 Computer graphics by Kushal Bhattarai
raster algorithm.pdf
Chapter 3 - Part 1 [Autosaved].pptx
1536 graphics &amp; graphical programming
Lect14 lines+circles
Unit 2 notes
Line drawing Algorithm DDA in computer Graphics.pdf
Study on Fundamentals of Raster Scan Graphics
Bresenham circles and polygons derication
Bresenham circlesandpolygons
Computer Graphics Unit 2
Computer graphics notes 2 tutorials duniya
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
4 CG_U1_M3_PPT_4 DDA.pptx
Computer Graphics Unit 1
03.Scan Conversion.ppt
L-5 (Line Drawing Algorithms Computer graphics).pptx
1 linedrawing
computer_graphics_line_algorithm in Computer Graphics
Chapter 2 Computer graphics by Kushal Bhattarai

More from Ankit Garg (11)

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

Recently uploaded (20)

PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PPTX
chapter 1.pptx dotnet technology introduction
PPTX
MAD Unit - 3 User Interface and Data Management (Diploma IT)
PDF
Principles of operation, construction, theory, advantages and disadvantages, ...
PDF
Project_Mgmt_Institute_-Marc Marc Marc .pdf
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PPTX
Principal presentation for NAAC (1).pptx
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
PDF
Computer organization and architecuture Digital Notes....pdf
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
PDF
Designing Fault-Tolerant Architectures for Resilient Oracle Cloud ERP and HCM...
PDF
Research on ultrasonic sensor for TTU.pdf
PDF
electrical machines course file-anna university
PDF
Present and Future of Systems Engineering: Air Combat Systems
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
PPTX
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
PPTX
Cisco Network Behaviour dibuywvdsvdtdstydsdsa
PPTX
Agentic Artificial Intelligence (Agentic AI).pptx
Beginners-Guide-to-Artificial-Intelligence.pdf
chapter 1.pptx dotnet technology introduction
MAD Unit - 3 User Interface and Data Management (Diploma IT)
Principles of operation, construction, theory, advantages and disadvantages, ...
Project_Mgmt_Institute_-Marc Marc Marc .pdf
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
Principal presentation for NAAC (1).pptx
Micro1New.ppt.pptx the mai themes of micfrobiology
Computer organization and architecuture Digital Notes....pdf
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
Designing Fault-Tolerant Architectures for Resilient Oracle Cloud ERP and HCM...
Research on ultrasonic sensor for TTU.pdf
electrical machines course file-anna university
Present and Future of Systems Engineering: Air Combat Systems
Cryptography and Network Security-Module-I.pdf
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
WN UNIT-II CH4_MKaruna_BapatlaEngineeringCollege.pptx
Cisco Network Behaviour dibuywvdsvdtdstydsdsa
Agentic Artificial Intelligence (Agentic AI).pptx

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.