chapter2 2 - aditipaulsite.files.wordpress.com · chapter2 2 scan conversion the screen of a...

24
2 Chapter2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns is known as a pixel. Scan conversion is the process of creating a pattern of points identical to the objects to be displayed. Each pixel on the display surface has a finite size depending on the screen resolution and hence a pixel cannot represent a single point. However, we consider each pixel as unit square area identified by the coordinate with respect to lower (or upper) left corner. Scan-converting a point A mathematical point (x,y) where x and y are real numbers within an image area, needs to be scan converted to a pixel at location (x / ,y / ). This may be done by making x / to be the integer part of x and y / the integer part of y. In other words, x / =Floor(x) and y / =floor(y), where function Floor returns the largest integer that is less than or equal to the argument. All points that satisfy x / x<x / +1 and y / y<y+1 are mapped to a pixel (x / ,y / ). For example, point P 1 (1.7,0.8) is represented by pixel (1,0). Points P 2 (2.2, 1.3) and P 3 (2.8,1.9) are both represented by pixel (2,1). In another approach we can convert (x,y) by making x / =Floor(x+.5) and y / =Floor(y+.5). All points that satisfy x / -0.5x<x / +0.5 and y / - 0.5y<y / +0.5 are mapped to pixel (x / ,y / ). This means that points P 1 and P2 are now both

Upload: others

Post on 18-Oct-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

2 Chapter2

Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns is known as a pixel. Scan conversion is the process of creating a pattern of points identical to the objects to be displayed. Each pixel on the display surface has a finite size depending on the screen resolution and hence a pixel cannot represent a single point. However, we consider each pixel as unit square area identified by the coordinate with respect to lower (or upper) left corner. Scan-converting a point A mathematical point (x,y) where x and y are real numbers within an image area, needs to be scan converted to a pixel at location (x/,y/). This may be done by making x/ to be the integer part of x and y/ the integer part of y. In other words, x/=Floor(x) and y/=floor(y), where function Floor returns the largest integer that is less than or equal to the argument. All points that satisfy x/≤ x<x/+1 and y/≤y<y+1 are mapped to a pixel

(x/,y/). For example, point P1 (1.7,0.8) is represented by pixel (1,0). Points P2 (2.2, 1.3) and P3 (2.8,1.9) are both represented by pixel (2,1). In another approach we can convert (x,y) by making x/=Floor(x+.5) and y/=Floor(y+.5). All points that satisfy x/-0.5≤x<x/+0.5 and y/-0.5≤y<y/+0.5 are mapped to pixel (x/,y/). This means that points P1 and P2 are now both

Page 2: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

3 Chapter2

represented by pixel (2,1), whereas point P3 is represented by pixel (3,2). Scan converting a line In order to draw a line on the screen, first we have to determine which pixels are to be switched ON. The process of determining which combination of pixels provides the best approximation to the desired line is known as Rasterization. The choice of pixels is determined by the orientation of the line which is to be drawn. There is little difficulty in selecting the pixels for horizontal, vertical and diagonal lines. For any other orientation of lines, selection of pixels is a difficult process.

General requirement for drawing a line

• Lines must appear to be straight • Lines should start and end accurately • Lines should have constant brightness

along their length.

Page 3: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

4 Chapter2

• Lines should be drawn rapidly.

On the raster scan systems, lines are plotted with pixels and step sizes in the horizontal and vertical directions are constrained by pixel separations. We must sample a line at discrete positions and determine the nearest pixel to the line at each sample position. This is decided by the equation of a straight line. Equation for a straight line is, y=mx+c where m is the slope of the line and c is the y-intercept

m= =

DDA Algorithm Let the line is to be drawn between the end points (xstart,ystart) and (xend and yend) . Let the equation of the line as y=mx+c where m is slope of the line and c is the intercept. The slope can be expressed as

m=

In fact any two consecutive points (xi,yi) and (xi+1,yi+1) lying on this line segment should

Page 4: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

5 Chapter2

satisfy the equation m= if we say yi+1-

yi=∆y and xi+1-xi=∆x then

So ∆y=m∆x Thus for a given x interval ∆x along the line , we can compute the corresponding y interval ∆y. Now if ∆x=1 i.e. xi+1-xi=1 or xi+1=xi+1 then ∆y=m which implies yi+1=yi+m. Thus a unit change in x changes y by m which is a constant for a given line. We know that if xi+1=xi+1, then yi+1=yi+m, the values of x and y are defined in terms of their previous values. Initializing (xi,yi) as (xstart,ystart) the line can be generated by incrementing the previous x values by one unit and solving the corresponding y value at each step till xend is reached. At each step we make incremental based on the previous step. This is what is defined as incremental algorithm and often referred to as the Digital Differential Analyzer (DDA) algorithm.

