SlideShare a Scribd company logo
1 of 80
Output Primitives
Points and Lines
Line Drawing Algorithms
DDA Algorithm
Bresenham’s Line Algorithm
Midpoint Circle Algorithm
Midpoint Ellipse Algorithm
Filled Area Primitives
Points and Lines
• Point is the fundamental element of picture
representation.
• It is the position in the plan defined as either
pair or triplets of number depending upon the
dimension.
• Two points represent line or edge and 3 or
more points a polygon.
• Curved lines are represented by the short
straight lines.
Line Drawing Algorithms
• Slope-Intercept Equation
• Slope
• Intercept
• Interval Calculation
bxmy  .
12
12
xx
yy
m



11 .xmyb 
xmy  . m
y
x


Line Drawing Algorithm
DDA Algorithm
 Digital Differential Analyzer
– Sample the line at unit intervals in one coordinate
– Determine the corresponding integer values
nearest the line path in another co-ordinate
DDA Algorithm (left to right)
• Slope
• For |m|<1 (|Δy|< |Δx|)
– Sample line at unit interval in x co-ordinate
• For |m|>1 (|Δy|> |Δx|)
– Sample line at unit interval in y co-ordinate
x
y
xx
yy
m
kk
kk








1
1
myy kk 1
m
xx kk
1
1 
11   kk xxx
11   kk yyy
DDA Algorithm (right to left)
• Slope
• For |m|<1 (|Δy|< |Δx|)
– Sample line at unit interval in x co-ordinate
• For |m|>1 (|Δy|> |Δx|)
– Sample line at unit interval in y co-ordinate
myy kk 1
m
xx kk
1
1 
11   kk xxx
11   kk yyy
x
y
xx
yy
m
kk
kk








