prev

next

out of 21

Published on

29-Feb-2016View

12Download

0

Embed Size (px)

DESCRIPTION

Computer graphics Algortihms

Transcript

Example Draw a line from (20,10) to (30,18)

Example on Bresenham Line Algorithm Draw a line from (20,10) to (30,18)19181716151413121110202122232425262728293031321(20,10)(30,18)dx = 10, dy = 8initial decision d0 = 2dy dx = 6Also 2dy = 16, 2(dy dx) = -4i di (xi+1,yi+1)0 6 (21,11) 1 2 (22,12) 2 -2 (23,12) 3 14 (24,13) 4 10 (25,14) 5 6 (26,15) 6 2 (27,16) 7 -2 (28,16) 8 14 (29,17) 9 10 (30,18) 1Special cases on Bresenhams Line Algorithm 2Special cases can be handled separatelyHorizontal lines (y = 0)Vertical lines (x = 0)Diagonal lines (|x| = |y|)directly into the frame-buffer without processing them through the line-plotting algorithms.2Circle Generating AlgorithmsCircle Properties:A set of points that are all at the same distance (r) from a center point (xc,yc).Expressed by Pythagorean equation in Cartesian coordinates as:(x xc )2 + (y - yc )2 = r2

Any given circle can be drawn on the origin(0,0) and then moved to its actual position by:Each calculated x on the circumference moved to x+xc.Each calculated y on the circumference is moved to y+yc.Circle Generating Algorithms:Standard AlgorithmPolar AlgorithmSymmetry AlgorithmMid-point Algorithm(xc, yc )r(x, y)Standard Algorithm:Uses the Pythagorean equation to find the points along the circumference.Steps along x axis by unit steps from xc-r to xc+r and calculate y for each step as:y= yc r2-(xc-yc)2It involves considerable computations at each step.Standard Algorithm:Spacing between plotted pixels is not uniform.

Spacing can be adjusted by stepping on y instead of x when the slop is greater than 1, but such approach increasing computations.

Polar Algorithm:Uses polar coordinates r and .Calculate points by fixed regular step size equations as:x= xc + r * cosy= yc + r * sinStep size that is chosen for depends on the application.Larger separations can be connected by line segments to approximate the circle path.Polar Algorithm:In raster displays, step size is 1/r which plots pixel positions that are approximately one unit apart.

rx,ySymmetry Algorithm:Reduces computations by considering the symmetry of circles in the eight octants in the xy plane.Generates all pixel positions around a circle by calculating only the points within the sector from x = 0 to x = y.

Bresenhams Circle Algorithm (CHK )General PrincipleThe circle function:

and

11Consider only 45 90

11Bresenhams Circle Algorithm12p1p3p2D(si)D(ti)After point p1, do we choose p2 or p3?yiyi - 1xixi + 1r12Bresenhams Circle Algorithm13Define:D(si) = distance of p3 from circleD(ti) = distance of p2 from circle

i.e.D(si) = (xi + 1)2 + yi2 r2 [always +ve]D(ti) = (xi + 1)2 + (yi 1)2 r2 [always -ve]

Decision Parameter pi = D(si) + D(ti)so if pi < 0 then the circle is closer to p3 (point above) if pi 0 then the circle is closer to p2 (point below)

13The Algorithm14x0 = 0y0 = rp0 = [12 + r2 r2] + [12 + (r-1)2 r2] = 3 2r

if pi < 0 thenyi+1 = yipi+1 = pi + 4xi + 6

else if pi 0 thenyi+1 = yi 1pi+1 = pi + 4(xi yi) + 10

Stop when xi yi and determine symmetry points in the other octantsxi+1 = xi + 114Mid-point Algorithm:Samples at unit intervals and uses decision parameter to determine the closest pixel position to the specified circle path at each step.Along the circle section from x = 0 to x = y in the first quadrant, the slope of the curve varies from 0 to -1. Therefore, we can take unit steps in the positive x direction over this octant and use a decision parameter to determine which of the two possible y positions is closer to the circle path at each step. Positions in the other seven octants are then obtained by symmetry.Mid-point Algorithm:To apply mid-point method, we define a circle function:and determine the nearest y position from pk:

Mid-point Algorithm: If pk < 0, this midpoint is inside the circle and the pixel on scan line yk is closer to the circle boundary.

Otherwise, the midposition is outside or on the circle boundary, and we select the pixel on scan line yk 1 .

Successive parameters are calculated using incremental calculations:

Mid-point Algorithm: Example: For a circle radius=10 and center (12,12)

we calculate positions in the first octant only , beginning with x=0 and ending when x=y

The initial decision parameter value:P0=1 - r = -9

Drawing on the origin (0,0) and the initial point (0,10)2x0=02y0=20

Mid-point Algorithm:24232221201918171615141312111098765432100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24K P (xk+1,yk+1)2xk+1 2yk+10 -9(1,10)2 201 -6(2,10)4 202 -1(3,10)6 203 6(4,9)8 184 -3(5,9)10 185 8(6,8)12 165(7,7)14 14

The first octant is completed and the remained seven octants can be plotted according to symmetry.Mid-point Algorithm:24232221201918171615141312111098765432100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 The circle after plotting all octants and moving it to its original center (12,12)Example10987654321001234567891021ipixi, yi0-17(0, 10)1-11(1, 10)2-1(2, 10)313(3, 10)4-5(4, 9)515(5, 9)69(6, 8)7(7,7)r = 10p0 = 3 2r = -17Initial point (x0, y0) = (0, 10)21