While incrementing the values of y by constant m, in this DDA method we have to keep in mind that m being the slope of the line, it can be any real number negative or positive – so that the calculated y values must be round off to the

Page 5: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

6 Chapter2

nearest integer for the sake of plotting on the screen. But the question is why not increment y values by 1 instead of x and accordingly calculate x values from the line’s equation. The determining factor here is absolute value of the slope of the line |m|. If |m|≤1 which implies |∆y|≤|∆x| we sample the line at unit x intervals. But if |m|˃1 means |∆y|>|∆x| a unit step in x creates a step in y that is greater than 1, which is not desirable. In that case we reverse the roles of x and y by sampling at unit y intervals as

∆y=yi+1-yi=1 so yi+1=yi+1 and ∆x= , xi+1=xi+

Both the equations are based on the assumption that xstart<xend and ystart<yend i.e. slope is positive. But if it is not so then we have to apply negative increment

The Pseudo code for rasterizing a line according to DDA is presented below.

Page 6: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

7 Chapter2

ALGORITHM Step 1: Initialize(xstart,ystart), (xend,yend) if abs(xend – xstart) ≥ abs(yend – ystart) then len = abs(xend – xstart) else len = abs(yend – ystart) ∆x = (xend – xstart) / len ∆y = (yend – ystart) / len x = xstart

y = ystart

Step 2: begin main loop i=1 while( i≤ len) Setpixel (Round(x),Round(y)) x = (x + ∆x) y = (y + ∆y) i = i + 1 end while end Advantage

• The DDA algorithm is faster method for calculating pixel positions.

• It eliminates the multiplication by making use of raster characteristics, so that appropriate increments are applied in the x or y direction to step to pixel positions along the line path

Drawback

Page 7: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

8 Chapter2

• Although DDA is fast, the accumulation

of round-off error in successive additions of floating point increment, however can cause the calculated pixel position to drift away from the true line path for long line segment.

• Floating point operation and rounding off in DDA is time-consuming.

Mathematical Example Consider a line from (0,0) to (6,7). Use DDA algorithm to rasterize this line. Solution Initializations: (xstart,ystart) = (0,0) (xend,yend) = (6,7) (xend – xstart)=6 ,(yend – ystart) = 7 so len=7 ∆x=6/7=0.857 ∆y=7/7=1 x=0 y=0 Plotting begins

Page 8: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

9 Chapter2

Bresenham’s Line Algorithm The algorithm avoids the round function and scan converts lines using only incremental integer calculation. The algorithm samples a line by incrementing one unit either x or y depending on the slope of the line and then selecting the pixels which one is close to the true line.

Let us consider a line L with a positive slope less than 1. Also consider that xi,yi be the point which is already selected to be displayed over the line segment. The next point to be select over the line

Page 9: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

10 Chapter2

is obviously xi+1 in the pixel grid. The question is whether it is (xi+1,yi+1) or (xi+1,yi) i.e. A or B. let C be the intersection of the line with the pixel grid with x=xi+1. In Bresenham’s approach the distance AC and BC is computed and the sign of their difference is used to select the pixel. Whose distance from C is smaller is selected as the best approximation. Let the vertical distance from A to C is denoted by d2 and from B to C is denoted by d1. If C is a point on the true line path the x coordinate of the point c is clearly xi+1. The y coordinate of the point can be obtained by the equation of the line as y=m(xi+1)+c considering the equation of the line in the standard slope intercept form , y=mx+c. Then d1=y-yi= m(xi+1)+c-yi and d2=(yi+1)-y=yi+1- m(xi+1)-c The difference between the two distances is d1-d2=2m(xi+1)-2yi+2c-1

Substituting m= where ∆y and ∆x are vertical

and horizontal separations between the end points of the line. Substituting the value of m we have ∆x(d1-d2)=2∆y(xi)-2∆x(yi)+2∆y+2c∆x-∆x Since ∆x>0 , ∆x(d1-d2) has same sign as (d1-d2). Therefore ∆x(d1-d2) can be used as decision parameter for choosing the pixel (xi+1,yi+1) next to (xi,yi). We call this ∆x(d1-d2) as a parameter Pi.

If Pi>0 then d1>d2 hence we select A with the coordinate (xi+1,yi+1). If Pi<0 then d1<d2 hence we select B with the coordinate (xi+1,yi) . If Pi=0 then d1=d2 hence we select either A or B.

