scan conversion of point , line and circle

Preview:

DESCRIPTION

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

Citation preview

Lecture Outline

• Scan Conversion

– Point

– Line

– Circle

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.

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.

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)

Point Scan…3

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)

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

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.

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 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 getPixel (x, y)

Pixel

column No

Scan L

ine N

o

0

0 1 2

1 2

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.

• The slope-intercept equation is not suitable for vertical lines. Horizontal, vertical and diagonal (|m| = 1) lines can be handled as special cases and can be mapped to image space straightforward.

y

b

y = m.x + b

P1 (x1, y1)

P2(x2, y2)

x

Line Drawing Algorithms

• Direct use of line equation

• DDA algorithm

• Bresenham’s Line Algorithm

Direct use of Line equation

• Direct approach

– The Cartesian slope intercept equation for a straight line:

y = m . x + b (1)

– ‘m’ represents slope of the line and ‘b’ is intercept on y-axis, such that

(2)

(3) 11

12

.

12

xmyb

xxm

yy

y1

y2

x1 x2

y1

y2

x1 x2

Direct use of Line equation..1

• For a small change in ‘x’ along the line, the corresponding change in ‘y’ can be given by

y = m . x (4)

or x = y/m (5)

– These equations form the basis for determining the deflection voltages in analog devices.

• For lines with slope magnitudes |m|<1, x is set proportional to small horizontal deflection voltage and the corresponding vertical deflection is then set proportional to y as calculated from the equation (4).

Direct use of Line equation…2

• For lines with slope magnitudes |m|>1, y is set proportional to a small vertical deflection voltage and the corresponding horizontal deflection is then set proportional to x as calculated from the equation (5).

• For lines with slope magnitudes m=1, x = y and the horizontal and vertical deflection voltage are equal

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)

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

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 …..

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)

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

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)

xk+1 = xk – 1/m (9)

x

y

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:

– 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

y

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.

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.

10

11

12

13

10 11 12 13

50

51

52

53

50 51 52 53

Fig-1 Fig-2

Bresenham’s Line Algorithm…1

• In Fig 1 the line segment starts from scan line 11 and pixel position (column) 10. The next point along the line may be at pixel position (11, 11) or (11, 12)

• Similarly, in Fig 2 the line segment starts from (50, 52) and the next pixel position may be (51, 52) or (51, 51)

Fig-1

Fig-2

10

11

12

13

10 11 12 13

50

51

52

53

50 51 52 53

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 point (xo, yo) of a given line. Now, the pixel whose scan-line y value is closest to the line path is plotted.

Fig-3

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

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)

• The difference between estimated value of y and new y value along the line is to be computed.

For first point yest =m . (xk+1) + b (10)

Difference d1 = yest – yk (11)

For second point d2 = (yk+1) – yest (12)

Difference between the two separations = d1 – d2

Fig-3

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

d1

d2

y = m.x + b

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

px = x (d1 – d2)

px = 2 y . xk - 2 x . yk + c (14)

Where, c = 2 y + x (2b – 1) (15)

• Decision parameter px is –ve i.e. d1<d2

– Pixel at yk is closer to line than that at yk+1

– Lower point will be plotted

– Vice-Versa

Fig-3

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

d1

d2

y = m.x + b

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)

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

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

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.

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.

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

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

Bresenham’s Line Algorithm…12

• For negative slope of a line (|m|>1)

– Increment is ∆y

– When moving from left to right

– ∆x = ∆y/m or (1/m) = ∆x/ ∆y

– d1 = xest - xk

– 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

d1 d2

y = m. x + b

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

Bresenham’s Line Algorithm…13

• For negative slope of a line (|m|>1)

– When moving from left to right

– pk = 2 ∆x . yk - 2 ∆y . xk + 2 ∆x (1-b) - ∆y

– pk = 2 ∆x . yk - 2 ∆y . xk + c

– Where c = 2 ∆x (1-b) - ∆y

– 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)

d1 d2

y = m. x + b

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

Bresenham’s Line Algorithm…14

• For negative slope of a line (|m|>1)

– When moving from left to right

– pk+1 = pk + 2 ∆x . (yk + 1 – yk) - 2 ∆y . (xk+1 –xk)

– pk+1 = pk + 2 ∆x - 2 ∆y . (xk+1 –xk)

– Now, if pk+1 ≤ 0, then d1 < d2 point (xk, yk+1)

– 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

d1 d2

y = m. x + b

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

Bresenham’s Line Algorithm…15

• For negative slope of a line (|m|>1)

– When moving from left to right

– Steps:

– Initial decision parameter po = 2 ∆x - ∆y

– If ≤ 0, then point (xk, yk+1) and

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

d1 d2

y = m. x + b

yk

yk+1

yk+2

yk+3

xk xk+1 xk+2 xk+3

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)

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

• Calculate corresponding y values as:

y = yc ± √(r2 – (xc – x)2 (23) xc

yc r

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.

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.

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

– Therefore calculations are required for points between x=0 and x=y and then these are mapped to rest eight sectors.

450

(y, x)

(-x, y)

(-y, x)

(-x, -y) (x, -y)

(-y, -x) (y, -x)

(x, y)

Circle Generating Algorithm…4

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

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

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

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) or the one at position (xk+1, yk-1) is closer to the circle.

• Decision parameter will be:

(27)

Midpoint

x2+y2-r2=0

xk xk + 1 xk + 2

yk-1

yk

along a circular path.

2

1,1 kkcirclek yxfp

22

k2

k r2

1y1x

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)

(28)

• yk+1 is either yk or yk-1 depending on the sign of pk

1)yy()yy()1x(2pp k1k2k

21kkk1k

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.

Midpoint Circle Algorithm…5

• The initial decision parameter is obtained by evaluating the circle function at the start position (x0, y0) = (0, r) as:

(29)

• If the radius r is specified as an integer, we can simply round to p0 = 1 – r (for r an integer).

rp

rr

rfp cricle

4

5

2

11

2

1 ,1

0

2

2

0

or

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

y = x

x

0 1 2 3 4 5 6 7 8 9 10

0

1

2

3

4

5

6

7

8

9

10

y

Example

• Plot the generated pixel positions for a circle with radius r = 10 using midpoint circle algorithm.

– po = 1 – r = -9

– Initial point (0, 10)

– Decision parameters

2xo = 0; 2yo = 20

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:

Choosing Pixels in Bresenham’s Circle Algorithm

(xi + 1, yi)

(xi, + 1, yi - 1)

T (xi, yi)

S

r

y

x

2

2)

1

(

i

i

y

x

2211 ii yx

BRESENHAM’S ALGORITHM…1

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

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 r2

Hence

di+1- di = 2(xi+1 + 1)2 + y2i+1 + (yi+1 - 1)2

– 2(xi + 1)2 – y2i – (yi – 1)2

Since xi+1 = xi + 1 so,

di+1 = di + 4xi + 2(y2i+1 – y2

i) – 2(yi+1 - yi) + 6

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

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

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.

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.

Example…3

• So next point (6,7).

d6 = 13+4x(6-7)+10

= 19.

So next point is (7,6)

Comparison

Iteration 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)

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

Modeling Coordinates

Coordinate Representations

Modeling

Transformations

66

FRAME BUFFER

A frame buffer is a video output device that drives a video display from a

memory buffer containing a complete frame of data. The information in the

memory buffer typically consists of color values for every pixel (point that can be

displayed) 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 on

the resolution of the output signal, and on the color depth and palette size.

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)+x

addr(x+1,y)=addr(x,y)+1

addr(x+1,y+1)=addr(x,y)+xmax+2

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)

Recommended