SlideShare une entreprise Scribd logo
1  sur  50
Bresenham's line drawing algorithm & Mid
Point Circle algorithm
Computer Graphics
Team Members
Group-I Assignment Topic : BRESENHARAM'S ALGORITHM (ELIPSE Drawing)
Group's representative: TANGUTURU SAI KRISHNA
S.No. BITS ID NAME Official Email ID Personal Email ID
1 2011HW69898
TANGUTURU SAI KRISHNA saikrishna.tanguturu@wipro.com sai.tsk2008@gmail.com
2 2011HW69900
RAYAPU MOSES rayapu.moses@wipro.com stalinkvd001@gmail.com
3 2011HW69932 SHENBAGAMOORTHY A
shenbagamoorthy.a83@wipro.com moorthy2626@gmail.com
4 2011HW69913
ANURUPA K C anurupa.c85@wipro.com anu.rupa30@gmail.com
5 2011HW69909
ARUNJUNAISELVAM P arunjunaiselvam.p95@wipro.com arunjunai.carrer@gmail.com
6 2011HW69569
PRANOB JYOTI KALITA pranob.kalita@wipro.com pranob.kalita90@gmail.com
7 2011HW69893
TINNALURI V N PRASANTH prasanth.tinnaluri@wipro.com naga.prasanth985@gmail.com
8 2011HW69904
KONDALA SUMATHI sumathi.kondala@wipro.com sumathi.kondala@gmail.com
9 2011HW69896
DASIKA KRISHNA dasika.krishna@wipro.com dasikakrishnas@gmail.com
Lines
3
Analog devises, such as a random-scan display or a
vector plotter, display a straight line smoothly from
one endpoint to another. Linearly varying horizontal
and vertical deflection voltages are generated that are
proportional to the required changes in the x and y
directions to produce the smooth line.
Digital devices display a straight line by plotting
discrete coordinate points along the line path which are
calculated from the equation of the line.
Screen locations are referenced with integer values, so plotted
positions may only approximate actual line positions between
two specific endpoints.
A computed line position of (10.48, 20.51) will be converted to
pixel position (10, 21). This rounding of coordinate values to
integers causes lines to be displayed with a stairstep appearance
(the “jaggies”).
Particularly noticeable on systems with low resolution.
To smooth raster lines, pixel intensities along the line paths must
be adjusted.
4
Line Drawing Algorithms
Cartesian equation:
y = mx + c
where
m – slope
c – y-intercept
x
y
xx
yy
m






12
12
5
x1
y1
x2
y2
Slope
6
if |m| = 1
 = 45°
45°
45°
+ve -ve
°
°
°
°
if |m|  1
-45° <  < 45°
if |m|  1
45° <  < 90° or
-90° <  < -45°
x y
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
7
8 
7 
6 
5 
4 
3 
2 
1 
0 
0 1 2 3 4 5 6 7 8
y = x
m = 1
c = 0
y
x
|m| = 1
x y round(y)
0 1 1
1 1.5 2
2 2 2
3 2.5 3
4 3 3
5 3.5 4
6 4 4
7 4.5 58
8
7
6
5  
4  
3  
2  
1 
0
0 1 2 3 4 5 6 7 8
y = ½ x + 1
m = ½
c = 1
y
x
|m|  1
9
|m|  1
8
7 
6
5
4 
3
2
1 
0
0 1 2 3 4 5 6 7 8
y = 3x - 2
m = 3
c = -2 y
x
x y round(y)
0 -2 -2
1 1 1
2 4 4
3 7 7
4 10 10
5 13 13
6 16 16
7 19 19
outside
Bresenham Line Algorithm
A more efficient approach
Basis of the algorithm:
From start position decide A or B next
A
B
10
Start position
Bresenham Line Algorithm
11
For a given value of x
one pixel lies at distance ti above the line, and
one pixel lies at distance si below the line
True line
si
ti
Bresenham Line Algorithm
12
Decision parameter
di = (si - ti)
If di  0, then closest pixel is below true line (si smaller)
If di  0, then closest pixel is above true line (ti smaller)
We must calculate the new values for di as we move
along the line.
Example:
13
)2or5.0(i.e.0.5(slope)gradientLet dxdy
dx
dy

3dy
2dy
dy
Start pixel at (x0,y1)
4dy
At x1 :
s1 = dy t1 = dx - dy
d1 = (si - ti) = dy - (dx - dy) = 2dy - dx
but 2dy  dx  di  0  y stays the same
hence next pixel is at (x1,y1)
At x2 :
s2 = 2dy t2 = dx - 2dy
d2 = (s2 – t2) = 2dy - (dx - 2dy) = 4dy - dx
Suppose d2  0  y is incremented
hence next pixel is at (x2,y2)
At x3 :
s3 = 3dy - dx t2 = 2dx - 3dy
d3 = (s2 – t3) = 6dy - 3dx  0
so y stays the same
hence next pixel is at (x3,y2)
x1 x2 x3
x4 x5
x0
y0
y1
y2
y3
y5
In General
14
For a line with gradient ≤ 1
d0 = 2dy – dx
if di  0 then yi+1 = yi
di+1 = di + 2dy
if di ≥ 0 then yi+1 = yi + 1
di+1 = di + 2(dy – dx)
xi+1 = xi + 1
For a line with gradient  1
d0 = 2dx – dy
if di  0 then xi+1 = xi
di+1 = di + 2dx
if di ≥ 0 then xi+1 = xi + 1
di+1 = di + 2(dx – dy)
yi+1 = yi + 1
Note: For |m| ≤ 1 the constants 2dy and 2(dy-dx) can be calculated
once,
so the arithmetic will involve only integer addition and subtraction.
Example – Draw a line from (20,10) to (30,18)
19
18
17
16
15
14
13
12
15
(20,10)
(30,18)
dx = 10
dy = 8
initial decision d0 = 2dy – dx = 6
Also 2dy = 16, 2(dy – dx) = -4
i di (xi+1,yi+1)
0 6 (21,11)
1 2 (22,12)
2 -2 (23,12)
3 14 (24,13)
4 10 (25,14)
5 6 (26,15)
6 2 (27,16)
7 -2 (28,16)
8 14 (29,17)
9 10 (30,18)
16
void LineBres(int x0, int y0, int x1, int y1) // line for |m| < 1
{
int dx = abs(x1 – x0), dy = abs(y1 – y0);
int d = 2 * dy – dx, twoDy = 2 * dy, twoDyMinusDx = 2 * (dy – dx);
int x, y;
if (x0 > x1) { // determines which point to use as start, which as
end
x = x1;
y = y1;
x1 = x0;
}
else {
x = x0;
y = y0;
}
setPixel(x,y);
while (x < x1) {
x++;
if (d < 0) d += twoDy;
else {
y++;
d += twoDyMinusDx;
}
setPixel(x, y);
}
}
Special cases
17
 Special cases can be handled separately
 Horizontal lines (y = 0)
 Vertical lines (x = 0)
 Diagonal lines (|x| = |y|)
 directly into the frame-buffer without processing
them through the line-plotting algorithms.
Circle Equations
18
 Polar form
x = rCos
y = rSin (r = radius of circle)

P=(rCos, rSin)
rSin)
rCos)
x
y
r
Drawing a circle
19
Disadvantages
 To find a complete circle  varies from 0° to 360°
 The calculation of trigonometric functions is very