Page 10: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

11 Chapter2

It is interesting to note that the value of the decision parameter Pi and therefore the location of the next pixel (xi+2,yi+2) depends upon our choice of pixel A or B. The parameter Pi+1 that decides the pixel (xi+2,yi+2) can be evaluated in similar manner. Pi+1=2∆y(xi+1)-2∆x(yi+1)+2∆y+2c∆x-∆x Subtracting Pi from Pi+1 we get the incremental difference Pi+1-Pi=2∆y(xi+1-xi)-2∆x(yi+1-yi) Pi+1=Pi+2∆y(xi+1-xi)-2∆x(yi+1-yi)= Pi+2∆y-2∆x(yi+1-yi) since xi+1=xi+1. If A is chosen then yi+1-yi=1 so Pi+1=Pi+2∆y-2∆x Else if B is chosen then yi+1-yi=0 so Pi+1=Pi+2∆y Now checking the sign of Pi+1 the choice can be made for the next pixel (xi+2,yi+2) i.e. whether the y coordinate of the next pixel is incremented or not. The process is continued until the end point of the line is reached. Now in case of every line the first point is specified. Let it be (x0,y0). The initial decision parameter can be easily calculated in terms of the starting point. Let P0 be the initial decision parameter. As (x0,y0)is over the line then we can say c=y0-

mx0 and 2c∆x=2y0∆x-2x0∆y substituting m as

Now from the equation of Pi substituting i as 0 we have P0=2∆y(x0)-2∆x(y0)+2∆y+2y0∆x-2x0∆y-∆x = 2∆y-∆x Algorithm (for 0<m<1) Step 1: Set the pixel (x0,y0) i.e. the starting point. Calculate the horizontal separation ∆x and vertical separation ∆y of the given end point.

Page 11: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

12 Chapter2

Step 2 : Calculate P0=2∆y-∆x Step 3: At each xi along the line starting at i=0, check the sign of the decision parameter Pi. If Pi<0 then the next point to be plot (xi+1,yi) and Pi+1=Pi+2∆y otherwise the next point to be plot is (xi+1,yi+1) and Pi+1=Pi+2∆y-2∆x. Set i=i+1 Step 4: repeat step 3 as long as i<∆x Note: This version of the Bresenham’s algorithm work for slope between 0 and 1. A little modification is needed for make it apply for lines having other tendency. Advantages:

• Accurate • Efficient • Integer Calculations • Uses Symmetry. • Adapted to display circles, ellipses

and curves. • It has been proven that the

algorithm gives an optimal fit for lines

Disadvantage: • Cannot generalize to arbitrary conics.

Example: Scan convert a line between the point (0,2) and (4,5) using Bresenham’s approach. Here (x0,y0)=(0,2) , ∆y=5-2=3 ,∆x=4-0=4 Slope m= <1

Page 12: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

13 Chapter2

The successive decision parameter Pi and the corresponding pixel position (xi+1,yi+1) are as follows P0=2∆y-∆x=2>0 so x1=1,y1=y0+1=3 P1=P0+2∆y-2∆x=2+2x3-2x4=0 So x2=2,y2=y1+1=4 P2=P1+2∆y-2∆x=0+2x3-2x4=-2<0 so x3=3 and y3=y2=4 P3=P2+2∆y=-2+2x3=4>0 so x4=4 and y4=y3+1=5 We have to stop here because we reach at (4,5) the end point The result is tabulated as follows

Generalized Bresenham’s Algorithm A Possible approach of Bresenham’s algorithm is to consider the pixel coordinate in different way for the lines having slope other than between 0 and 1. When the absolute magnitude of the slope of the line is greater than 1, we step along the direction of Y instead of X in unit steps and calculate successive X values using the algorithm.

Page 13: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

14 Chapter2

However for negative slope s the procedure is imilar except that now one coordinates decreases as the other increases from start point to the end point of such lines. Therefore the decreasing coordinate is incremented by -1 instead of +1 in Bresenham’s logic.

Considering all the cases a generalized version of the Bresenham’s algorithm (Pseudocode) is given below. The line end points are (xs,ys) and (xe,ye). Initialize variables x=xs,y=ys ∆x=abs(xe-xs), ∆y=abs(ye-ys)

Page 14: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

15 Chapter2

S1= sign(xe-xs), s2= sign(ye-ys) // sign function return +1 or -1 according to positive or negative if ∆y>∆x then

t=∆x ∆x=∆y ∆y=t flag=1 else flag=0 end if

