Presentation on theme: "Scan conversion of Line , circle & ellipse"— Presentation transcript:
1 Scan conversion of Line , circle & ellipse Computer graphicsScan conversion of Line , circle & ellipse
2 Scan conversionis the process of converting basic, low level objects in totheir corresponding pixel map representations. This is oftenan approximation to the object, since the frame buffer is a discrete grid.
3 Line Drawing algorithms Direct or floating or simple algorithmDigital Differential Analyzer algorithm (DDA)Bresenham's algorithm or midpoint algorithmGeneral Bresenham's algorithmDescription:Given the specification for a straight line (parameters).find the collection of addressable pixels which most closely approximates this line (mathematical equations) .Draw the scan conversion of lines (frame buffer map).GoalsStraight lines should appear straight.Lines should start and end accurately.Lines should be drawn as rapidly as possible.matching endpoints with connecting lines.Lines should have constant brightness.
4 Direct method Description: 1. A straight line may be defined by two endpoints and an equationIf the two endpoints used to specify a line are (X1,Y1) and (X2,Y2) ,then the equation of the line is used to describe the X , Y coordinates of all the pointes that lie between these two endpoints.x1y1x2Y22. The line equation depend on octant which contain lineDx = x2 - x1Octant covering in 2D spaceDy = y2 - y1dy > dxnegativeVIIIdy < dxVIIpositiveVIVIVIIIIIIratioSlope (m)Octant
5 x go from x1 to x2 with values (+1) or (-1) 3. The equation of straight line in octants Dx > DyY= M * X + BWhere: M is the slope of the line.B is the Y intercept. B= Y – M * XNote : The slope between any point (X1,Y1) on the line and (X2,Y2)M = DY/ DXx go from x1 to x2 with values (+1) or (-1)EX1:- draw line between(0,1) and ( 5,4)Sol:- M= 4 -1 / 5-0 = 3/5 = 0.6 , B=1 , y= (0.6)*X+1x go from x1 to x2 with integer values (+1) in each stepx12345y126.96.36.199.4draw(0,1)(1,2)(2,2)(3,3)(4,3)(5,4)
6 y go from y1 to y2 with values (+1) or (-1) 4. The equation of straight line in octants Dy > DxX= Y – B / My go from y1 to y2 with values (+1) or (-1)Ex: draw line between(1,2) and ( 3,6)sol: m= 2 , B= 0XYdraw12(1,2)1.53(2.3)4(2,4)2.55(3,4)6(3,6)
8 features:The algorithm performs a floating-point multiplication for every step in x. This method therefore requires an enormous number of floating-point multiplications, and is therefore expensive.Round functions are needednot general for all octantsCan get gaps in the line.example:y = 10.x + 2x=1, y=12;x=2, y=22.
9 Algorithm for octant with x1<x2 Dim img As New Bitmap(1, 1)img.SetPixel(0, 0, Color.Blue)dx = x2 - x1dy = y2 - y1m = dy / dxb = y1 - m * x1For x = x1 To x2e.Graphics.DrawImage(img, x, Int(y))y = m * x + bNextHW: develop direct method to draw lines in octants(( Dx >Dy), slope( positive , negative))
10 length=max( Abs(y2-y1) , Abs(x2-x1) Digital Differential Analyzer (DDA)Description:1. We calculate the length of the line in the X direction ( number of pointes) by the equationAbs(x2-x1)2. calculate the length of the line in the Y direction( number of pointes) by the EquationAbs(y2-y1)Where ABS is a function takes the positive of the arguments.3. The Length estimates is equal to the larger of theabove two equations.length=max( Abs(y2-y1) , Abs(x2-x1)
11 4. The increment steps ( dX and dY ) are used to increment the X and Y coordinates for the nextpointes to be plotted.Dx= (x2-x1) / lengthDy= (y2-y1) / length5. each point will calculate as equationx = x + Dxy = y + Dy6. Integer function works as follow( round down)Ex. Integer (8.5) = 8Integer (-8.5) = -97. first point we add 0.5x = xy = y
12 Ex1: Consider the line from (-8,-4) to (0,0)Use DDA to scan conversion of line.Sol 1 :X1=-8 ; Y1= ; X2= ; Y2=0 ;Length= 8dX= 1; dY=0.5 ; X= ; Y=-3.5IXYdraw-7.5-3.5(-8,-4)1-6.5-3(-7,-3)2-5.5-2.5(-6,-3)3-4.5-2(-5,-2)4-1.5(-4,-2)5-1(-3,-1)6-0.5(-2,-1)7(-1,0)80.5(0,0)
14 Features of DDA 1- The algorithm is orientation dependent 2- The end point accuracy deteriorates3- The algorithm suffer from the fact that itmust be performed using floating point arithmeticHW1: Consider the line from (0,0) to (-8,-4)evaluate the DDA algorithm