slow.
 = 0°
while ( < 360°)
x = rCos
y = rSin
setPixel(x,y)
 =  + 1°
end while
Cartesian form
 Use Pythagoras theorem
x2 + y2 = r2
20
x
r
y
y
x x
y
r
 2 2
,P x r x 
Circle algorithms
21
 Step through x-axis to determine y-values
 Disadvantages:
– Not all pixel filled in
– Square root function is very slow
Circle Algorithms
22
 Use 8-fold symmetry and only compute pixel
positions for the 45° sector.
45°
(x, y)
(y, x)
(-x, y)
(y, -x)
(x, -y)(-x, -y)
(-y, x)
(-y, -x)
Bresenham’s Circle Algorithm
General Principle
 The circle function:
 and
2 2 2
( , )circlef x y x y r  
23
Consider only
45° ≤  ≤ 90°
if (x,y) is inside the circle boundary
if (x,y) is on the circle boundary
if (x,y) is outside the circle boundary
0
( , ) 0
0
circlef x y


 

Bresenham’s Circle Algorithm
24
p1 p3
p2
D(si)
D(ti)
After point p1, do we choose p2 or p3?
yi
yi - 1
xi xi + 1
r
Bresenham’s Circle Algorithm
25
Define: D(si) = distance of p3 from circle
D(ti) = distance of p2 from circle
i.e. D(si) = (xi + 1)2 + yi
2 – r2 [always +ve]
D(ti) = (xi + 1)2 + (yi – 1)2 – r2 [always -ve]
 Decision Parameter pi = D(si) + D(ti)
so if pi < 0 then the circle is closer to p3 (point
above)
if pi ≥ 0 then the circle is closer to p2 (point below)
The Algorithm
26
x0 = 0
y0 = r
p0 = [12 + r2 – r2] + [12 + (r-1)2 – r2] = 3 – 2r
if pi < 0 then
yi+1 = yi
pi+1 = pi + 4xi + 6
else if pi ≥ 0 then
yi+1 = yi – 1
pi+1 = pi + 4(xi – yi) + 10
 Stop when xi ≥ yi and determine symmetry
points in the other octants
xi+1 = xi + 1
Example
10    
9  
8 
7 
6 
5 
4 
3 
2 
1 
0 
0 1 2 3 4 5 6 7 8 9 10
27
i pi xi, yi
0 -17 (0, 10)
1 -11 (1, 10)
2 -1 (2, 10)
3 13 (3, 10)
4 -5 (4, 9)
r = 10
p0 = 3 – 2r = -17
Initial point (x0, y0) = (0, 10)
Midpoint Circle Algorithm
yi 
yi-1
xi xi+1 xi+2
28
Midpoint
x2 + y2 – r2 = 0
Assuming that we have just plotted the pixels at (xi , yi).
Which is next? (xi+1, yi) OR (xi+1, yi – 1).
- The one that is closer to the circle.
Midpoint Circle Algorithm
 The decision parameter is the circle at the midpoint
between the pixels yi and yi – 1.
 If pi < 0, the midpoint is inside the circle and the pixel
yi is closer to the circle boundary.
 If pi ≥ 0, the midpoint is outside the circle and the
pixel yi - 1 is closer to the circle boundary.
1
2
2 2 21
2
( 1, )
( 1) ( )
i circle i i
i i
p f x y
x y r
  
    
29
Decision Parameters
 Decision Parameters are obtained using
incremental calculations
OR
where yi+1 is either yi or yi-1 depending on the sign of pi
1
1 1 1 2
2 2 21
1 2
( 1, )
( 2) ( )
i circle i i
i i
p f x y
x y r
  

  
    
