33

Computer Graphics

Embed Size (px)

Citation preview

Page 1: Computer Graphics
Page 2: Computer Graphics

Output primitives are the basic geometric structures which facilitate or describe a scene/picture.

Example of these include:points, lines, curves (circles, conics etc), surfaces, fill colour, character string etc.

Introduction

Page 3: Computer Graphics

In order to draw the primitive objects, one has to first scan convert the object.

Scan convert: Refers to the operation of finding out the location of pixels and then setting the values of corresponding bits, in the graphic memory, to the desired intensity code.

Page 4: Computer Graphics

Digital Differential Analyzer Algorithm

(DDA)

Page 5: Computer Graphics

The Digital Differential Analyzer (DDA) Algorithm

5

mx

y

means that for a unit (1) change in x

there is m-change in y.

my

x 1

means that for a unit (1) change in y

there is 1/m change in x.

Page 6: Computer Graphics

6

The DDA MethodUses differential equation of the line : mIf slope |m| 1 then increment x in steps of 1 pixel and find corresponding y-values.If slope |m| 1 then increment y in steps of 1 pixel and find corresponding x-values.

step through in x step through in y

Page 7: Computer Graphics

DDA- Line with positive Slope

A line with positive slope (Left to Right) If m <= 1, sample at unit x intervals (Δx = 1) and compute successive y values as: yk+1 = yk + m. If m >1, sample at unit y intervals (Δy =1) andcompute successive x values as: xk+1 = xk + 1/m.

Page 8: Computer Graphics

A line with positive slope (Right to Left) If m <= 1, sample at unit x intervals (Δx =-1)and compute successive y values as: yk+1 = yk – m If m >1, sample at unit y intervals (Δy = -1) and compute successive x values as: xk+1 = xk - 1/m

Page 9: Computer Graphics

A line with negative slope (Left to Right) If |m| <= 1, sample at unit x intervals (Δx = 1) and compute successive y values as: yk+1 = yk + m If |m| >1, sample at unit y intervals (Δy =-1)and compute successive x values as: xk+1 = xk - 1/m

DDA- Line with negative Slope

Page 10: Computer Graphics

A line with negative slope (Right to Left)If |m| <=1, sample at unit x intervals (Δx =1) and compute successive y values as: yk+1 = yk - m If |m| >1, sample at unit y intervals (Δy =1)and compute successive x values as: xk+1 = xk + 1/m

Page 11: Computer Graphics

1) Accept the end point co-ordinates of the line segment AB ie A(x1,x2) and B(x2,y2). 2) Calculate dx and dy.

3) If abs(dx)>=abs(dy) then , Step=dx else Step=dy.

Dda algorithm

Page 12: Computer Graphics

4) Let x increment = dx/Step ; Let y increment = dy/Step.

5) Display the pixels at standing portion put pixel (x,y,white).

6) Compute the next co-ordinate position along the line path xk+1 = xk + x increment

yk+1 = yk + y increment

Put Pixel(xk+1 , yk+1 ,white).

Page 13: Computer Graphics

7) If xk+1=x2 OR / AND yk+1=y2

then STOP else go to Step (4).

Page 14: Computer Graphics

Bresenham’s Line Algorithm

Page 15: Computer Graphics

Bresenham’s Line Algorithm

1) In Bresenham’s Line Drawing Algorithm the pixel positions along a line path are obtained by determining the pixel i.e nearer the line at each step. 2) It is an efficient raster line generation algorithm.

Page 16: Computer Graphics

1) Accept the end point co-ordinates of the line segment AB ie A(x1,x2) and B(x2,y2).

2) Calculate dx and dy.

3) If abs(dy)<=abs(dx) ie slope |m|<=1 (a) Compute initial decision parameter Po= 2abs(dy)-abs(dx).

Page 17: Computer Graphics

(b) At each xk position perform the following

if Pk <0 i.e d1< d2 then,