1
1
DDA Algorithm
1. Input the two line endpoints and store the left endpoint in (x0,y0)
2. Plot first point (x0,y0)
3. Calculate constants Δx, Δy
4. If |Δx| > |Δy| steps = |Δx| else steps = |Δy|
5. Calculate XInc = |Δx| / steps and YInc = |Δy| / steps
6. At each xk along the line, starting at k=0, Plot the next pixel at (xk + XInc, yk
+ YInc)
7. Repeat step 6 steps times
Pseudo Code
Void lineDDA(int xa, int ya, int xb, int yb)
{
int dx = xb – xa, dy = yb – ya, steps, k;
float xIncrement, yIncrement, x = xa, y = ya;
if( abs (dx) > abs (dy) ) steps = abs (dx);
else steps = abs (dy);
xIncrement = dx / (float) steps;
yIncrement = dy / (float) steps;
setPixel (ROUND (x), ROUND (y));
for (k=0; k<steps; k++){
x += xIncrement;
y += yIncrement;
setPixel (ROUND(x), ROUND(y));
}
}
• Use DDA algorithm for rasterizing line (0,0) to
(6,6).
• Use DDA algorithm for rasterizing line (0,0) to
(4,6).
Bresenham’s Line Algorithm
• Uses only incremental integer
calculations
• Which pixel to draw ?
– (11,11) or (11,12) ?
– (51,50) or (51,49) ?
– Answered by Bresenham
• For |m|<1
– Start from left end point (x0,y0) step to each
successive column (x samples) and plot the pixel
whose scan line y value is closest to the line path.
– After (xk,yk) the choice could be (xk+1,yk) or
(xk+1,yk+1)
Then
And
Difference between separations
bxmy k  )1(
kyyd 1
kk ybxm  )1(
yyd k  )1(2
bxmy kk  )1(1
122)1(221  byxmdd kk
Defining decision parameter
[1]
Sign of pk is same as that of d1-d2 for Δx>0 (left to right sampling)
For Recursive calculation, initially
cyxxy kk  .2.2
Constant=2Δy + Δx(2b-1) Which is
independent of pixel position
cyxxyp kkk   111 .2.2
)(2)(2 111 kkkkkk yyxxxypp  
c eliminated here
)(22 11 kkkk yyxypp  
because xk+1 = xk + 1
yk+1-yk = 0 if pk < 0
yk+1-yk = 1 if pk ≥ 0
xyp  20
Substitute b = y0 – m.x0
and m = Δy/Δx in [1]
)( 21 ddxpk 
Algorithm Steps (|m|<1)
1. Input the two line endpoints and store the left endpoint in (x0,y0)
2. Plot first point (x0,y0)
3. Calculate constants Δx, Δy, 2Δy and 2 Δy- 2Δx, and obtain p0 = 2Δy – Δx
4. At each xk along the line, starting at k=0, perform the following test:
If pk<0, the next point plot is (xk+1,yk) and
Pk+1 = pk + 2Δy
Otherwise, the next point to plot is (xk + 1, yk+1) and
Pk+1 = pk + 2Δy - 2Δx
5. Repeat step 4 Δx times
What’s the advantage?
• Answer: involves only the calculation of constants Δx, Δy,
2Δy and 2Δy- 2Δx once and integer addition and
subtraction in each steps
Example
Endpoints (20,10) and (30,18)
Slope m = 0.8
Δx = 10, Δy = 8
P0 = 2Δy - Δx = 6
2Δy = 16, 2Δy-2Δx = -4
Plot (x0,y0) = (20,10)
• Use Bresenham’s algorithm for rasterizing the
line (5,5) to (13,9)
• Digitize a line with endpoints (15,18) and
(10,15) using BLA.
• Digitize a line with endpoints (15,15) and
(10,18) using BLA.
Algorithm Steps (|m|>1)
1. Input the two line endpoints and store the left endpoint in (x0,y0)
2. Plot first point (x0,y0)
3. Calculate constants Δx, Δy, 2Δx and 2 Δx- 2Δy, and obtain p0 = 2Δx – Δy
4. At each xk along the line, starting at k=0, perform the following test:
If pk<0, the next point plot is (xk, yk+1) and
Pk+1 = pk + 2Δx
Otherwise, the next point to plot is (xk + 1, yk+1) and
Pk+1 = pk + 2Δx - 2Δy
5. Repeat step 4 Δx times
• Use BLA algorithm for rasterizing line (0,0) to
(4,6).
Circle-Generating Algorithms (Basic
Foundations)
• Circle Equation:
• Points along circumference could be calculated by stepping along x-
axis:
222
)()( ryyxx cc 
22
)( xxryy cc 
Problem (in above method)
• Computational complexity
• Spacing:
– Non-uniform spacing of
plotted pixels
Adjustments (To fix problems)
• Spacing problem (2 ways):
– Interchange the role of x and y whenever the absolute value of the slope of
the circle tangent > 1
– Use polar co-ordinate:
• Equally spaced points are plotted along the circumference with fixed angular
step size.
• step size chosen for θ depends on the application and display device.
• Computation Problem:
– Use symmetry of circle; i.e calculate for one octant and use symmetry for
others.


sin
cos
ryy
rxx
c
c


Circle Symmetry
Bresenham’s Algorithm Could Be Adapted ??
• Yes
• How ?
– Setting decision parameter for finding the closest
pixel to the circumference
• And what to do For Non-linear equation of
circle ?
– Comparison of squares of the pixel separation
distance avoids square root calculations
Midpoint Circle Algorithm
• Circle function defined as:
• Any point (x,y) satisfies following conditions








boundarycircletheoutsideisyxif
boundarycircletheonisyxif
boundarycircletheinsideisyxif
yxfcircle
),(,0
),(,0
),(,0
),(
222
),( ryxyxfcircle 
• Decision parameter is the circle function; evaluated as:
222
)
2
1
()1(
)
2
1
,1(
ryx
yxfp
kk
kkcirclek


1)()()1(2
)
2
1
(]1)1[(
)
2
1
,1(
1
22
11
22
1
2
111






kkkkkkk
kk
kkcirclek
yyyyxpp
ryx
yxfp
yk+1 = yk if pk<0
yk+1 = yk-1 otherwise
• Thus
Pk+1 = Pk + 2xk+1+1 if pk<0
Pk+1 = Pk + 2xk+1+1-2yk+1 otherwise
• Also incremental evaluation of 2xk+1 and 2yk+1
2xk+1 = 2xk + 2
2yk+1 = 2yk – 2 if pk >0
• At start position (x0,y0) = (0,r)
2x0 = 0 and 2y0 = 2r
• Initial decision parameter
• For r specified as an integer, round p0 to
P0 = 1-r
(because all increments are integers)
r
rr
rfp circle



4
5
)
2
1
(1
)
2
1
,1(
22
0
Algorithm
1. Input radius r and circle center (xc, yc) and obtain the first point on the circumference of
a circle centered on the origin as
(x0,y0) = (0,r)
2. Calculate the initial value of the decision parameter as
P0 = 5/4 – r
3. At each xk position, starting at k = 0, perform the following test:
If pk < 0, the next point along the circle centered on (0,0) is (xk+1,yk) and
Pk+1 = pk + 2xk+1 + 1
Otherwise, the next point along the circle is (xk+1,yK-1) and
Pk+1 = pk + 2xk+1 + 1 -2yk+1
Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk-2
4. Determine the symmetry points in the other seven octants.
5. Move each calculated pixel position (x,y) onto the circular path
centered on (xc,yc) and plot the co-ordinate values:
x = x + xc, y = y+yc
6. Repeat steps 3 through 5 until x ≥ y
• Given radius =10 use mid-point circle drawing
algorithm to determine the pixel in the first
quadrant.
Solution:
P0 = 1-r = -9
(x0 , y0)=(0,10)
2x0 =0
2y0 =20
• Digitize the circle (x-2)^2+(y-3)^2=25 in first
quadrant.
Solution:
P0=(1-r)= -4
(x0 , y0)=(0,5)
2x0 =0
2y0 =10
Ellipse Generating Algorithms
• Equation of ellipse:
• F1(x1,y1), F2(x2,y2)
• General Equation
• Simplified Form
• In polar co-ordinate
constantyyxxyyxx  2
2
2
2
2
1
2
1 )()()()(
constantdd  21
022
 FEyDxCxyByAx
1
22








 





 
y
c
x
c
r
yy
r
xx


sin
cos
yc
xc
ryy
rxx


• Ellipse function
222222
),( yxyellipse rryrxryxf x 







boundaryellipsetheoutsideisyxif
boundaryellipsetheonisyxif
boundaryellipsetheinsideisyxif
yxfellipse
),(,0
),(,0
),(,0
),(
• From ellipse tangent slope:
• At boundary region (slope = -1):
• Start from (0,ry), take x samples to boundary
between 1 and 2
• Switch to sample y from boundary between 1
and 2
(i.e whenever )
yr
xr
dx
dy
x
y
2
2
2
2

yrxr xy
22
22 
yrxr xy
22
22 
Slope=-1
• In the region 1
• For next sample
• Thus increment
222222
)
2
1
()1(
)
2
1
,1(1
yxkxky
kkellipsek
rryrxr
yxfp


 


























22
1
222
1
222
1
222
111
2
1
2
1
)1(211
)
2
1
(1)1(
)
2
1
,1(1
kkxykykk
yxkxky
kkellipsek
yyrrxrpp
rryrxr
yxfp








01,22
01,2
1
22
1
2
2
1
2
kkxyky
kyky
pifyrrxr
pifrxr
increment
•For increment calculation;
Initially:
•Incrementally:
Update x by adding
2ry
2 to first equation
and update y by
subtracting 2rx
2 to
second equation
yxx
y
rryr
xr
22
2
22
02


• Initial value
222
0
22
2
22
0
4
1
1
2
1
2
1
,11
xyxy
yxyxy
yellipse
rrrrp
rrrrr
rfp















(0,ry)
• In the region 2
• For next sample
• Initially
222222
)1()
2
1
(
)1,
2
1
(2
yxkxky
kkellipsek
rryrxr
yxfp


  
































22
1
222
1
2222
2
1
2
111
2
1
2
1
)1(222
11
2
1
)1,
2
1
(2
kkyxkxkk
yxkxky
kkellipsek
xxrryrpp
rryrxr
yxfp
222
0
2
2
0
2
0
000
)1(
2
1
2
1,
2
1
2
yxxy
ellipse
rryrxrp
yxfp














For simplification calculation of
p20 can be done by selecting
pixel positions in counter
clockwise order starting at (rx,0)
and unit samples to positive y
direction until the boundary
between two regions
Algorithm
1. Input rx,ry, and the ellipse center(xc,yc) and obtain the first point on an ellipse centered on the origin as
(x0,y0) = (0,ry)
2. Calculate the initial value of the decision parameter in region 1 as
3. At each xk position in region 1, starting at k = 0, perform the following test: If p1k < 0, the next point along the
ellipse centered on (0,0) is (xk+1,yk) and
Otherwise, the next point along the ellipse is (xk+1,yk-1) and
With
and continue until
222
0
4
1
1 xyxy rrrrp 
2
1
2
1 211 ykykk rxrpp  
2
1
2
1
2
1 2211 ykxkykk ryrxrpp  
22
1
222
1
2
222,222 xkxkxykyky ryryrrxrxr  
yrxr xy
22
22 
4. Calculate the initial value of decision parameter in region 2 using the last point (x0,y0) calculated in region 1 as
5. At each yk position in region 2, starting at k = 0, perform the following test: If p2k>0, the next point along the
ellipse centered on (0,0) is (xk,yk-1) and
Otherwise the next point along the ellipse is (xk+1,yk-1) and
Using the same incremental calculations for x and y as in region 1.
6. Determine the symmetry points in the other three quadrants.
7. Move each calculated pixel position (x,y) onto the elliptical path centered on (xc,yc) and plot the co-ordinate
values:
X = x + xc, y = y+ yc
8. Repeat the steps for region 1 until
222
0
2
2
0
2
0 )1(
2
1
2 yxxy rryrxrp 






2
1
2
1 222 xkxkk ryrpp  
2
1
2
1
2
1 2222 xkxkykk ryrxrpp  
yrxr xy
22
22 
• Digitize the ellipse with parameter rx =8 and
ry =6 in first quadrant.
Solution:
Filled Area Primitives
• Two basic approaches for area filling:
– By determining overlap intervals for scan lines
– Start from given interior position and filling
outwards
Scan Line Polygon Filled Algorithm
• Intersection points of scan line with the
polygon edge are calculated.
• Points are sorted from left to right.
• Corresponding frame buffer position between
each intersection pair are set by specified
color.
• A scan line pass through vertex, intersect two
polygon edges.
• Scan line y’
– Intersect even number of edges
– 2 pairs of intersection points correctly find the
interior span
• Scan line y
– Intersect an odd number of edges(5)
– Must count the vertex intersection as only one
point
How to distinguish these cases?
• Scan line y
– Intersecting edges are on the opposite side
• Scan line y’
– Intersecting edges are on the same side.
• By tracing around the boundary,
– If the endpoint y values of two consecutive edges
monotonically increases or decreases count
middle vertex as single
Implementation
• In determining edge intersection, we can set
up incremental set up calculation using fact
that slope of edge is constant.
Inside Outside test
• Odd Even rule:
– Odd edge means interior
• Non zero winding number rule
– Non zero winding number means interior
Scan line fill for Curved Area
• Require more works than polygon filling due
to non-linear boundary.
• We calculate the scan line intersection and fill
all the interior points.
• Symmetries between the quadrant can be
used to reduce the calculation.
Boundary fill algorithm
• Fill the region starting from the interior point
until the appropriate color boundary is
reached.
• Two ways:
– 4 connected
– 8 connected
4 connected
8 connected
Using 4 connected flood fill algorithm

More Related Content

What's hot

Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformationAnkit Garg
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Raster scan systems with video controller and display processor
Raster scan systems with video controller and display processorRaster scan systems with video controller and display processor
Raster scan systems with video controller and display processorhemanth kumar
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesOmprakash Chauhan
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 
Input devices in computer graphics
Input devices in computer graphicsInput devices in computer graphics
Input devices in computer graphicsAnu Garg
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphicsSafayet Hossain
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notessmruti sarangi
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniquesMani Kanth
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics systemKamal Acharya
 
Scan line method
Scan line methodScan line method
Scan line methodPooja Dixit
 

What's hot (20)

Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Raster scan systems with video controller and display processor
Raster scan systems with video controller and display processorRaster scan systems with video controller and display processor
Raster scan systems with video controller and display processor
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Input devices in computer graphics
Input devices in computer graphicsInput devices in computer graphics
Input devices in computer graphics
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
Scan line method
Scan line methodScan line method
Scan line method
 

Viewers also liked

Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c versionMarwa Al-Rikaby
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Saikrishna Tanguturu
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphicsAaina Katyal
 
Composite transformations
Composite transformationsComposite transformations
Composite transformationsMohd Arif
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)Amit Kapoor
 
Graphics input and output devices
Graphics input and output devicesGraphics input and output devices
Graphics input and output devicesVamsi Dhar
 
Computer Graphics Introduction
Computer Graphics IntroductionComputer Graphics Introduction
Computer Graphics IntroductionGhaffar Khan
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversionMohd Arif
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformationsMohd Arif
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm774474
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transformPatel Punit
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmMahesh Kodituwakku
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics Barani Tharan
 

Viewers also liked (20)

Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle alg...
 
applications of computer graphics
applications of computer graphicsapplications of computer graphics
applications of computer graphics
 
Composite transformations
Composite transformationsComposite transformations
Composite transformations
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)
 