2 2 2
1 1 12( 1) ( ) ( ) 1i i i i i i ip p x y y y y         
30
Note:
xi+1 = xi +1
The Algorithm1. Initial values:- point(0,r)
x0 = 0
y0 = r
2. Initial decision parameter
3. At each xi position, starting at i = 0, perform the
following test: if pi < 0, the next point is (xi + 1, yi) and
pi+1 = pi + 2xi+1 + 1
If pi ≥ 0, the next point is (xi+1, yi-1) and
pi+1 = pi + 2xi+1 + 1 – 2yi+1
where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 2
4. Determine symmetry points in the other octants
5. Move pixel positions (x,y) onto the circular path
centered on (xc, yc) and plot the coordinates: x = x + xc,
y = y + yc
6. Repeat 3 – 5 until x ≥ y
2 2 51 1
0 2 2 4(1, ) 1 ( )circlep f r r r r       
31
move circle origin at (0,0) by
x = x – xc and y = y – yc
Example
10    
9  
8 
7 
6 
5 
4 
3 
2 
1 
0 
0 1 2 3 4 5 6 7 8 9 10
32
i pi xi+1,
yi+1
2xi+
1
2yi+
1
0 -9 (1, 10) 2 20
1 -6 (2, 10) 4 20
2 -1 (3, 10) 6 20
3 6 (4, 9) 8 18
4 -3 (5, 9) 10 18
5 8 (6, 8) 12 16
6 5 (7, 7)
r = 10
p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer)
Initial point (x0, y0) = (0, 10)
33
Midpoint function
void plotpoints(int x, int y)
{
setpixel(xcenter+x, ycenter+y);
setpixel(xcenter-x, ycenter+y);
setpixel(xcenter+x, ycenter-y);
setpixel(xcenter-x, ycenter-y);
setpixel(xcenter+y, ycenter+x);
setpixel(xcenter-y, ycenter+x);
setpixel(xcenter+y, ycenter-x);
setpixel(xcenter-y, ycenter-x);
}
void circle(int r)
{
int x = 0, y = r;
plotpoints(x,y);
int p = 1 – r;
while (x<y) {
x++;
if (p<0) p += 2*x + 1;
else {
y--;
p += 2*(x-y) + 1;
}
plotpoints(x,y);
}
}
34
Ellipse-Generating Algorithms
 Ellipse – A modified circle whose radius varies from a
maximum value in one direction (major axis) to a minimum
value in the perpendicular direction (minor axis).
P=(x,y)F1
F2
d1
d2
 The sum of the two distances d1 and d2, between the fixed positions F1 and
F2 (called the foci of the ellipse) to any point P on the ellipse, is the same
value, i.e.
d1 + d2 = constant
35
Ellipse Properties
 Expressing distances d1 and d2 in terms of the focal
coordinates F1 = (x1, x2) and F2 = (x2, y2), we have:
 Cartesian coordinates:
 Polar coordinates:
2 2 2 2
1 1 2 2( ) ( ) ( ) ( ) constantx x y y x x y y       
ry
rx
22
1c c
x y
x x y y
r r
   
     
   
cos
sin
c x
c y
x x r
y y r


 
 
36
Ellipse Algorithms
 Symmetry between quadrants
 Not symmetric between the two octants of a quadrant
 Thus, we must calculate pixel positions along the
elliptical arc through one quadrant and then we obtain
positions in the remaining 3 quadrants by symmetry
(x, y)(-x, y)
(x, -y)(-x, -y)
rx
ry
37
Ellipse Algorithms
 Decision parameter:
2 2 2 2 2 2
( , )ellipse y x x yf x y r x r y r r  
1
Slope = -1
rx
ry 2
0 if ( , ) is inside the ellipse
( , ) 0 if ( , ) is on the ellipse
0 if ( , ) is outside the ellipse
ellipse
x y
f x y x y
x y


 

2
2
2
2
y
x
r xdy
Slope
dx r y
  
38
Ellipse Algorithms
 Starting at (0, ry) we take unit steps in the x direction
until we reach the boundary between region 1 and
region 2. Then we take unit steps in the y direction
over the remainder of the curve in the first quadrant.
 At the boundary
 therefore, we move out of region 1 whenever
1
Slope = -1
rx
ry 2
2 2
1 2 2y x
dy
r x r y
dx
   
2 2
2 2y xr x r y
39
Midpoint Ellipse Algorithm
yi 
yi-1
xi xi+1 xi+2
Midpoint
Assuming that we have just plotted the pixels at (xi , yi).
The next position is determined by:
1
2
2 2 2 2 2 21
2
1 ( 1, )
( 1) ( )
i ellipse i i
y i x i x y
p f x y
r x r y r r
  
    
If p1i < 0 the midpoint is inside the ellipse  yi is closer
If p1i ≥ 0 the midpoint is outside the ellipse  yi – 1 is closer
40
Decision Parameter (Region 1)
At the next position [xi+1 + 1 = xi + 2]
OR
where yi+1 = yi
or yi+1 = yi – 1
1
1 1 1 2
2 2 2 2 2 21
1 2
1 ( 1, )
( 2) ( )
i ellipse i i
y i x i x y
p f x y
r x r y r r
  

  
    
2 2 2 2 2 21 1
1 1 2 21 1 2 ( 1) ( ) ( )i i y i y x i ip p r x r r y y 
         
41
Decision Parameter (Region 1)
Decision parameters are incremented by:
Use only addition and subtraction by obtaining
At initial position (0, ry)
2 2
1
2 2 2
1 1
2 if 1 0
2 2 if 1 0
y i y i
y i y x i i
r x r p
increment
r x r r y p

 
  
 
  
2 2
2 and 2y xr x r y
2
2 2
2 2 2 2 21 1
0 2 2
2 2 21
4
2 0
2 2
1 (1, ) ( )
y
x x y
ellipse y y x y x y
y x y x
r x
r y r r
p f r r r r r r
r r r r


     
  
42
Region 2
Over region 2, step in the negative y direction and midpoint is
taken between horizontal pixels at each step.
yi 
yi-1
xi xi+1 xi+2
Midpoint
Decision parameter:
1
2
2 2 2 2 2 21
2
2 ( , 1)
( ) ( 1)
i ellipse i i
y i x i x y
p f x y
r x r y r r
  
    
If p2i > 0 the midpoint is outside the ellipse  xi is closer
If p2i ≤ 0 the midpoint is inside the ellipse  xi + 1 is closer
43
Decision Parameter (Region 2)
At the next position [yi+1 – 1 = yi – 2]
OR
where xi+1 = xi
or xi+1 = xi + 1
1
1 1 12
2 2 2 2 2 21
1 2
2 ( , 1)
( ) ( 2)
i ellipse i i
y i x i x y
p f x y
r x r y r r
  

  
    
2 2 2 2 21 1
1 1 2 22 2 2 ( 1) ( ) ( )i i x i x y i ip p r y r r x x 
         
44
Decision Parameter (Region 2)
Decision parameters are incremented by:
At initial position (x0, y0) is taken at the last
position selected in region 1
2 2
1
2 2 2
1 1
2 if 2 0
2 2 if 2 0
x i x i
y i x i x i
r y r p
increment
r x r y r p

 
  
 
  
1
0 0 02
2 2 2 2 2 21
0 02
2 ( , 1)
( ) ( 1)
ellipse
y x x y
p f x y
r x r y r r
  
    
45
Midpoint Ellipse Algorithm
1. Input rx, ry, and 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 parameter in region 1 as
3. At each xi position, starting at i = 0, if p1i < 0, the next
point along the ellipse centered on (0, 0) is (xi + 1, yi)
and
otherwise, the next point is (xi + 1, yi – 1) and
and continue until
2 2 21
0 41 y x y xp r r r r  
2 2
1 11 1 2i i y i yp p r x r   
2 2 2
1 1 11 1 2 2i i y i x i yp p r x r y r     
2 2
2 2y xr x r y
46
Midpoint Ellipse Algorithm
4. (x0, y0) is the last position calculated in region 1. Calculate
the initial parameter in region 2 as
5. At each yi position, starting at i = 0, if p2i > 0, the next point
along the ellipse centered on (0, 0) is (xi, yi – 1) and
otherwise, the next point is (xi + 1, yi – 1) and
Use the same incremental calculations as in region 1.
Continue until y = 0.
6. For both regions determine 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 coordinate values
x = x + xc , y = y + yc
2 2 2 2 2 21
0 0 022 ( ) ( 1)y x x yp r x r y r r    
2 2
1 12 2 2i i x i xp p r y r   
2 2 2
1 1 12 2 2 2i i y i x i xp p r x r y r     
47
Example
i pi xi+1, yi+1 2ry
2xi+1 2rx
2yi+1
0 -332 (1, 6) 72 768
1 -224 (2, 6) 144 768
2 -44 (3, 6) 216 768
3 208 (4, 5) 288 640
4 -108 (5, 5) 360 640
5 288 (6, 4) 432 512
6 244 (7, 3) 504 384
rx = 8 , ry = 6
2ry
2x = 0 (with increment 2ry
2 = 72)
2rx
2y = 2rx
2ry (with increment -2rx
2 = -128)
Region 1
(x0, y0) = (0, 6)
2 2 21
0 41 332y x y xp r r r r    
Move out of region 1 since
2ry
2x > 2rx
2y
48
Example
6    
5  
4 
3 
2 
1 
0 
0 1 2 3 4 5 6 7 8
i pi xi+1, yi+1 2ry
2xi+1 2rx
2yi+1
0 -151 (8, 2) 576 256
1 233 (8, 1) 576 128
2 745 (8, 0) - -
Region 2
(x0, y0) = (7, 3) (Last position in region 1)
1
0 22 (7 ,2) 151ellipsep f   
Stop at y = 0
49
Midpoint Ellipse Function
void ellipse(int Rx, int Ry)
{
int Rx2 = Rx * Rx, Ry2 = Ry * Ry;
int twoRx2 = 2 * Rx2, twoRy2 = Ry2 * Ry2;
int p, x = 0, y = Ry;
int px = 0, py = twoRx2 * y;
ellisePlotPoints(xcenter, ycenter, x, y);
// Region 1
p = round(Ry2 – (Rx2 * Ry) + (0.25 * Rx2));
while (px < py) {
x++;
px += twoRy2;
if (p < 0) p += Ry2 + px;
else {
y--;
py -= twoRx2;
p += Ry2 + px – py;
}
ellisePlotPoints(xcenter, ycenter, x, y);
}
// Region 2
p = round(Ry2 * (x+0.5) * (x+0.5) + Rx2 * (y-1)*(y-1) – Rx2 * Ry2;
while (y > 0) {
y--;
py -= twoRx2;
if (p > 0) p += Rx2 – py;
else {
x++;
px += twoRy2;
p += Rx2 – py + px;
}
ellisePlotPoints(xcenter, ycenter, x, y);
}
}
Thank You

Contenu connexe

Tendances

Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics University of Potsdam
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Part 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptxPart 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptxKhalil Alhatab
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clippingMdAlAmin187
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphicsSafayet Hossain
 
2.2. interactive computer graphics
2.2. interactive computer graphics2.2. interactive computer graphics
2.2. interactive computer graphicsRatnadeepsinh Jadeja
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithmnehrurevathy
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithmPooja Dixit
 

Tendances (20)

Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
3d transformation computer graphics
3d transformation computer graphics 3d transformation computer graphics
3d transformation computer graphics
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 lecture2  computer graphics graphics hardware(Computer graphics tutorials) lecture2  computer graphics graphics hardware(Computer graphics tutorials)
lecture2 computer graphics graphics hardware(Computer graphics tutorials)
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
Part 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptxPart 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptx
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
2.2. interactive computer graphics
2.2. interactive computer graphics2.2. interactive computer graphics
2.2. interactive computer graphics
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Bresenham's line algorithm
Bresenham's line algorithmBresenham's line algorithm
Bresenham's line algorithm
 

Similaire à Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle algorithm

Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.Mohd Arif
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationMuhammad Fiaz
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
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_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptAliZaib71
 
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
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
48 circle part 1 of 2
48 circle part 1 of 248 circle part 1 of 2
48 circle part 1 of 2tutulk
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 

Similaire à Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle algorithm (20)

Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Bresenham's line algo.
Bresenham's line algo.Bresenham's line algo.
Bresenham's line algo.
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
2.circle
2.circle2.circle
2.circle
 
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
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
 
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
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
module 1.pdf
module 1.pdfmodule 1.pdf
module 1.pdf
 
Unit 3
Unit 3Unit 3
Unit 3
 
Maths 301 key_sem_1_2007_2008
Maths 301 key_sem_1_2007_2008Maths 301 key_sem_1_2007_2008
Maths 301 key_sem_1_2007_2008
 
48 circle part 1 of 2
48 circle part 1 of 248 circle part 1 of 2
48 circle part 1 of 2
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 

Dernier

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Computer Graphics - Bresenham's line drawing algorithm & Mid Point Circle algorithm

  • 1. Bresenham's line drawing algorithm & Mid Point Circle algorithm Computer Graphics
  • 2. Team Members Group-I Assignment Topic : BRESENHARAM'S ALGORITHM (ELIPSE Drawing) Group's representative: TANGUTURU SAI KRISHNA S.No. BITS ID NAME Official Email ID Personal Email ID 1 2011HW69898 TANGUTURU SAI KRISHNA saikrishna.tanguturu@wipro.com sai.tsk2008@gmail.com 2 2011HW69900 RAYAPU MOSES rayapu.moses@wipro.com stalinkvd001@gmail.com 3 2011HW69932 SHENBAGAMOORTHY A shenbagamoorthy.a83@wipro.com moorthy2626@gmail.com 4 2011HW69913 ANURUPA K C anurupa.c85@wipro.com anu.rupa30@gmail.com 5 2011HW69909 ARUNJUNAISELVAM P arunjunaiselvam.p95@wipro.com arunjunai.carrer@gmail.com 6 2011HW69569 PRANOB JYOTI KALITA pranob.kalita@wipro.com pranob.kalita90@gmail.com 7 2011HW69893 TINNALURI V N PRASANTH prasanth.tinnaluri@wipro.com naga.prasanth985@gmail.com 8 2011HW69904 KONDALA SUMATHI sumathi.kondala@wipro.com sumathi.kondala@gmail.com 9 2011HW69896 DASIKA KRISHNA dasika.krishna@wipro.com dasikakrishnas@gmail.com
  • 3. Lines 3 Analog devises, such as a random-scan display or a vector plotter, display a straight line smoothly from one endpoint to another. Linearly varying horizontal and vertical deflection voltages are generated that are proportional to the required changes in the x and y directions to produce the smooth line.
  • 4. Digital devices display a straight line by plotting discrete coordinate points along the line path which are calculated from the equation of the line. Screen locations are referenced with integer values, so plotted positions may only approximate actual line positions between two specific endpoints. A computed line position of (10.48, 20.51) will be converted to pixel position (10, 21). This rounding of coordinate values to integers causes lines to be displayed with a stairstep appearance (the “jaggies”). Particularly noticeable on systems with low resolution. To smooth raster lines, pixel intensities along the line paths must be adjusted. 4
  • 5. Line Drawing Algorithms Cartesian equation: y = mx + c where m – slope c – y-intercept x y xx yy m       12 12 5 x1 y1 x2 y2
  • 6. Slope 6 if |m| = 1  = 45° 45° 45° +ve -ve ° ° ° ° if |m|  1 -45° <  < 45° if |m|  1 45° <  < 90° or -90° <  < -45°
  • 7. x y 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 7 8  7  6  5  4  3  2  1  0  0 1 2 3 4 5 6 7 8 y = x m = 1 c = 0 y x |m| = 1
  • 8. x y round(y) 0 1 1 1 1.5 2 2 2 2 3 2.5 3 4 3 3 5 3.5 4 6 4 4 7 4.5 58 8 7 6 5   4   3   2   1  0 0 1 2 3 4 5 6 7 8 y = ½ x + 1 m = ½ c = 1 y x |m|  1
  • 9. 9 |m|  1 8 7  6 5 4  3 2 1  0 0 1 2 3 4 5 6 7 8 y = 3x - 2 m = 3 c = -2 y x x y round(y) 0 -2 -2 1 1 1 2 4 4 3 7 7 4 10 10 5 13 13 6 16 16 7 19 19 outside
  • 10. Bresenham Line Algorithm A more efficient approach Basis of the algorithm: From start position decide A or B next A B 10 Start position
  • 11. Bresenham Line Algorithm 11 For a given value of x one pixel lies at distance ti above the line, and one pixel lies at distance si below the line True line si ti
  • 12. Bresenham Line Algorithm 12 Decision parameter di = (si - ti) If di  0, then closest pixel is below true line (si smaller) If di  0, then closest pixel is above true line (ti smaller) We must calculate the new values for di as we move along the line.
  • 13. Example: 13 )2or5.0(i.e.0.5(slope)gradientLet dxdy dx dy  3dy 2dy dy Start pixel at (x0,y1) 4dy At x1 : s1 = dy t1 = dx - dy d1 = (si - ti) = dy - (dx - dy) = 2dy - dx but 2dy  dx  di  0  y stays the same hence next pixel is at (x1,y1) At x2 : s2 = 2dy t2 = dx - 2dy d2 = (s2 – t2) = 2dy - (dx - 2dy) = 4dy - dx Suppose d2  0  y is incremented hence next pixel is at (x2,y2) At x3 : s3 = 3dy - dx t2 = 2dx - 3dy d3 = (s2 – t3) = 6dy - 3dx  0 so y stays the same hence next pixel is at (x3,y2) x1 x2 x3 x4 x5 x0 y0 y1 y2 y3 y5
  • 14. In General 14 For a line with gradient ≤ 1 d0 = 2dy – dx if di  0 then yi+1 = yi di+1 = di + 2dy if di ≥ 0 then yi+1 = yi + 1 di+1 = di + 2(dy – dx) xi+1 = xi + 1 For a line with gradient  1 d0 = 2dx – dy if di  0 then xi+1 = xi di+1 = di + 2dx if di ≥ 0 then xi+1 = xi + 1 di+1 = di + 2(dx – dy) yi+1 = yi + 1 Note: For |m| ≤ 1 the constants 2dy and 2(dy-dx) can be calculated once, so the arithmetic will involve only integer addition and subtraction.
  • 15. Example – Draw a line from (20,10) to (30,18) 19 18 17 16 15 14 13 12 15 (20,10) (30,18) dx = 10 dy = 8 initial decision d0 = 2dy – dx = 6 Also 2dy = 16, 2(dy – dx) = -4 i di (xi+1,yi+1) 0 6 (21,11) 1 2 (22,12) 2 -2 (23,12) 3 14 (24,13) 4 10 (25,14) 5 6 (26,15) 6 2 (27,16) 7 -2 (28,16) 8 14 (29,17) 9 10 (30,18)
  • 16. 16 void LineBres(int x0, int y0, int x1, int y1) // line for |m| < 1 { int dx = abs(x1 – x0), dy = abs(y1 – y0); int d = 2 * dy – dx, twoDy = 2 * dy, twoDyMinusDx = 2 * (dy – dx); int x, y; if (x0 > x1) { // determines which point to use as start, which as end x = x1; y = y1; x1 = x0; } else { x = x0; y = y0; } setPixel(x,y); while (x < x1) { x++; if (d < 0) d += twoDy; else { y++; d += twoDyMinusDx; } setPixel(x, y); } }
  • 17. Special cases 17  Special cases can be handled separately  Horizontal lines (y = 0)  Vertical lines (x = 0)  Diagonal lines (|x| = |y|)  directly into the frame-buffer without processing them through the line-plotting algorithms.
  • 18. Circle Equations 18  Polar form x = rCos y = rSin (r = radius of circle)  P=(rCos, rSin) rSin) rCos) x y r
  • 19. Drawing a circle 19 Disadvantages  To find a complete circle  varies from 0° to 360°  The calculation of trigonometric functions is very slow.  = 0° while ( < 360°) x = rCos y = rSin setPixel(x,y)  =  + 1° end while
  • 20. Cartesian form  Use Pythagoras theorem x2 + y2 = r2 20 x r y y x x y r  2 2 ,P x r x 
  • 21. Circle algorithms 21  Step through x-axis to determine y-values  Disadvantages: – Not all pixel filled in – Square root function is very slow
  • 22. Circle Algorithms 22  Use 8-fold symmetry and only compute pixel positions for the 45° sector. 45° (x, y) (y, x) (-x, y) (y, -x) (x, -y)(-x, -y) (-y, x) (-y, -x)
  • 23. Bresenham’s Circle Algorithm General Principle  The circle function:  and 2 2 2 ( , )circlef x y x y r   23 Consider only 45° ≤  ≤ 90° if (x,y) is inside the circle boundary if (x,y) is on the circle boundary if (x,y) is outside the circle boundary 0 ( , ) 0 0 circlef x y     
  • 24. Bresenham’s Circle Algorithm 24 p1 p3 p2 D(si) D(ti) After point p1, do we choose p2 or p3? yi yi - 1 xi xi + 1 r
  • 25. Bresenham’s Circle Algorithm 25 Define: D(si) = distance of p3 from circle D(ti) = distance of p2 from circle i.e. D(si) = (xi + 1)2 + yi 2 – r2 [always +ve] D(ti) = (xi + 1)2 + (yi – 1)2 – r2 [always -ve]  Decision Parameter pi = D(si) + D(ti) so if pi < 0 then the circle is closer to p3 (point above) if pi ≥ 0 then the circle is closer to p2 (point below)
  • 26. The Algorithm 26 x0 = 0 y0 = r p0 = [12 + r2 – r2] + [12 + (r-1)2 – r2] = 3 – 2r if pi < 0 then yi+1 = yi pi+1 = pi + 4xi + 6 else if pi ≥ 0 then yi+1 = yi – 1 pi+1 = pi + 4(xi – yi) + 10  Stop when xi ≥ yi and determine symmetry points in the other octants xi+1 = xi + 1
  • 27. Example 10     9   8  7  6  5  4  3  2  1  0  0 1 2 3 4 5 6 7 8 9 10 27 i pi xi, yi 0 -17 (0, 10) 1 -11 (1, 10) 2 -1 (2, 10) 3 13 (3, 10) 4 -5 (4, 9) r = 10 p0 = 3 – 2r = -17 Initial point (x0, y0) = (0, 10)
  • 28. Midpoint Circle Algorithm yi  yi-1 xi xi+1 xi+2 28 Midpoint x2 + y2 – r2 = 0 Assuming that we have just plotted the pixels at (xi , yi). Which is next? (xi+1, yi) OR (xi+1, yi – 1). - The one that is closer to the circle.
  • 29. Midpoint Circle Algorithm  The decision parameter is the circle at the midpoint between the pixels yi and yi – 1.  If pi < 0, the midpoint is inside the circle and the pixel yi is closer to the circle boundary.  If pi ≥ 0, the midpoint is outside the circle and the pixel yi - 1 is closer to the circle boundary. 1 2 2 2 21 2 ( 1, ) ( 1) ( ) i circle i i i i p f x y x y r         29
  • 30. Decision Parameters  Decision Parameters are obtained using incremental calculations OR where yi+1 is either yi or yi-1 depending on the sign of pi 1 1 1 1 2 2 2 21 1 2 ( 1, ) ( 2) ( ) i circle i i i i p f x y x y r             2 2 2 1 1 12( 1) ( ) ( ) 1i i i i i i ip p x y y y y          30 Note: xi+1 = xi +1
  • 31. The Algorithm1. Initial values:- point(0,r) x0 = 0 y0 = r 2. Initial decision parameter 3. At each xi position, starting at i = 0, perform the following test: if pi < 0, the next point is (xi + 1, yi) and pi+1 = pi + 2xi+1 + 1 If pi ≥ 0, the next point is (xi+1, yi-1) and pi+1 = pi + 2xi+1 + 1 – 2yi+1 where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 2 4. Determine symmetry points in the other octants 5. Move pixel positions (x,y) onto the circular path centered on (xc, yc) and plot the coordinates: x = x + xc, y = y + yc 6. Repeat 3 – 5 until x ≥ y 2 2 51 1 0 2 2 4(1, ) 1 ( )circlep f r r r r        31 move circle origin at (0,0) by x = x – xc and y = y – yc
  • 32. Example 10     9   8  7  6  5  4  3  2  1  0  0 1 2 3 4 5 6 7 8 9 10 32 i pi xi+1, yi+1 2xi+ 1 2yi+ 1 0 -9 (1, 10) 2 20 1 -6 (2, 10) 4 20 2 -1 (3, 10) 6 20 3 6 (4, 9) 8 18 4 -3 (5, 9) 10 18 5 8 (6, 8) 12 16 6 5 (7, 7) r = 10 p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer) Initial point (x0, y0) = (0, 10)
  • 33. 33 Midpoint function void plotpoints(int x, int y) { setpixel(xcenter+x, ycenter+y); setpixel(xcenter-x, ycenter+y); setpixel(xcenter+x, ycenter-y); setpixel(xcenter-x, ycenter-y); setpixel(xcenter+y, ycenter+x); setpixel(xcenter-y, ycenter+x); setpixel(xcenter+y, ycenter-x); setpixel(xcenter-y, ycenter-x); } void circle(int r) { int x = 0, y = r; plotpoints(x,y); int p = 1 – r; while (x<y) { x++; if (p<0) p += 2*x + 1; else { y--; p += 2*(x-y) + 1; } plotpoints(x,y); } }
  • 34. 34 Ellipse-Generating Algorithms  Ellipse – A modified circle whose radius varies from a maximum value in one direction (major axis) to a minimum value in the perpendicular direction (minor axis). P=(x,y)F1 F2 d1 d2  The sum of the two distances d1 and d2, between the fixed positions F1 and F2 (called the foci of the ellipse) to any point P on the ellipse, is the same value, i.e. d1 + d2 = constant
  • 35. 35 Ellipse Properties  Expressing distances d1 and d2 in terms of the focal coordinates F1 = (x1, x2) and F2 = (x2, y2), we have:  Cartesian coordinates:  Polar coordinates: 2 2 2 2 1 1 2 2( ) ( ) ( ) ( ) constantx x y y x x y y        ry rx 22 1c c x y x x y y r r               cos sin c x c y x x r y y r      
  • 36. 36 Ellipse Algorithms  Symmetry between quadrants  Not symmetric between the two octants of a quadrant  Thus, we must calculate pixel positions along the elliptical arc through one quadrant and then we obtain positions in the remaining 3 quadrants by symmetry (x, y)(-x, y) (x, -y)(-x, -y) rx ry
  • 37. 37 Ellipse Algorithms  Decision parameter: 2 2 2 2 2 2 ( , )ellipse y x x yf x y r x r y r r   1 Slope = -1 rx ry 2 0 if ( , ) is inside the ellipse ( , ) 0 if ( , ) is on the ellipse 0 if ( , ) is outside the ellipse ellipse x y f x y x y x y      2 2 2 2 y x r xdy Slope dx r y   
  • 38. 38 Ellipse Algorithms  Starting at (0, ry) we take unit steps in the x direction until we reach the boundary between region 1 and region 2. Then we take unit steps in the y direction over the remainder of the curve in the first quadrant.  At the boundary  therefore, we move out of region 1 whenever 1 Slope = -1 rx ry 2 2 2 1 2 2y x dy r x r y dx     2 2 2 2y xr x r y
  • 39. 39 Midpoint Ellipse Algorithm yi  yi-1 xi xi+1 xi+2 Midpoint Assuming that we have just plotted the pixels at (xi , yi). The next position is determined by: 1 2 2 2 2 2 2 21 2 1 ( 1, ) ( 1) ( ) i ellipse i i y i x i x y p f x y r x r y r r         If p1i < 0 the midpoint is inside the ellipse  yi is closer If p1i ≥ 0 the midpoint is outside the ellipse  yi – 1 is closer
  • 40. 40 Decision Parameter (Region 1) At the next position [xi+1 + 1 = xi + 2] OR where yi+1 = yi or yi+1 = yi – 1 1 1 1 1 2 2 2 2 2 2 21 1 2 1 ( 1, ) ( 2) ( ) i ellipse i i y i x i x y p f x y r x r y r r             2 2 2 2 2 21 1 1 1 2 21 1 2 ( 1) ( ) ( )i i y i y x i ip p r x r r y y           
  • 41. 41 Decision Parameter (Region 1) Decision parameters are incremented by: Use only addition and subtraction by obtaining At initial position (0, ry) 2 2 1 2 2 2 1 1 2 if 1 0 2 2 if 1 0 y i y i y i y x i i r x r p increment r x r r y p            2 2 2 and 2y xr x r y 2 2 2 2 2 2 2 21 1 0 2 2 2 2 21 4 2 0 2 2 1 (1, ) ( ) y x x y ellipse y y x y x y y x y x r x r y r r p f r r r r r r r r r r           
  • 42. 42 Region 2 Over region 2, step in the negative y direction and midpoint is taken between horizontal pixels at each step. yi  yi-1 xi xi+1 xi+2 Midpoint Decision parameter: 1 2 2 2 2 2 2 21 2 2 ( , 1) ( ) ( 1) i ellipse i i y i x i x y p f x y r x r y r r         If p2i > 0 the midpoint is outside the ellipse  xi is closer If p2i ≤ 0 the midpoint is inside the ellipse  xi + 1 is closer
  • 43. 43 Decision Parameter (Region 2) At the next position [yi+1 – 1 = yi – 2] OR where xi+1 = xi or xi+1 = xi + 1 1 1 1 12 2 2 2 2 2 21 1 2 2 ( , 1) ( ) ( 2) i ellipse i i y i x i x y p f x y r x r y r r             2 2 2 2 21 1 1 1 2 22 2 2 ( 1) ( ) ( )i i x i x y i ip p r y r r x x           
  • 44. 44 Decision Parameter (Region 2) Decision parameters are incremented by: At initial position (x0, y0) is taken at the last position selected in region 1 2 2 1 2 2 2 1 1 2 if 2 0 2 2 if 2 0 x i x i y i x i x i r y r p increment r x r y r p            1 0 0 02 2 2 2 2 2 21 0 02 2 ( , 1) ( ) ( 1) ellipse y x x y p f x y r x r y r r        
  • 45. 45 Midpoint Ellipse Algorithm 1. Input rx, ry, and 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 parameter in region 1 as 3. At each xi position, starting at i = 0, if p1i < 0, the next point along the ellipse centered on (0, 0) is (xi + 1, yi) and otherwise, the next point is (xi + 1, yi – 1) and and continue until 2 2 21 0 41 y x y xp r r r r   2 2 1 11 1 2i i y i yp p r x r    2 2 2 1 1 11 1 2 2i i y i x i yp p r x r y r      2 2 2 2y xr x r y
  • 46. 46 Midpoint Ellipse Algorithm 4. (x0, y0) is the last position calculated in region 1. Calculate the initial parameter in region 2 as 5. At each yi position, starting at i = 0, if p2i > 0, the next point along the ellipse centered on (0, 0) is (xi, yi – 1) and otherwise, the next point is (xi + 1, yi – 1) and Use the same incremental calculations as in region 1. Continue until y = 0. 6. For both regions determine 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 coordinate values x = x + xc , y = y + yc 2 2 2 2 2 21 0 0 022 ( ) ( 1)y x x yp r x r y r r     2 2 1 12 2 2i i x i xp p r y r    2 2 2 1 1 12 2 2 2i i y i x i xp p r x r y r     
  • 47. 47 Example i pi xi+1, yi+1 2ry 2xi+1 2rx 2yi+1 0 -332 (1, 6) 72 768 1 -224 (2, 6) 144 768 2 -44 (3, 6) 216 768 3 208 (4, 5) 288 640 4 -108 (5, 5) 360 640 5 288 (6, 4) 432 512 6 244 (7, 3) 504 384 rx = 8 , ry = 6 2ry 2x = 0 (with increment 2ry 2 = 72) 2rx 2y = 2rx 2ry (with increment -2rx 2 = -128) Region 1 (x0, y0) = (0, 6) 2 2 21 0 41 332y x y xp r r r r     Move out of region 1 since 2ry 2x > 2rx 2y
  • 48. 48 Example 6     5   4  3  2  1  0  0 1 2 3 4 5 6 7 8 i pi xi+1, yi+1 2ry 2xi+1 2rx 2yi+1 0 -151 (8, 2) 576 256 1 233 (8, 1) 576 128 2 745 (8, 0) - - Region 2 (x0, y0) = (7, 3) (Last position in region 1) 1 0 22 (7 ,2) 151ellipsep f    Stop at y = 0
  • 49. 49 Midpoint Ellipse Function void ellipse(int Rx, int Ry) { int Rx2 = Rx * Rx, Ry2 = Ry * Ry; int twoRx2 = 2 * Rx2, twoRy2 = Ry2 * Ry2; int p, x = 0, y = Ry; int px = 0, py = twoRx2 * y; ellisePlotPoints(xcenter, ycenter, x, y); // Region 1 p = round(Ry2 – (Rx2 * Ry) + (0.25 * Rx2)); while (px < py) { x++; px += twoRy2; if (p < 0) p += Ry2 + px; else { y--; py -= twoRx2; p += Ry2 + px – py; } ellisePlotPoints(xcenter, ycenter, x, y); } // Region 2 p = round(Ry2 * (x+0.5) * (x+0.5) + Rx2 * (y-1)*(y-1) – Rx2 * Ry2; while (y > 0) { y--; py -= twoRx2; if (p > 0) p += Rx2 – py; else { x++; px += twoRy2; p += Rx2 – py + px; } ellisePlotPoints(xcenter, ycenter, x, y); } }