n=1 P=2∆y-∆x Setpixel(x,y) while(n≤∆x) if P≥0 then x=x+s1 y=y+s2 P=P+2(∆y-∆x) Else if flag=1 then y=y+s2

else x=x+s1 end if P=P+2∆y end if , setpixel(x,y) n=n+1 end while Scan converting a circle Approach of generating a circle is based on the symmetric property of the circle to plot eight points for each value that the algorithm calculates. A circle is a symmetric figure. Eight-

Page 15: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

16 Chapter2

way symmetric is used by reflecting each calculated point around each 45º axis.

Symmetry about the pair of lines with slopes of one and minus one

We can find any point's symmetric complement about these lines by permuting the indices. For example the point (x,y) has a complementary point (y,x) about the line x=y. And the total set of complements for the point (x,y) are

Symmetric complement of the point’s can be obtained easily about these lines by permuting the indices only : {(x,-y), (-x,y), (-x,-y), (y,x), (y,-x), (-y,x),(-y,-x)} as the equation of the circle is

(±x)2+(±y)2=r2 with center at (0,0) and with radius r.

Page 16: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

17 Chapter2

Bresenham’s circle drawing algorithm It uses eight-way symmetric property of a circle points over the entire circle. Initially we generate the points over the angle 90º to 45º where moves are made in the positive x direction and negative y direction. It is to be noted that while plotting the points over the said angle we have to take two actions

• Move in the positive x direction by one unit.

• Move in the positive x direction by one unit and in the negative y direction by one unit as well.

These two choices are necessary to generate all the points’ closest to the true circle over the angle 90º to 45º.

Xi+1,Y

Xi+1,yi-1

Page 17: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

18 Chapter2

Assume that (xi,yi) are the coordinates of the point which is already to be selected over the true circle. Let the distance from the origin to pixel T squared minus the distance to the true circle squared =D(T) and the distance from the origin to the pixel S squared minus the distance to the true circle squared=D(S). As the coordinate of T are (xi+1,yi) and those of S are (xi+1,yi-1), the following expression can be developed : D(T)=(xi+1)2+yi

2-r2 and D(S)=(xi+1)2+(yi-1)2-r2 The function D provides a relative measurement of the distance from the center of a pixel to the true circle. Since D(T) is always positive and D(S) is always negative a decision variable di may be defined as follows. di=D(T)+D(S) so di=2(xi+1)2+yi

2+(yi-1)2-2r2 When di<0 we have |D(T)|<|D(S)| and pixel T is chosen. When di≥0, we have |D(T)|≥|D(S)| and pixel S is selected. We can also write the decision variable di+1 for the next step di+1=2(xi+1+1)2+yi+1

2+(yi+1-1)2-2r2

Page 18: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

19 Chapter2

Hence di+1-di= 2(xi+1+1)2+yi+12+(yi+1-1)2 -

2(xi+1)2-yi2-(yi-1)2

Since xi+1=xi+1 we have di+1=di+4xi+2(yi+12-

yi2)-2(yi+1-yi)+6

If T is chosen i.e. if di<0 then yi+1=yi and so di+1=di+4xi+6 On the other hand if S is chose i.e. di≥0 then yi+1=yi -1 and so di+1=di+4(xi-yi) +10 Hence we have di+1= di+1=di+4xi+6 if di<0 or di+1= di+1=di+4(xi-yi)+10 if di≥0 The plotting begins at a point over the y axis where the x coordinate is =0 and x coordinate is obviously =r because the radius of the circle is =r. If we consider the polar coordinate (r,Ө) of circle then x=r cosӨ and y=r sinӨ ,if we put Ө=90° then we have x=0 and y=r as the beginning point to be plot. As the starting point of the algorithm is the pixel (0,r) we have the initial decision parameter d1=2(0+1)2+r2+(r-1)2-2r2=3-2r The algorithm is as follows: Step 1: Input radius r of the circle and the first

point on the circumference of a circle centered on the origin as x=0,y=r

Step2: Calculate the initial value of the decision parameter as d=3-2r

Step 3: Setpixel (x,y) Step4: At each x position starting from the initial

point perform the following test :if d<0 then

d=d+4x+6; x=x+1

Page 19: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

20 Chapter2

Otherwise d=d+4(x-y)+10; x=x+1;y=y-1

Step 4: Repeat step 2 to 3 until x≥y note :

• The circle is drawn only over the angle from 90º to 45º. For other part of the circle we have to apply the eight way symmetric property of the circle.

• Remember that the circle is centered at origin. For any arbitrary centered circle we have to apply transformation over the entire circle. For the circle with center at xc,yc we have to plot the coordinate as x=x+xc and y=y+yc

