Upload
destini-rawe
View
215
Download
1
Embed Size (px)
Citation preview
Computer Computer graphicsgraphics
Computer Computer graphicsgraphics
Scan conversion of Line Scan conversion of Line , circle & ellipse, circle & ellipse
Scan conversionScan conversionis the process of converting basic, low level objects in to their corresponding pixel map representations. This is often an approximation to the object, since the frame buffer is a discrete grid.
• Direct or floating or simple algorithm • Digital Differential Analyzer algorithm (DDA) • Bresenham's algorithm or midpoint algorithm• General Bresenham's algorithm
Line Drawing algorithmsLine Drawing algorithms
Description: • 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). Goals• Straight 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.
1. A straight line may be defined by two endpoints and an equation1. A straight line may be defined by two endpoints and an equation If 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.
x1
y1
x2
Y2
Description: Direct methodDirect method
dy > dxdy > dxnegativenegativeVIIIVIIIdy < dxdy < dxnegativenegativeVIIVIIdy < dxdy < dxpositivepositiveVIVIdy > dxdy > dxpositivepositiveVVdy > dxdy > dxnegativenegativeIVIVdy < dxdy < dxnegativenegativeIIIIIIdy < dxdy < dxpositivepositiveIIIIdy > dxdy > dxpositivepositiveII
ratioratioSlope Slope (m)(m)
OctantOctant
Octant covering in 2D spaceOctant covering in 2D spaceDx = x2 - x12. The line equation depend on octant which contain 2. The line equation depend on octant which contain lineline
Dy = y2 - y1
Y= M * X + BY= M * X + B
Where:Where: M is the slope of the line. B is the Y intercept. B= Y – M * X
Note :Note : The slope between any point (X1,Y1) on the line and (X2,Y2) M = DY/ DX
3. The equation of straight line in octants Dx > 3. The equation of straight line in octants Dx > Dy Dy
x go from x1 to x2 with values (+1) or (-x go from x1 to x2 with values (+1) or (-1)1)
EX1:- draw line between(0,1) and ( 5,4)Sol:Sol:- M= 4 -1 / 5-0 = 3/5 = 0.6 , B=1 , y= (0.6)*X+1- M= 4 -1 / 5-0 = 3/5 = 0.6 , B=1 , y= (0.6)*X+1 x go from x1 to x2 with integer values (+1) in each x go from x1 to x2 with integer values (+1) in each stepstep
0 1 2 3 4 5
0
1
2
3
4
xx 00 11 22 33 44 55
yy 11 1.61.6 2.22.2 2.82.8 3.43.4 44
dradraww
(0,1(0,1))
(1,2(1,2))
(2,2(2,2))
(3,3(3,3))
(4,3(4,3))
(5,4(5,4))
X= Y – B / MX= Y – B / M
4. The equation of straight line in octants Dy > 4. The equation of straight line in octants Dy > Dx Dx
y go from y1 to y2y go from y1 to y2 with values (+1) or (-with values (+1) or (-1)1)
Ex:Ex: draw line between(1,2) and ( 3,6) draw line between(1,2) and ( 3,6)sol:-sol:- m= 2 , B= 0 m= 2 , B= 0
XX Y Y drawdraw
11 22 (1,2)(1,2)
1.1.55
33 (2.3)(2.3)
22 44 (2,4)(2,4)
2.2.55
55 (3,4)(3,4)
33 66 (3,6)(3,6) 1 2 3 4 5
1
2
3
4
5
6
Ex: draw line between(2,-2) and ( 6,-Ex: draw line between(2,-2) and ( 6,-6)6)Sol:-Sol:- m= -4 / 4 = -1 , B= -2 – (-1*2) = 0m= -4 / 4 = -1 , B= -2 – (-1*2) = 0
XX Y Y drawdraw
22 -2-2 (2,-2)(2,-2)
33 -3-3 (3,-3)(3,-3)
44 -4-4 (4,-4)(4,-4)
55 -5-5 (5,-5)(5,-5)
66 -6-6 (6,-6)(6,-6)
2 3 4 5 6 -2 -3
-4 -5
-6
features: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 needed• not general for all octants• Can get gaps in the line.
example: y = 10.x + 2 x=1, y=12; x=2, y=22.
Algorithm for octant with x1<x2
Dim img As New Bitmap(1, 1) img.SetPixel(0, 0, Color.Blue) dx = x2 - x1 dy = y2 - y1 m = dy / dx b = y1 - m * x1 For x = x1 To x2 e.Graphics.DrawImage(img, x, Int(y)) y = m * x + b Next
HW:HW: develop direct method to draw lines in develop direct method to draw lines in octants(( Dx >Dy), slope( positive , octants(( Dx >Dy), slope( positive ,
negative)) negative))
Digital Differential Analyzer (DDA)Digital Differential Analyzer (DDA)
1. We calculate the length of the line in the X direction ( number of pointes) by the equation
Abs(y2-y1)Abs(y2-y1)
2. calculate the length of the line in the Y direction ( number of pointes) by the Equation
Abs(x2-x1)Abs(x2-x1)
3. The Length estimates is equal to the larger of the above two equations.
Where ABS is a function takes the positive of the arguments.
length=max( Abs(y2-y1) , Abs(x2-length=max( Abs(y2-y1) , Abs(x2-x1)x1)
Description:
4. The increment steps ( dX and dY ) are used to increment the X and Y coordinates for the next pointes to be plotted.Dx= (x2-x1) / lengthDx= (x2-x1) / length
Dy= (y2-y1) / lengthDy= (y2-y1) / length
5. each point will calculate as equation
7. first point we add 0.5
x = x + Dxx = x + Dxy = y + Dyy = y + Dy
x = x1 + x = x1 + 0.50.5 y = y1 + y = y1 + 0.50.5
6. Integer function works as follow( round down)
Ex.Ex. Integer (8.5) = 8Integer (8.5) = 8 Integer (-8.5) = -9Integer (-8.5) = -9
Ex1: Consider the line from (-8,-4) to (0,0)Use DDA to scan conversion of line.Sol 1 :X1=-8 ; Y1=-4 ; X2=0 ; Y2=0 ; Length= 8 dX= 1; dY=0.5 ; X=-7.5 ; Y=-3.5
II XX Y Y drawdraw
-7.5-7.5 -3.5-3.5 (-8,-4)(-8,-4)
11 -6.5-6.5 -3-3 (-7,-3)(-7,-3)
22 -5.5-5.5 -2.5-2.5 (-6,-3)(-6,-3)
33 -4.5-4.5 -2-2 (-5,-2)(-5,-2)
44 -3.5-3.5 -1.5-1.5 (-4,-2)(-4,-2)
55 -2.5-2.5 -1-1 (-3,-1)(-3,-1)
66 -1.5-1.5 -0.5-0.5 (-2,-1)(-2,-1)
77 -0.5-0.5 00 (-1,0)(-1,0)
88 0.50.5 0.50.5 (0,0)(0,0)
-8 -7 -6 -5 -4 -3 -2 -1 0
-4
-3
-2
-1
0
Start Length=ABS (X2-X1) If length < ABS (Y2-Y1) Then Length=ABS (Y2-Y1) dX = (X2 - X1) / Length dY = (Y2 - Y1) / Length X=X1 + 0.5 Y=Y1 + 0.5 Plot (Integer (X) , Integer (Y)) For I=1 to Length Begin X=X + dX Y=Y + dY Plot (Integer (X) , Integer (Y)) EndFinish
Algorithm Algorithm DDADDA
Features of DDAFeatures of DDA
1- The algorithm is orientation dependent2- The end point accuracy deteriorates3- The algorithm suffer from the fact that it must be performed using floating point arithmetic
HW1:HW1: Consider the line from (0,0) to (-Consider the line from (0,0) to (-8,-4)8,-4) evaluate the DDA algorithmevaluate the DDA algorithm