x increment=dx/abs(dx) AND y increment=0

Pk+1= Pk + 2abs(dy)

else,

Pk >0 ie d1>d2

X increment =dx/abs(dx) Y increment =dy/abs(dy)

Pk+1= Pk +2abs(dy)-2abs(dx).

Page 18: Computer Graphics

4) If abs(dy) > abs(dx) ie slope |m|>1

(a) Compute initial decision parameter Po= 2abs(dx)-abs(dy) (b) At each xk position,perform the following if Pk < 0 i.e d1 < d2 then

x increment=0 y increment=dy/abs(dy)

Pk+1= Pk + 2abs(dx)

Page 19: Computer Graphics

Else, Pk >0 ie d1>d2

X increment=dx/abs(dx) Y increment=dy/abs(dy) Pk+1= Pk +2abs(dx)-2abs(dy).

5) Calculate : xnext = xk + x increment

ynext = yk + y increment.

Display (xk+1, yk+1, white).

Page 20: Computer Graphics

6) Repeat Step (3) to (5) until xk+1=x2 AND /OR yk+1 =y2

7)STOP.

Page 21: Computer Graphics

Midpoint Circle Algorithm

Page 22: Computer Graphics

Mid-point Circle Algorithm

A method for direct distance comparison isto test the halfway position between twopixels to determine if this midpoint is insideor outside the circle boundary. This method is more easily applied toother conics, and for an integer circleradius.

Page 23: Computer Graphics

1) Accept the radius r and center (xc, yc).The point of the circumference of a circle with center as origin (x0, y0) =(0,r).

2) Calculate the initial decision parameter as Po =5/4 –r .

3) At each xk position starting at k=0.Perform

the following test.

Page 24: Computer Graphics

If Pk <0 then,

Xk+1= xk +1 and yk+1= yk

Pk+1 = Pk +2xk +3

Otherwise, Pk >0

Xk+1= xk +1 and Yk+1= yk -1

Pk+1= Pk +2( xk - yk ) +5

4) Determine the symmetric points in other 7 octants.

Page 25: Computer Graphics

5) Translate each calculated pixel position by T ( xk , yk ) and display the pixel

X= xk+1 + xc AND Y= yk+1 + yc

Put pixel ( x,y, white).

6) Repeat step (3) to step (5) until x>=y.

7)STOP.

Page 26: Computer Graphics

BRESENHAM’S CIRCLE ALGORITHM

Page 27: Computer Graphics

1) Accept the radius r and center (xc, yc).The point of the circumference of a circle with center as origin (x0, y0) =(0,r).

2) Calculate the initial decision parameter as PO =3 – 2r.

3) At each xk position starting at k=0.Perform

the following test.

Page 28: Computer Graphics

If Pk <0 then,

Xk+1= xk +1 and yk+1= yk

Pk+1 = Pk +4xk +6.

Otherwise, Pk > 0

Xk+1= xk +1 AND Yk+1= yk -1

Pk+1= Pk +4( xk - yk ) +10

4) Determine the symmetric points in other 7 octants.

Page 29: Computer Graphics

5) Translate each calculated pixel position by T ( xk , yk ) and display the pixel

X= xk+1 + xc AND Y= yk+1 + yc

Put pixel ( x, y, white)6) Repeat step (3) to step (5) until x>=y 7) STOP.

Page 30: Computer Graphics

The DDA algorithm is accomplished by taking unit step in one direction and calculating other.

The Bresenham’s Algorithm finds the closest integer co-ordinate to the actual part.

DDA algorithm uses floating point calculation. Bresenham’s uses integer point calculation. DDA is more accurate compared to

Bresenhams.

CONCLUSION

Page 31: Computer Graphics

Circles and ellipses can be efficiently and accurately scan converted using midpoint methods.

Bresenham’s line algorithm and the midpoint line algorithm methods are the most efficient.

Page 32: Computer Graphics
Page 33: Computer Graphics

THANK YOU