Pseudocode for the algorithm: int x=0,y=r,d=3-2r, center(xc,yc); while (x≤y) { setpixel(x+xc,y+yc); setpixel(-x+xc,-y+yc); setpixel(y+xc,x+yc); setpixel(y+xc,-x+yc); setpixel(-y+xc,x+yc); setpixel(y+xc,-x+yc); setpixel(-x+xc,y+yc); setpixel(x+xc,-y+yc); if(d<0) d=d+4x+6; else { d=d+4(x-y)+10; y--; }

Page 20: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

21 Chapter2

x++; } Example: Consider an origin centered circle of radius 10. Determine the pixel that will be put ON for the first quadrant only. Initialization: x=0,y=10,d=3-2x10=-17 Plotting begins

Midpoint Circle Algorithm This procedure describes another incremental circle algorithm similar to Bresenham’s approach. It is based on the following function for testing the spatial relationship between an arbitrary point (x,y) and a circle of radius r centered at the origin:

Page 21: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

22 Chapter2

f(x,y)=x2+y2-

r2

Let us now consider the coordinate of the point midway between the pixel T and the pixel S (xi+1,yi-½) and with the midpoint we define a decision parameter as pi=f(xi+1,yi-½)=(xi+1)2+(yi-½)2-r2 If pi is negative the midpoint is inside the circle and we choose the pixel T. on the other hand if pi is positive the midpoint is outside the circle and we choose pixel S. the decision parameter for the next step is pi+1=(xi+1+1)2+(yi-½)2-r2 Since xi+1=xi+1 we have pi+1-pi=[(xi+1)+1]2-(xi+1)2+(yi+1-½)2-(yi-½)2

Hence pi+1=pi+2(xi+1)+1+(yi+12-yi

2)-(yi+1-yi) If pixel T is chosen (meaning pi<0) we have yi+1=yi . on the other hand if pixel S is chosen (meaning pi≥0) , we have yi+1=yi-1 so we have

Page 22: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

23 Chapter2

pi+1=

The initial value of the decision parameter pi can be obtained by taking the value of xi=0 and yi=r

pi=(0+1)2+(r-½)2-r2= -r,

However we can set the initial decision parameter p1=1-r for integer computation. It does not affect the scan conversion process because the decision parameter is used only for integer computation of the subsequent coordinates. The algorithm is as follows:

Step 1: Input radius r of the circle and the first point on the circumference of a circle centered on the origin as x=0,y=r

Step2: Calculate the initial value of the decision parameter as p=1-r

Step 3: Set pixel (x, y) Step4: At each x position starting from the initial point

perform the following test: if p<0 then p=p+2x+3; x=x+1 Otherwise p=p+2(x-y)+5; x=x+1;y=y-

1 Step 4: Repeat step 2 to 3 until x≤y

Page 23: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

24 Chapter2

Note: when eight-way symmetric is used to obtain a full circle from pixel coordinate generated for the 0° to 45° or the 90° to 45° octant certain pixels are set or plotted twice. This phenomenon is sometimes referred to as overstrike. Over striking is not harmful because resetting a pixel with the same value does not really change the image of the frame buffer. But it is wasting of time because some pixels are drawn twice Pseudocode for the algorithm: int x=0,y=r,p=1-r, center(xc,yc); while (x≤y) { setpixel(x+xc,y+yc); setpixel(-x+xc,-y+yc); setpixel(y+xc,x+yc); setpixel(y+xc,-x+yc); setpixel(-y+xc,x+yc); setpixel(y+xc,-x+yc); setpixel(-x+xc,y+yc); setpixel(x+xc,-y+yc); if(p<0) p=p+2x+3; else { p=d+2(x-y)+5; y--; } x++; }

Page 24: Chapter2 2 - aditipaulsite.files.wordpress.com · Chapter2 2 Scan Conversion The screen of a computer is divided into rows and columns. The intersection area of these rows and columns

25 Chapter2

Example: Consider an origin centered circle of radius 10. Determine the pixel that will be put ON for the first quadrant only. Initialization: x=0,y=10,d=1-10=-9 Plotting begins

Midpoint Ellipse Algorithm Midpoint ellipse algorithm is a method for drawing ellipses in computer graphics. This method is modified from Bresenham’s algorithm. The advantage of this modified method is that only addition operations are required in the program loops. This leads to simple and fast implementation in all processors. Let us consider one quarter of an ellipse. The curve is divided into two regions. In region I, the slope on the curve is greater than –1 while in region II less than –1.