Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

- Computer graphics Unit 2 by Vidhya Venkatesan 1153 views
- Online trading sites by Share FREE eBooks 237 views
- Digital books online by Share FREE eBooks 94 views
- Free ebook search by Share FREE eBooks 169 views
- How to buy penny shares? by Share FREE eBooks 260 views
- Red hot penny shares by Share FREE eBooks 365 views

1,515 views

1,472 views

1,472 views

Published on

Bresenham's line and circle algorithm , mid point circle algorithm

Published in:
Education

No Downloads

Total views

1,515

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

85

Comments

0

Likes

5

No embeds

No notes for slide

- 1. Lecture Outline• Scan Conversion – Point – Line – Circle
- 2. Point Scan• Point plotting is furnished by converting a single coordinate position into appropriate operations for the output device in use.• Random scan uses stored point-plotting instructions (coordinates) and convert them in deflection voltage that positions the electron beam at the screen locations to be plotted during each refresh cycle.
- 3. Point Scan…1• Raster scan depends on setting the bit value corresponding the specified screen position within the frame buffer to 1. The electron beam when sweeps across such position in a line emits burst of electrons with intensities corresponding to colour codes to be displayed at that location.
- 4. Point Scan…2• Let as scan-convert a point (x, y) to a pixel location (x’, y’) • x’ = Floor(x), and y’ = Floor(y) • Where Floor is a function that returns largest integer that is less than or equal to the argument.• In such a case, the origin is placed at the lowest left corner of the pixel grid in the image space• All points that satisfy x’ x < x’+1 and y’ y < y’ + 1 will be mapped to pixel location (x’, y’) (refer Fig a)
- 5. Point Scan…3
- 6. Point Scan…4• If the origin of coordinate system for (x, y) is to be shifted to new location say (x+0.5, y+0.5), then – x’ = Floor(x+0.5), and y’ = Floor(y+0.5) – This will place the origin of the coordinate system (x, y) at the centre of pixel (0, 0) – Now, all points that satisfy x’-0.5 x < x’+0.5 and y’-0.5 y < y’+0.5 will be mapped to pixel location (x’, y’) (refer Fig b)
- 7. Line Scan-Conversion• Line plotting is done by calculating intermediate positions between the two specified endpoint positions.• Linearly varying horizontal and vertical deflection voltages are generated in proportion to the required changes in x, y directions to produce the smooth line.• A straight line segment is displayed by plotting the discrete points between endpoint positions. – These intermediate positions are calculated from the equation of the line – Colour intensity is loaded into the frame buffer at the corresponding pixel coordinate
- 8. Line Scan-Conversion…1• Screen locations are referenced with integer values. E.g. (10.48, 20.51) will be converted to pixel position (10, 20)• This rounding effect causes lines to be displayed with a stairstep appearance . This is noticeable on low resolution systems.• Better smoothing can be achieved by adjusting light intensities along the line paths.
- 9. Line Scan-Conversion…2• Pixel column number is basically pixel position across a scan line. These are increasing from left to right.• Scan line number are increasing from bottom to top. • Loading a specified colour into frame Scan Line No buffer at a pixel position defined by column ‘x’ along scan line ‘y’ setPixel (x, y) • Current frame-buffer intensity for a specified location can be accomplished 2 1 getPixel (x, y) 0 0 12 Pixel column No
- 10. Line Scan-Conversion…3• Line is defined by two end points P1, P2 and the equation of line as shown in the Figure• These can be plotted or scan-converted using different line plotting algorithms. y • The slope-intercept equation is P2(x2, y2) not suitable for vertical lines. y = m.x + b Horizontal, vertical and diagonal (|m| = 1) lines can be handled P1 (x1, y1) as special cases and can be mapped to image space b straightforward. x
- 11. Line Drawing Algorithms• Direct use of line equation• DDA algorithm• Bresenham’s Line Algorithm
- 12. Direct use of Line equation• Direct approach y2 – The Cartesian slope intercept equation for a straight line: y1 y=m.x+b (1) x1 x2 – ‘m’ represents slope of the line and ‘b’ is intercept on y-axis, such that y2 y 2 y1 y1 m (2) x2 x1 x1 x2 b y1 m . x1 (3)
- 13. Direct use of Line equation..1• For a small change in ‘x’ • For lines with slope along the line, the magnitudes |m|<1, x corresponding change is set proportional to in ‘y’ can be given by small horizontal y = m . x (4) deflection voltage and or x = y/m (5) the corresponding – These equations form vertical deflection is the basis for determining then set proportional to the deflection voltages y as calculated from in analog devices. the equation (4).
- 14. Direct use of Line equation…2• For lines with slope • For lines with slope magnitudes |m|>1, y magnitudes m=1, x = is set proportional to a y and the horizontal small vertical deflection and vertical deflection voltage and the voltage are equal corresponding horizontal deflection is then set proportional to x as calculated from the equation (5).
- 15. Direct use of Line equation…3• This means: – First scan convert end points to pixel locations (x1’, y1’) and (x2’, y2’) – Set ‘m’ and ‘b’ using equations – For |m| 1, for integer value of x between and excluding x1’, x2’, calculate the corresponding value of y and scan- convert (x, y) – For |m|> 1, for integer value of y between and excluding y1’, y2’, calculate the corresponding value of x and scan- convert (x, y)
- 16. Direct use of Line equation…4• Example: – End points are (0, 0) and (6, 18). Compute each value of x as y steps from 0 to 18 and plot. • For equation y = m.x + b, compute slope as – m = y/x • Using value of ‘m’ compute ‘b’ • Place y = 1 to 17 and compute corresponding value of ‘x’ • Plot
- 17. Direct use of Line equation…5• Example: – M = (18 – 0) /(6 – 0) = 3 m>1 b=0 – Change y: compute for y = 1 the value of x = ∆y/m = 1/3 • Cartesian coordinate point (1, 0.3) • Pixel coordinate point (Case-I): (1, 0) • Pixel coordinate point (Case-II): (1, 0) – Compute for y = 2 the value of x = 2/3 • Cartesian coordinate point (1, 0.67) • Pixel coordinate point (Case-I): (1, 0) • Pixel coordinate point (Case-II): (1, 1) – Plot the three graphs – Continue …..
- 18. Digital Differential Analyzer (DDA)• DDA is an incremental scan-conversion line algorithm based on calculating either x or y as mentioned in line primitives.• Suppose at step ‘i’ the point is (xi, yi) on the line.• For next point (xi+1, yi+1) – yi+1 = yi + y, where y = m x – xi+1 = xi + x, where x = y/m – The process continues until x reaches x2’ (for |m| 1 case) or y reaches y2’ (for |m|> 1 case)
- 19. Digital Differential Analyzer…1• Consider a line with positive slope. Let the slope be less than or equal to 1. For unit interval x=1, yk+1 = yk + m, where k = 1, 2, …., end point (6) – The value of yk+1 should be rounded to the nearest integer• For slope greater than 1, increasing y by 1 xk+1 = xk + 1/m, where k = 1, 2, …., end point (7) – The value of xk+1 should be rounded to the nearest integer
- 20. Digital Differential Analyzer…2• The assumption here is that lines are processed from left to right. If it is processed from right to left then yk+1 = yk – m (8) y xk+1 = xk – 1/m (9) x
- 21. Digital Differential Analyzer…3• For negative slope of line as shown in figure: • If moving from left to right: – Set x = +1 and use equation (8) for m<1 to calculate y values – Set y = -1 and use equation (7) for m>1 to calculate x values • If moving from right to left: y – If m < 1 then set x = -1 and obtain y values from equation (6) – If m > 1 then set y = +1 and obtain x values from equation (9) x
- 22. Digital Differential Analyzer…4• This algorithm is faster in calculating pixel positions• It eliminates multiplication by making use of raster characteristics• But rounding off in successive additions and its accumulation may cause drifting of the pixel position away from the true line• This rounding off procedure is also time consuming• By converting m or 1/m into integer or fractional part, the time consumed can be reduced.
- 23. Bresenham’s Line Algorithm• This raster-line generating algorithm is more accurate and efficient• It uses only incremental integer calculations• It can be adapted to display circles and other curves.• The method is based on identifying the nearest pixel position closer to the line path at each sample step. 13 53 12 52 11 51 10 50 Fig-1 Fig-2 10 11 12 13 50 51 52 53
- 24. Bresenham’s Line Algorithm…1• In Fig 1 the line segment 13 starts from scan line 11 12 and pixel position 11 (column) 10. The next 10 point along the line may Fig-1 10 11 12 13 be at pixel position (11, 11) or (11, 12) 53• Similarly, in Fig 2 the line 52 segment starts from (50, 51 52) and the next pixel 50 Fig-2 position may be (51, 52) 50 51 52 53 or (51, 51)
- 25. Bresenham’s Line Algorithm…2• Bresenham’s line algorithm tests the sign of an integer parameter and the one whose value is proportional to the difference between the separations of the two pixel positions from the actual line path is selected.• Let the line starts from left-end k+3y point (xo, yo) of a given line. Now, y k+2 the pixel whose scan-line y value y k+1 is closest to the line path is plotted. y k xk xk+1 xk+2 xk+3 Fig-3
- 26. Bresenham’s Line Algorithm…3• Let the pixel displayed is (xk, yk). The next pixel to plot will be in column xk+1 and may be represented as (xk+1, yk) or (xk+1, yk+1) y k+3• The difference between estimated y k+2 y = m.x + b value of y and new y value along the y k+1 d 2 line is to be computed. y d 1 k For first point yest =m . (xk+1) + b (10) x k xk+1 xk+2 xk+3 Difference d1 = yest – yk (11) Fig-3 For second point d2 = (yk+1) – yest (12) Difference between the two separations = d1 – d2
- 27. Bresenham’s Line Algorithm…4• Difference (d1 – d2) = 2m.(xk+1) – 2 yk + 2b – 1 (13)• Let m = y/x denoting vertical and horizontal separations. Let px is defined as y k+3 px = x (d1 – d2) yk+2 y = m.x + b px = 2 y . xk - 2 x . yk + c (14) yk+1 d2 Where, c = 2 y + x (2b – 1) (15) yk d1• Decision parameter px is –ve i.e. d1<d2 xk xk+1 xk+2 xk+3 – Pixel at yk is closer to line than that at yk+1 Fig-3 – Lower point will be plotted – Vice-Versa
- 28. Bresenham’s Line Algorithm…5• The change in coordinate along the line takes place in unit steps. The decision parameter at next step will be: pk+1 = 2y . xk+1 - 2 x . yk+1 + c And pk+1 – pk = 2 y (xk+1 – xk) - 2 x (yk+1 – yk) (16) But xk+1 = xk+1, so that pk+1 = pk + 2 y - 2 x (yk+1 – yk) (17) (yk+1 – yk) is either 0 or 1 depending upon the sign of pk. The initial value of parameter will be po = 2 y - x (18)
- 29. Bresenham’s Line Algorithm…6• Algorithm for |m|<1: (steps) – Input and store (xo, yo). Plot it (load on buffer). – Calculate x, y, 2 y - 2 x – Compute decision parameter, po (= 2 y - x) – Assuming pk < 0, the next point will be (xk+1, yk) and pk+1 = pk + 2y Otherwise, plot point (xk +1, yk +1) and pk+1 = pk + 2 y - 2 x – Repeat step x times
- 30. Bresenham’s Line Algorithm…7• E.g. Plot a line with end points (20, 10) and (30, 18). The slope of line is 0.8. – Calculate x (=10), y (=8) – Compute decision parameter, po (= 2 y - x = 6) – Compute 2 y (=16), 2 y - 2 x (= -4) – Assuming pk < 0, the next point will be (xk+1, yk) and pk+1 = pk + 2y Otherwise, plot point (xk +1, yk +1) and pk+1 = pk + 2 y - 2 x – Repeat step x times
- 31. Bresenham’s Line Algorithm…8• It is generalized to lines with arbitrary slopes.• Considers symmetry between octants and quadrants of the xy plane.• Algorithm allows moving along pixel position from either end of the line.• For positive slope and start from left end point, both the increments are positive. It is vice-versa for start from right end point.• For negative slope, one increment will be positive and other negative depending upon the start point.
- 32. Bresenham’s Line Algorithm…9• When the two vertical separations from the line path are equal (d1 = d2), we choose upper (or lower) of the two candidate pixels.• Special cases like y = 0 (horizontal line); x = 0 (vertical line) and |x| = |y| (diagonal line) can be loaded directly into the frame buffer without processing them through the line –plotting algorithm.
- 33. Bresenham’s Line Algorithm…10• For negative slope of a line (|m|<1) – When moving from left to right – Po = - 2∆y - ∆x – If po is – ve point will be (xk+1, yk) and pk+1 = po - 2 ∆y – If po is + ve point will be (xk+1, yk-1) and pk+1 = po - 2 ∆y - 2 ∆x
- 34. Bresenham’s Line Algorithm…11• For negative slope of a line (|m|<1) – When moving from right to left – Po = 2∆y + ∆x – If po is – ve point will be (xk-1, yk) and pk+1 = po - 2 ∆y – If po is + ve point will be (xk-1, yk+1) and pk+1 = po + 2 ∆y + 2 ∆x
- 35. Bresenham’s Line Algorithm…12 y = m. x + b• For negative slope of a line (|m|>1) yk+3 – Increment is ∆y yk+2 d1 d2 – When moving from left to right yk+1 – ∆x = ∆y/m or (1/m) = ∆x/ ∆y yk – d1 = xest - xk xk xk+1 xk+2 xk+3 – d1 = (1/m)(yk+1 – b) – xk – d2 = xk+1 – xest – d2 = xk+1 – (1/m)(yk+1 – b) – d1 – d2 = (2/m)(yk + 1) – 2xk – (2b/m) – 1 – pk = ∆y . (d1 – d2) – pk = 2 ∆x . yk - 2 ∆y . xk + 2 ∆x (1-b) - ∆y
- 36. Bresenham’s Line Algorithm…13 y = m. x + b• For negative slope of a line (|m|>1) yk+3 – When moving from left to right yk+2 d1 d2 – pk = 2 ∆x . yk - 2 ∆y . xk + 2 ∆x (1-b) - ∆y yk+1 – pk = 2 ∆x . yk - 2 ∆y . xk + c yk – Where c = 2 ∆x (1-b) - ∆y xk xk+1 xk+2 xk+3 – When pk ≤ 0, then d1 < d2 point (xk, yk+1) – When pk > 0, then d1 > d2 point (xk+1, yk+1) – Now, pk+1 = 2 ∆x . yk+1 - 2 ∆y . xk+1 + c – pk+1 – pk = 2 ∆x . (yk+1 – yk) - 2 ∆y . (xk+1 –xk) – pk+1 = pk+2 ∆x . (yk + 1 – yk) - 2 ∆y . (xk+1 –xk)
- 37. Bresenham’s Line Algorithm…14 y = m. x + b• For negative slope of a line (|m|>1) yk+3 – When moving from left to right yk+2 d1 d2 – pk+1 = pk + 2 ∆x . (yk + 1 – yk) - 2 ∆y . (xk+1 y k) –x k+1 – pk+1 = pk + 2 ∆x - 2 ∆y . (xk+1 –xk) yk – Now, if pk+1 ≤ 0, then d1 < d2 point (xk, yk+1) xk xk+1 xk+2 xk+3 – Decision parameter pk+1 = pk + 2 ∆x – When pk+1 > 0, then d1 > d2 point (xk+1, yk+1) – Decision parameter pk+1 = pk + 2 ∆x - 2∆y – Initial decision parameter po = 2 ∆x - ∆y
- 38. Bresenham’s Line Algorithm…15 y = m. x + b• For negative slope of a line (|m|>1) yk+3 – When moving from left to right yk+2 d1 d2 – Steps: yk+1 – Initial decision parameter po = 2 ∆x - ∆y yk – If ≤ 0, then point (xk, yk+1) and xk xk+1 xk+2 xk+3 Decision parameter pk+1 = pk + 2 ∆x – If > 0, then point (xk+1, yk+1) and Decision parameter pk+1 = pk + 2 ∆x - 2∆y – For other orientations or start from right to left, change the sign of ∆x and ∆y based on change in value of respective x or y
- 39. Bresenham’s Line Algorithm…16• Example: Line 6x + 5y = 30 – Points are (0, 6) and (5, 0) (|m|>1) increment ∆y – ∆x = 5; ∆y = -6; 2 ∆x = 10; 2 ∆y = -12 – po = 2 ∆x + ∆y = 10 - 6 = 4 point (1, 5) – p > 0; pk+1 = pk + 2 ∆x + 2∆y = 4 + 10 – 12 = 2 point (2, 4) – p2 = 2 + 10 -12 = 0 point (2, 3) – p3 = pk + 2 ∆x = 0 + 10 = 10 point (3, 2) – p4 = 10 + 10 - 12 = 8 point (4, 1) – p5 = 8 + 10 - 12 = 6 point (5, 0)
- 40. Circle Generating Algorithms• Properties of circle: – A circle is defined as the set of points that are all at a given distance r from a center position (xc,yc) – This distance relationship is expressed by the Pythagorean theorem in Cartesian coordinates as (x – xc)2 + (y – yc)2 = r2 (22) – For position of points on a circle • Move from (xc – r) to (xc + r) in unit steps r yc • Calculate corresponding y values as: y = yc ± √(r2 – (xc – x)2 (23) xc
- 41. Circle Generating Algorithms…1• This is not the best method for generating a circle.• One problem with this approach is that it involves considerable computation at each step.• Moreover, the spacing between plotted pixel positions is not uniform• The spacing can be adjusted by interchanging x and y whenever the absolute value of slope of the curve is greater than 1.• This is computationally more cumbersome.
- 42. Circle Generating Algorithms…2• Another approach is to use polar coordinates r and θ, yielding x = xc + r Cos θ (24) y = yc + r Sin θ (25)• Larger angular separations along the circumference can be connected with straight line segments to approximate the circular path.• For a more continues boundary on a raster display, the step size is set at 1/r. This plots pixel positions that are approximately one unit apart.
- 43. Circle Generating Algorithms…3• Computation can be reduced either by – Considering symmetry w.r.t. y-axis for segment in 1st and 2nd quadrant, and then considering symmetry w.r.t. x-axis for segment in 3rd and 4th quadrant or – Considering the symmetry between adjacent octants within a quadrant w.r.t 45o line (-y, x) (y, x) – Therefore calculations are required (-x, y) (x, y) for points between x=0 and x=y 450 and then these are mapped to rest (-x, -y) (x, -y) eight sectors. (-y, -x) (y, -x)
- 44. Circle Generating Algorithm…4
- 45. Circle Generating Algorithms…5• All these procedures require a good deal of computation time• More efficient circle algorithms are based on incremental calculations as in the Bresenham line algorithm• Bresenham’s line algorithm is adapted to circle generation by setting up decision parameters for finding the closest pixel to the circumference at each sampling step• It avoids square-root calculations by comparing the squares of the pixel separation distances
- 46. Midpoint Circle Algorithm• The closest pixel position to the specified circle path is determined by moving unit distance at each step• Let radius is r and screen center position is (xc, yc)• Set up algorithm to calculate pixel positions around a circle path centered at the coordinate origin (0, 0)• To move each calculated position (x, y) to its proper screen position add xc to x and yc to y• Along the circle section from x = 0 to x = y in the first quadrant the slope of the curve varies from 0 to -1
- 47. Midpoint Circle Algorithm…1• To apply the midpoint method, circle function is defined as: fcircle (x, y) = x2 + y2 – r2 (26) Such that fcircle (x, y) < 0, if (x, y) is inside the circle boundary = 0, if (x, y) is on the circle boundary > 0, if (x, y) outside the circle boundary• This becomes the decision parameter for midpoint algorithm
- 48. Midpoint Circle Algorithm…2• Let us consider the midpoint between the two candidate pixels at sampling position xk+1.• After plotting of the pixel at (xk, yk), next to determine is whether the pixel at position (xk+1, yk) along a circular path. or the one at position (xk+1, yk-1) is closer to the circle.• Decision parameter will be: y x +y -r =0 2 2 2 k 1 pk f circle xk 1, yk yk-1 2 Midpoint 2 1 x k 1 2 yk r 2 xk xk + 1 xk + 2 2 (27)
- 49. Midpoint Circle Algorithm…3• If pk<0, this midpoint is inside the circle and the pixel on scan line yk is closer to the circle boundary.• Otherwise, the mid position is outside or on the circle boundary, and we select the pixel on scanline yk-1.• Successive decision parameters are obtained using incremental calculations. For pixel location (xk+1+ 1) p k 1 p k 2(x k 1) ( y 2 1 y 2 ) ( y k 1 y k ) 1 k k (28)• yk+1 is either yk or yk-1 depending on the sign of pk
- 50. Midpoint Circle Algorithm…4• Increments for obtaining pk+1 are either 2xk+1 +1 (if pk is negative) or (2xk+1 + 1 - 2yk+1)• Evaluation of the terms 2xk+1 and 2yk+1 can also be done incrementally as 2xk+1 = 2xk + 2; 2yk+1 = 2yk - 2• At the start position (0, r) these two terms have the values 0 and 2r, respectively.• Each successive value is obtained by adding 2 to the previous value of 2x and subtracting 2 from the previous value of 2y.
- 51. Midpoint Circle Algorithm…5• The initial decision parameter is obtained by evaluating the circle function at the start position (x0, y0) = (0, r) as: 1 p0 f cricle 1, r 2 2 1 1 r r 2 2 5 p0 r (29) 4• If the radius r is specified as an integer, we can simply or round to p0 = 1 – r (for r an integer).
- 52. Steps• Input radius r, circle center (xc, yc), and obtain the first point on the circumference of a circle centered at the origin as (x0, y0) = (0, r)• Calculate the initial value of the decision parameter as p0 = 5/4 – r• At each xk position, starting at k = 0, perform the following test: if pk < 0, the next point along the circle centered on (0,0) is (xk+1 , yk) and pk+1 = pk + 2xk+1 + 1• Otherwise, the next point along the circle is (xk+1, yk-1) and pk+1 = pk + 2xk+1 + 1 - 2yk+1 Where 2xk+1 = 2x k + 2 and 2yk+1 = 2y k - 2• Determine symmetry points in the seven other octants• Move pixel position (calculated) to screen position by adding
- 53. Example• Plot the generated pixel positions for a circle with radius r = 10 using midpoint circle algorithm. – po = 1 – r = -9 y y=x – Initial point (0, 10) 10 – Decision parameters 9 8 2xo = 0; 2yo = 20 7 6 5 4 3 2 1 0 x 0 1 2 3 4 5 6 7 8 9 10
- 54. BRESENHAM’S ALGORITHM• Assume that (xi, yi) are the coordinates of the last scan- converted pixel upon entering step i.• Let the distance from the origin to pixel T squared minus the distance to the true circle squared = D(t).• Then let the distance from the origin to pixel S squared minus the distance to the true circle squared = D(s).• As the coordinates of T are (xi + 1, yi) and those of S are (xi + 1, yi -1), the following expression can be developed:
- 55. BRESENHAM’S ALGORITHM…1 (xi, yi) T (xi + 1, yi) y (xi, + 1, yi - 1) S 2 i y )2 r 1 i (x xi 12 yi 12 x Choosing Pixels in Bresenham’s Circle Algorithm
- 56. BRESENHAM’S ALGORITHM…2 D(t) = (xi + 1)2 + yi2 - r2 D(s) = (xi+1)2 + (yi – 1)2 – r2• This function D provides a relative measurement of the distance from the center of a pixel to the true circle.• Since D(t) will always be positive (T is outside the true circle) and D(s) will always be negative (S is inside the true circle), a decision variable, di may be defined as follows: di = D(t) + D(s)Therefore di = 2(xi + 1)2 + yi2 + (yi – 1)2 – 2r2
- 57. BRESENHAM’S ALGORITHM…3• When di<0, |D(t)|<|D(s)|, then select pixel T.• When di ≥ 0, |D(t) ≥ |D(s)|, then select pixel S.• The decision variable di+1 for the next step: di+1 = 2(xi+1+1)2 + y2i+ 1 + (yi+1-1)2 – 2 r2Hence di+1- di = 2(xi+1 + 1)2 + y2i+1 + (yi+1 - 1)2 – 2(xi + 1)2 – y2i – (yi – 1)2Since xi+1 = xi + 1 so, di+1 = di + 4xi + 2(y2i+1 – y2i) – 2(yi+1 - yi) + 6
- 58. BRESENHAM’S ALGORITHM…4• If T is the chosen pixel (di < 0) then yi+1=yi and so di+1 = di + 4xi + 6• If S is the chosen pixel (di ≥ 0) then yi+1 = yi-1and so di+1 = di + 4(xi–yi) + 10• Set (0, r) to be the starting pixel coordinates and compute the base case value di : d1 = 2 (0 + 1)2 + r2 + (r – 1)2 – 2r2 = 3- 2r
- 59. Example• Given a radius of 10 units.• Compute di = 2(xi+1)2 + yi2+(yi-1)2-2r2.• Set the value as (0,r) as the start point d0 = 2(0+1)2 + 102 + 10-1)2 - 2x102 = 2+100+81-200 = 183-200 = -17. Or = 3 – 2r = 3 – 20 = -17
- 60. Example…1• As d0 < 0, yi+1=yi.• So next point (1,10) d1 = d0 + 4xi + 6. = - 17+ 4 + 6 = -7• So next point is (2, 10). d2 = d1 + 4x2+6 = -7+8+6. =+7.
- 61. Example…2• So next point (3, 9). d3 = di+4(xi-yi)+10 = 7+4(3-9)+10 = 7-24+10 = -7.• So next point (4, 9) d4 = -7+16+6 = 15.• So next point (5, 8). d5 = 15+4(5-8)+10 = 13.
- 62. Example…3• So next point (6,7). d6 = 13+4x(6-7)+10 = 19. So next point is (7,6)
- 63. ComparisonIteration Mid point Bresenham 0 (0,10) (0,10) 1 (1,10) (1,10) 2 (2,10) (2,10) 3 (3,10) (3,9) 4 (4,9) (4,9) 5 (5,9) (5,8) 6 (6,8) (6,7) 7 (7,7) (7,6)
- 64. Coordinate Representations• General graphics packages are designed to be used with Cartesian Coordinate specifications.• If coordinate values for a picture are specified in some other reference frame, they must be converted to Cartesian system.• Several different Cartesian reference frames are used to construct and display a scene: – Modeling or local coordinates – World coordinates – Device or screen coordinates• Graphics system first converts world coordinates to normalized coordinates before final conversion to device coordinates. 64
- 65. Coordinate Representations Modeling TransformationsModeling Coordinates 65
- 66. FRAME BUFFERA frame buffer is a video output device that drives a video display from amemory buffer containing a complete frame of data. The information in thememory buffer typically consists of color values for every pixel (point that can bedisplayed) on the screen.Color values are commonly stored in 1-bit binary (monochrome), 4-bit palettized,8-bit palettized, 16-bit highcolor and 24-bit truecolor formats.The total amount of the memory required to drive the frame buffer depends onthe resolution of the output signal, and on the color depth and palette size. 66
- 67. Loading Frame Buffer• When objects are scan converted for display with raster system, frame buffer positions must be calculated.• Scan conversion algorithms generate pixel positions at successive unit intervals, this allows the use of incremental methods to calculate frame buffer addresses.• This is accomplished with setPixel procedure, which stores intensity values for the pixels at the corresponding addresses within the frame-buffer array. 67
- 68. Frame-buffer array is addressed in row-major order Pixel screen positions stored linearly in row- major order within the frame buffer For 1 bit per pixel, the frame buffer address for pixel position (x,y) is calculated as addr(x,y)=addr(0,0)+y(xmax+1)+xaddr(x+1,y)=addr(x,y)+1addr(x+1,y+1)=addr(x,y)+xmax+2 68
- 69. SOFTWARE STANDARDS The primary goal is portability among the graphics softwares. Without standards, programs designed for one hardware system can not be transferred to another system without extensive rewriting of programs. Several Int. & national standards planning organizations have cooperated and developed Graphical Kernel System (GKS). The is adopted by Int. Standards organisation (ISO) and American National Standards Institute (ANSI). Other system is PHIGS (Programmer’s Hierarchial Interactive Graphics Standard), which is extension of GKS. PHIGS+ is developed to provide 3D surface-shading. Standard graphics functions are defined as a set of specifications that is in- dependent to any programming language.PHIGS polyline(n,x,y)Fortran call gpl(n,x,y)C ppolyline (n,pts) 69

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment