Download - Line Circle Algorithm
-
8/8/2019 Line Circle Algorithm
1/33
Scan converting lines
circles and ellipses
-
8/8/2019 Line Circle Algorithm
2/33
-
8/8/2019 Line Circle Algorithm
3/33
Line drawing
Description: Given the specification of the straightline, find the collection of the addressable pixels
which more closely approximates this line
Goal: (Not all of them are acheivable with the discrete
space of a raster device) .Straight line should appear straight.
Lines should start and end accurately.
Lines should have constant brightness.
Lines should be drawn as rapidly as possible.
-
8/8/2019 Line Circle Algorithm
4/33
ProblemsHow do we determine which pixel to illuminate to
satisfy the above goals?
Vertical, horizontal and lines with slope with +/- 1 are
easy to draw.
Others create problems: Stair casing/ jaggies/aliasing
Quality of the line depends on the location of the
pixels and their brightness.
-
8/8/2019 Line Circle Algorithm
5/33
-
8/8/2019 Line Circle Algorithm
6/33
Direct solution
Solve y=mx+b, where (0,b) is the y-intercept and m is
the slope.
Go from X0 to X1Calculate round(y) from the equation.
Take an example, b=1 [starting point is (0,1)] and
m=3/5.Then X=1, Y=2= ROUND (8/5)
X=2, Y=2= ROUND (11/5)
X=3, Y=3= ROUND (14/5)
X=4, Y=3= ROUND (17/5)
X=5, Y=4= ROUND (20/5)
-
8/8/2019 Line Circle Algorithm
7/33
-
8/8/2019 Line Circle Algorithm
8/33
-
8/8/2019 Line Circle Algorithm
9/33
-
8/8/2019 Line Circle Algorithm
10/33
Bresenharms line drawing
algorithm (Midpoint line algorithm)
Mathematical description:
True line
B
A
A = the distance of pixels
which are lying above
the true lineB = the distance of pixels
which are lying below
the true line
-
8/8/2019 Line Circle Algorithm
11/33
-
8/8/2019 Line Circle Algorithm
12/33
-
8/8/2019 Line Circle Algorithm
13/33
-
8/8/2019 Line Circle Algorithm
14/33
Let us define the decision variable as
di = B A
If di < 0 then it implies that B > A
i:epixel below the true line is closer to the
expected line. If di is greater than or equal
to zero then the pixel above the true line iscloset. Hence, if di 0 increment
both the values of x and y.
-
8/8/2019 Line Circle Algorithm
15/33
Algorithm
1. Input the two line end points and store the left endpoint in(x0,y0).
2. Load (x0,y0), into the frame buffer, that is, plot the firstpoint.
3. Calculate constants x, y, 2y, and 2y - 2x, and obtainthe starting value for the decision parameter as
d0 = 2y x.
4. At each xk along the line, starting at k=0, perform the
following test:if dk
-
8/8/2019 Line Circle Algorithm
16/33
11 12 13 14 15 16 17
9
10
11
12
13
14
15
16
6 7 8 9 10
k dk (x ,y)
0
1
2
.
.
So do it..
Problem: Construct a line with
endpoints (6,9) and (17,15).
-
8/8/2019 Line Circle Algorithm
17/33
Note: This method is well suited for the line having the
slope less than 45. When the magnitude of the slope is lesser than 1, xincremented by one, and the decision variable ismade use to find the incremental value of y.
When the slope is greater than 1, y is incrementedby one and x is incremented based on decisionvariable.
Line is constructed from left to right. For the rightto left appropriate directions need to be reversed.
-
8/8/2019 Line Circle Algorithm
18/33
-
8/8/2019 Line Circle Algorithm
19/33
DDA line algorithm : Disadvantages
Key disadvantage:
it relies on floating point operations to computepixel positions.
Implications:
Computationally inefficient because floating-
point operations are slow. Round-off errors accumulate, producing incorrect
line drawings (e.g., if m is rounded to 0.9 eventhough it is equal to 0.99, lines of length > 10 will
be drawn inaccurately)
-
8/8/2019 Line Circle Algorithm
20/33
Circle algorithmStarting with the equation of the circle
We could use this equation to calculate the position of points on
a circle by stepping along the x axis in unit steps from x0-r to
x0+r and calculating the corresponding y values at each
position as :
-
8/8/2019 Line Circle Algorithm
21/33
This works, but is inefficient coz it involves
multiplication and square root operations. Italso creates large gaps in the circle for values
of x values close to r.
-
8/8/2019 Line Circle Algorithm
22/33
Exploiting Symmetry Circle can be drawn by
two ways namely :
polynomial method and
trigonometric method.
Take advantage of
symmetries to minimize
cases (slopes) and amount
of curve drawn. We cangenerate all pixel positions
around a circle by
calculating only the points
within the sector from x=0
to x=y
(x, y)
(y, x)(y, -x)
(-x, y)
(-x, -y)
(-y, -x) (-y, x)
(x, -y)
-
8/8/2019 Line Circle Algorithm
23/33
-
8/8/2019 Line Circle Algorithm
24/33
Bresenhams circle drawing algorithm
1. read the radius of the circle say r
2. d=3-2r (initial decision variable)
x=0, y=r
3. plot the initial four points (x,y),(x,-y), (y,x)and(-y,-x)
4. if (dy stop or else goto step 4 until thecondition is satisfied.
-
8/8/2019 Line Circle Algorithm
25/33
Draw a circle whose radius is 8 units
and centre is (0,0)
Step1:
Set (h,k) = (0,0)
x=0 and y= 8
d= 3-2r = -13 Step 2:
check , if x>y then stop0>8, which is false.
-
8/8/2019 Line Circle Algorithm
26/33
Step 3: plot the 8 points,
(x+h, y+k)= (0,8)
(y+h, x+k)=(8,0)
(-y+h, x+k)=(-8,0)(-x +h, y+k)=(0,8)
(-x +h, -y+k)=(0,-8)(-y +h, -x+k)=(-8,0)
(y +h, -x+k)=(8,0)
(x +h, -y+k)=(0,-8)
-
8/8/2019 Line Circle Algorithm
27/33
Step 4: d= -13
since d8, answer will be no
Again plotting 8 points while taking x=1
x=1, h=0 , k=0, y=8
Points to be plotted are as follows(1,8), (8,1), (-8,1), (-1,8), (-1,-8), (-8,-1), (8,-1), (1,-8)
-
8/8/2019 Line Circle Algorithm
28/33
Now checking decision parameter,
Since d8Again plot 8 points taking x=2, y=8, h=0,k=0
(2,8), (8,2), (-8,2), (-2,8), (-2,-8),(-8,-2), (8,-2), (2,-8)
-
8/8/2019 Line Circle Algorithm
29/33
Now d 0 3 0
d=d+4(x-y)+10=3+4(2-8)+10
= -11
x= x+1
= 2+1 = 3
y = y-1= 8-1= 7Now x>y No.
Again plotting 8 points x=3, y=7, h=0, k=0
(3,7), (7,3), (-7,3), (-3,7), (-3,-7), (-7,-3), (7,-3), (3,-7)
-
8/8/2019 Line Circle Algorithm
30/33
d= -11y which is false
So again computing 8 points with x=4(4,7), (7,4), (-7,4), (-4,7), (-4,-7), (-7,-4), (7,-4),
(4,-7)
-
8/8/2019 Line Circle Algorithm
31/33
now d 0 i:e 7 >0
d= d+4(x-y)+10
= 7+4(4-8)+10 = 1
x= x+1 = 4+1 = 5y=y-1 =7-1 = 6
Check if x>y which is falseSo again computing 8 points with x=5,y=6
(5,6), (6,5), (-6,5), (-5,6), (-5,-6), (-6,-5), (6,-5),
(5,-6)
-
8/8/2019 Line Circle Algorithm
32/33
now d 0 i:e d=1
d= d+4(x-y)+10= 1+4(5-6)+10 = 7
x= x+1 = 5+1 = 6
y=y-1 =6-1 = 5
Checking the condition if x>y i:e 6>5
hence we stopSo again computing 8 points with x=5,y=6
(5,6), (6,5), (-6,5), (-5,6), (-5,-6), (-6,-5), (6,-5),(5,-6)
-
8/8/2019 Line Circle Algorithm
33/33
-10
-8
-6
-4
-2
0
2
4
6
8
10
-10 -5 0 5 10Series1