Graphics input and output devices
Graphics input and output devicesGraphics input and output devices
Graphics input and output devices
 
Computer Graphics Introduction
Computer Graphics IntroductionComputer Graphics Introduction
Computer Graphics Introduction
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
2 d geometric transformations
2 d geometric transformations2 d geometric transformations
2 d geometric transformations
 
dda algorithm
dda  algorithmdda  algorithm
dda algorithm
 
Unit 3
Unit 3Unit 3
Unit 3
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics
 

Similar to Output primitives in Computer Graphics

Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi54MahakBansal
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsThirunavukarasu Mani
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 

Similar to Output primitives in Computer Graphics (20)

Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
module 1.pdf
module 1.pdfmodule 1.pdf
module 1.pdf
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
2.circle
2.circle2.circle
2.circle
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 

More from Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer SecurityKamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHPKamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in phpKamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPKamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data WarehousingKamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data MiningKamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data MiningKamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingKamal Acharya
 

More from Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Recently uploaded

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

Output primitives in Computer Graphics

  • 1. Output Primitives Points and Lines Line Drawing Algorithms DDA Algorithm Bresenham’s Line Algorithm Midpoint Circle Algorithm Midpoint Ellipse Algorithm Filled Area Primitives
  • 2. Points and Lines • Point is the fundamental element of picture representation. • It is the position in the plan defined as either pair or triplets of number depending upon the dimension. • Two points represent line or edge and 3 or more points a polygon. • Curved lines are represented by the short straight lines.
  • 3. Line Drawing Algorithms • Slope-Intercept Equation • Slope • Intercept • Interval Calculation bxmy  . 12 12 xx yy m    11 .xmyb  xmy  . m y x  
  • 5.
  • 6.
  • 7. DDA Algorithm  Digital Differential Analyzer – Sample the line at unit intervals in one coordinate – Determine the corresponding integer values nearest the line path in another co-ordinate
  • 8. DDA Algorithm (left to right) • Slope • For |m|<1 (|Δy|< |Δx|) – Sample line at unit interval in x co-ordinate • For |m|>1 (|Δy|> |Δx|) – Sample line at unit interval in y co-ordinate x y xx yy m kk kk         1 1 myy kk 1 m xx kk 1 1  11   kk xxx 11   kk yyy
  • 9. DDA Algorithm (right to left) • Slope • For |m|<1 (|Δy|< |Δx|) – Sample line at unit interval in x co-ordinate • For |m|>1 (|Δy|> |Δx|) – Sample line at unit interval in y co-ordinate myy kk 1 m xx kk 1 1  11   kk xxx 11   kk yyy x y xx yy m kk kk         1 1
  • 10. DDA Algorithm 1. Input the two line endpoints and store the left endpoint in (x0,y0) 2. Plot first point (x0,y0) 3. Calculate constants Δx, Δy 4. If |Δx| > |Δy| steps = |Δx| else steps = |Δy| 5. Calculate XInc = |Δx| / steps and YInc = |Δy| / steps 6. At each xk along the line, starting at k=0, Plot the next pixel at (xk + XInc, yk + YInc) 7. Repeat step 6 steps times
  • 11. Pseudo Code Void lineDDA(int xa, int ya, int xb, int yb) { int dx = xb – xa, dy = yb – ya, steps, k; float xIncrement, yIncrement, x = xa, y = ya; if( abs (dx) > abs (dy) ) steps = abs (dx); else steps = abs (dy); xIncrement = dx / (float) steps; yIncrement = dy / (float) steps; setPixel (ROUND (x), ROUND (y)); for (k=0; k<steps; k++){ x += xIncrement; y += yIncrement; setPixel (ROUND(x), ROUND(y)); } }
  • 12.
  • 13.
  • 14. • Use DDA algorithm for rasterizing line (0,0) to (6,6). • Use DDA algorithm for rasterizing line (0,0) to (4,6).
  • 15.
  • 16.
  • 17.
  • 18. Bresenham’s Line Algorithm • Uses only incremental integer calculations • Which pixel to draw ? – (11,11) or (11,12) ? – (51,50) or (51,49) ? – Answered by Bresenham
  • 19. • For |m|<1 – Start from left end point (x0,y0) step to each successive column (x samples) and plot the pixel whose scan line y value is closest to the line path. – After (xk,yk) the choice could be (xk+1,yk) or (xk+1,yk+1)
  • 20. Then And Difference between separations bxmy k  )1( kyyd 1 kk ybxm  )1( yyd k  )1(2 bxmy kk  )1(1 122)1(221  byxmdd kk
  • 21. Defining decision parameter [1] Sign of pk is same as that of d1-d2 for Δx>0 (left to right sampling) For Recursive calculation, initially cyxxy kk  .2.2 Constant=2Δy + Δx(2b-1) Which is independent of pixel position cyxxyp kkk   111 .2.2 )(2)(2 111 kkkkkk yyxxxypp   c eliminated here )(22 11 kkkk yyxypp   because xk+1 = xk + 1 yk+1-yk = 0 if pk < 0 yk+1-yk = 1 if pk ≥ 0 xyp  20 Substitute b = y0 – m.x0 and m = Δy/Δx in [1] )( 21 ddxpk 
  • 22. Algorithm Steps (|m|<1) 1. Input the two line endpoints and store the left endpoint in (x0,y0) 2. Plot first point (x0,y0) 3. Calculate constants Δx, Δy, 2Δy and 2 Δy- 2Δx, and obtain p0 = 2Δy – Δx 4. At each xk along the line, starting at k=0, perform the following test: If pk<0, the next point plot is (xk+1,yk) and Pk+1 = pk + 2Δy Otherwise, the next point to plot is (xk + 1, yk+1) and Pk+1 = pk + 2Δy - 2Δx 5. Repeat step 4 Δx times
  • 23. What’s the advantage? • Answer: involves only the calculation of constants Δx, Δy, 2Δy and 2Δy- 2Δx once and integer addition and subtraction in each steps
  • 24. Example Endpoints (20,10) and (30,18) Slope m = 0.8 Δx = 10, Δy = 8 P0 = 2Δy - Δx = 6 2Δy = 16, 2Δy-2Δx = -4 Plot (x0,y0) = (20,10)
  • 25. • Use Bresenham’s algorithm for rasterizing the line (5,5) to (13,9)
  • 26.
  • 27. • Digitize a line with endpoints (15,18) and (10,15) using BLA.
  • 28.
  • 29. • Digitize a line with endpoints (15,15) and (10,18) using BLA.
  • 30.
  • 31. Algorithm Steps (|m|>1) 1. Input the two line endpoints and store the left endpoint in (x0,y0) 2. Plot first point (x0,y0) 3. Calculate constants Δx, Δy, 2Δx and 2 Δx- 2Δy, and obtain p0 = 2Δx – Δy 4. At each xk along the line, starting at k=0, perform the following test: If pk<0, the next point plot is (xk, yk+1) and Pk+1 = pk + 2Δx Otherwise, the next point to plot is (xk + 1, yk+1) and Pk+1 = pk + 2Δx - 2Δy 5. Repeat step 4 Δx times
  • 32. • Use BLA algorithm for rasterizing line (0,0) to (4,6).
  • 33. Circle-Generating Algorithms (Basic Foundations) • Circle Equation: • Points along circumference could be calculated by stepping along x- axis: 222 )()( ryyxx cc  22 )( xxryy cc 
  • 34. Problem (in above method) • Computational complexity • Spacing: – Non-uniform spacing of plotted pixels
  • 35. Adjustments (To fix problems) • Spacing problem (2 ways): – Interchange the role of x and y whenever the absolute value of the slope of the circle tangent > 1 – Use polar co-ordinate: • Equally spaced points are plotted along the circumference with fixed angular step size. • step size chosen for θ depends on the application and display device. • Computation Problem: – Use symmetry of circle; i.e calculate for one octant and use symmetry for others.   sin cos ryy rxx c c  
  • 37. Bresenham’s Algorithm Could Be Adapted ?? • Yes • How ? – Setting decision parameter for finding the closest pixel to the circumference • And what to do For Non-linear equation of circle ? – Comparison of squares of the pixel separation distance avoids square root calculations
  • 38. Midpoint Circle Algorithm • Circle function defined as: • Any point (x,y) satisfies following conditions         boundarycircletheoutsideisyxif boundarycircletheonisyxif boundarycircletheinsideisyxif yxfcircle ),(,0 ),(,0 ),(,0 ),( 222 ),( ryxyxfcircle 
  • 39. • Decision parameter is the circle function; evaluated as: 222 ) 2 1 ()1( ) 2 1 ,1( ryx yxfp kk kkcirclek   1)()()1(2 ) 2 1 (]1)1[( ) 2 1 ,1( 1 22 11 22 1 2 111       kkkkkkk kk kkcirclek yyyyxpp ryx yxfp
  • 40. yk+1 = yk if pk<0 yk+1 = yk-1 otherwise • Thus Pk+1 = Pk + 2xk+1+1 if pk<0 Pk+1 = Pk + 2xk+1+1-2yk+1 otherwise • Also incremental evaluation of 2xk+1 and 2yk+1 2xk+1 = 2xk + 2 2yk+1 = 2yk – 2 if pk >0 • At start position (x0,y0) = (0,r) 2x0 = 0 and 2y0 = 2r
  • 41. • Initial decision parameter • For r specified as an integer, round p0 to P0 = 1-r (because all increments are integers) r rr rfp circle    4 5 ) 2 1 (1 ) 2 1 ,1( 22 0
  • 42. Algorithm 1. Input radius r and circle center (xc, yc) and obtain the first point on the circumference of a circle centered on the origin as (x0,y0) = (0,r) 2. Calculate the initial value of the decision parameter as P0 = 5/4 – r 3. At each xk position, starting at k = 0, perform the following test: If pk < 0, the next point along the circle centered on (0,0) is (xk+1,yk) and Pk+1 = pk + 2xk+1 + 1 Otherwise, the next point along the circle is (xk+1,yK-1) and Pk+1 = pk + 2xk+1 + 1 -2yk+1 Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk-2 4. Determine the symmetry points in the other seven octants. 5. Move each calculated pixel position (x,y) onto the circular path centered on (xc,yc) and plot the co-ordinate values: x = x + xc, y = y+yc 6. Repeat steps 3 through 5 until x ≥ y
  • 43. • Given radius =10 use mid-point circle drawing algorithm to determine the pixel in the first quadrant. Solution: P0 = 1-r = -9 (x0 , y0)=(0,10) 2x0 =0 2y0 =20
  • 44.
  • 45.
  • 46. • Digitize the circle (x-2)^2+(y-3)^2=25 in first quadrant. Solution: P0=(1-r)= -4 (x0 , y0)=(0,5) 2x0 =0 2y0 =10
  • 47.
  • 48.
  • 49.
  • 50. Ellipse Generating Algorithms • Equation of ellipse: • F1(x1,y1), F2(x2,y2) • General Equation • Simplified Form • In polar co-ordinate constantyyxxyyxx  2 2 2 2 2 1 2 1 )()()()( constantdd  21 022  FEyDxCxyByAx 1 22                  y c x c r yy r xx   sin cos yc xc ryy rxx  
  • 51. • Ellipse function 222222 ),( yxyellipse rryrxryxf x         boundaryellipsetheoutsideisyxif boundaryellipsetheonisyxif boundaryellipsetheinsideisyxif yxfellipse ),(,0 ),(,0 ),(,0 ),(
  • 52. • From ellipse tangent slope: • At boundary region (slope = -1): • Start from (0,ry), take x samples to boundary between 1 and 2 • Switch to sample y from boundary between 1 and 2 (i.e whenever ) yr xr dx dy x y 2 2 2 2  yrxr xy 22 22  yrxr xy 22 22  Slope=-1
  • 53. • In the region 1 • For next sample • Thus increment 222222 ) 2 1 ()1( ) 2 1 ,1(1 yxkxky kkellipsek rryrxr yxfp                               22 1 222 1 222 1 222 111 2 1 2 1 )1(211 ) 2 1 (1)1( ) 2 1 ,1(1 kkxykykk yxkxky kkellipsek yyrrxrpp rryrxr yxfp         01,22 01,2 1 22 1 2 2 1 2 kkxyky kyky pifyrrxr pifrxr increment •For increment calculation; Initially: •Incrementally: Update x by adding 2ry 2 to first equation and update y by subtracting 2rx 2 to second equation yxx y rryr xr 22 2 22 02  
  • 55. • In the region 2 • For next sample • Initially 222222 )1() 2 1 ( )1, 2 1 (2 yxkxky kkellipsek rryrxr yxfp                                      22 1 222 1 2222 2 1 2 111 2 1 2 1 )1(222 11 2 1 )1, 2 1 (2 kkyxkxkk yxkxky kkellipsek xxrryrpp rryrxr yxfp 222 0 2 2 0 2 0 000 )1( 2 1 2 1, 2 1 2 yxxy ellipse rryrxrp yxfp               For simplification calculation of p20 can be done by selecting pixel positions in counter clockwise order starting at (rx,0) and unit samples to positive y direction until the boundary between two regions
  • 56. Algorithm 1. Input rx,ry, and the ellipse center(xc,yc) and obtain the first point on an ellipse centered on the origin as (x0,y0) = (0,ry) 2. Calculate the initial value of the decision parameter in region 1 as 3. At each xk position in region 1, starting at k = 0, perform the following test: If p1k < 0, the next point along the ellipse centered on (0,0) is (xk+1,yk) and Otherwise, the next point along the ellipse is (xk+1,yk-1) and With and continue until 222 0 4 1 1 xyxy rrrrp  2 1 2 1 211 ykykk rxrpp   2 1 2 1 2 1 2211 ykxkykk ryrxrpp   22 1 222 1 2 222,222 xkxkxykyky ryryrrxrxr   yrxr xy 22 22 
  • 57. 4. Calculate the initial value of decision parameter in region 2 using the last point (x0,y0) calculated in region 1 as 5. At each yk position in region 2, starting at k = 0, perform the following test: If p2k>0, the next point along the ellipse centered on (0,0) is (xk,yk-1) and Otherwise the next point along the ellipse is (xk+1,yk-1) and Using the same incremental calculations for x and y as in region 1. 6. Determine the symmetry points in the other three quadrants. 7. Move each calculated pixel position (x,y) onto the elliptical path centered on (xc,yc) and plot the co-ordinate values: X = x + xc, y = y+ yc 8. Repeat the steps for region 1 until 222 0 2 2 0 2 0 )1( 2 1 2 yxxy rryrxrp        2 1 2 1 222 xkxkk ryrpp   2 1 2 1 2 1 2222 xkxkykk ryrxrpp   yrxr xy 22 22 
  • 58. • Digitize the ellipse with parameter rx =8 and ry =6 in first quadrant. Solution:
  • 59.
  • 60.
  • 61.
  • 62. Filled Area Primitives • Two basic approaches for area filling: – By determining overlap intervals for scan lines – Start from given interior position and filling outwards
  • 63. Scan Line Polygon Filled Algorithm • Intersection points of scan line with the polygon edge are calculated. • Points are sorted from left to right. • Corresponding frame buffer position between each intersection pair are set by specified color.
  • 64.
  • 65. • A scan line pass through vertex, intersect two polygon edges.
  • 66. • Scan line y’ – Intersect even number of edges – 2 pairs of intersection points correctly find the interior span • Scan line y – Intersect an odd number of edges(5) – Must count the vertex intersection as only one point
  • 67. How to distinguish these cases? • Scan line y – Intersecting edges are on the opposite side • Scan line y’ – Intersecting edges are on the same side. • By tracing around the boundary, – If the endpoint y values of two consecutive edges monotonically increases or decreases count middle vertex as single
  • 69.
  • 70. • In determining edge intersection, we can set up incremental set up calculation using fact that slope of edge is constant.
  • 71.
  • 72.
  • 73. Inside Outside test • Odd Even rule: – Odd edge means interior • Non zero winding number rule – Non zero winding number means interior
  • 74.
  • 75. Scan line fill for Curved Area • Require more works than polygon filling due to non-linear boundary. • We calculate the scan line intersection and fill all the interior points. • Symmetries between the quadrant can be used to reduce the calculation.
  • 76. Boundary fill algorithm • Fill the region starting from the interior point until the appropriate color boundary is reached. • Two ways: – 4 connected – 8 connected
  • 77.
  • 80. Using 4 connected flood fill algorithm