You are on page 1of 69

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 Scan1
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 Scan2
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 s x < x+1 and y s y < y + 1
will be mapped to pixel location (x, y) (refer Fig a)
Point Scan3
Point Scan4
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 s x < x+0.5 and
y-0.5 s 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-Conversion1
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-Conversion2
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
S
c
a
n

L
i
n
e

N
o

0
0 1 2
1
2
Line Scan-Conversion3
Line is defined by two end points P
1
, P
2
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
P
1
(x
1
, y
1
)
P
2
(x
2
, y
2
)
x
Line Drawing Algorithms
Direct use of line equation
DDA algorithm
Bresenhams 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)
1 1
1 2
.
1 2
x m y b
x x
m
y y
=

=

y
1

y
2

x
1
x
2

y
1

y
2

x
1
x
2

Direct use of Line equation..1
For a small change in x
along the line, the
corresponding change
in y can be given by
Ay = m . Ax (4)
or Ax = Ay/m (5)
These equations form
the basis for determining
the deflection voltages
in analog devices.
For lines with slope
magnitudes |m|<1, Ax
is set proportional to
small horizontal
deflection voltage and
the corresponding
vertical deflection is
then set proportional to
Ay as calculated from
the equation (4).
Direct use of Line equation2
For lines with slope
magnitudes |m|>1, Ay
is set proportional to a
small vertical deflection
voltage and the
corresponding
horizontal deflection is
then set proportional to
Ax as calculated from
the equation (5).
For lines with slope
magnitudes m=1, Ax =
Ay and the horizontal
and vertical deflection
voltage are equal
Direct use of Line equation3
This means:
First scan convert end points to pixel locations (x
1
, y
1
) and
(x
2
, y
2
)
Set m and b using equations
For |m|s 1, for integer value of x between and excluding
x
1
, x
2
, calculate the corresponding value of y and scan-
convert (x, y)
For |m|> 1, for integer value of y between and excluding
y
1
, y
2
, calculate the corresponding value of x and scan-
convert (x, y)

Direct use of Line equation4
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 = Ay/Ax
Using value of m compute b
Place y = 1 to 17 and compute corresponding value of x
Plot
Direct use of Line equation5
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 Ax or Ay as mentioned in
line primitives.
Suppose at step i the point is (x
i
, y
i
) on the line.
For next point (x
i+1
, y
i+1
)
y
i+1
= y
i
+ Ay, where Ay = m Ax
x
i+1
= x
i
+ Ax, where Ax = Ay/m
The process continues until x reaches x
2
(for |m|s 1 case)
or y reaches y
2
(for |m|> 1 case)
Digital Differential Analyzer1
Consider a line with positive slope. Let the slope be
less than or equal to 1. For unit interval Ax=1,
y
k+1
= y
k
+ m, where k = 1, 2, ., end point (6)
The value of y
k+1
should be rounded to the nearest integer
For slope greater than 1, increasing Ay by 1
x
k+1
= x
k
+ 1/m, where k = 1, 2, ., end point (7)
The value of x
k+1
should be rounded to the nearest integer

Digital Differential Analyzer2
The assumption here is that lines are processed from
left to right. If it is processed from right to left then
y
k+1
= y
k
m (8)
x
k+1
= x
k
1/m (9)
x
y
Digital Differential Analyzer3
For negative slope of line as shown in figure:
If moving from left to right:
Set Ax = +1 and use equation (8) for m<1 to calculate y values
Set A y = -1 and use equation (7) for m>1 to calculate x values
If moving from right to left:
If m < 1 then set Ax = -1 and obtain y
values from equation (6)
If m > 1 then set Ay = +1 and obtain x
values from equation (9)

x
y
Digital Differential Analyzer4
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.
Bresenhams 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
Bresenhams Line Algorithm1
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
Bresenhams Line Algorithm2
Bresenhams 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 (x
o
, y
o
) of a given line. Now,
the pixel whose scan-line y value
is closest to the line path is plotted.
Fig-3
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

Bresenhams Line Algorithm3
Let the pixel displayed is (x
k
, y
k
). The next pixel to
plot will be in column x
k+1
and may be represented as
(x
k
+1, y
k
) or (x
k
+1, y
k
+1)
The difference between estimated
value of y and new y value along the
line is to be computed.
For first point y
est
=m . (x
k
+1) + b (10)
Difference d
1
= y
est
y
k
(11)
For second point d
2
= (y
k
+1) y
est
(12)
Difference between the two separations = d
1
d
2
Fig-3
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

d
1

d
2

y = m.x + b
Bresenhams Line Algorithm4
Difference (d
1
d
2
) = 2m.(x
k
+1) 2 y
k
+ 2b 1 (13)
Let m = Ay/Ax denoting vertical and horizontal
separations. Let p
x
is defined as
p
x
= A x (d
1
d
2
)
p
x
= 2 Ay . x
k
- 2 Ax . y
k
+ c (14)
Where, c = 2 Ay + Ax (2b 1) (15)
Decision parameter p
x
is ve i.e. d
1
<d
2

Pixel at y
k
is closer to line than that at y
k
+1
Lower point will be plotted
Vice-Versa
Fig-3
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

d
1

d
2

y = m.x + b
Bresenhams Line Algorithm5
The change in coordinate along the line takes place
in unit steps. The decision parameter at next step will
be:
p
k+1
= 2Ay . x
k+1
- 2 Ax . y
k+1
+ c
And p
k+1
p
k
= 2 Ay (x
k+1
x
k
) - 2 Ax (y
k+1
y
k
) (16)
But x
k+1
= x
k
+1, so that
p
k+1
= p
k
+ 2 Ay - 2 Ax (y
k+1
y
k
) (17)
(y
k+1
y
k
) is either 0 or 1 depending upon the sign of p
k
.
The initial value of parameter will be
p
o
= 2 Ay - Ax (18)
Bresenhams Line Algorithm6
Algorithm for |m|<1: (steps)
Input and store (x
o
, y
o
). Plot it (load on buffer).
Calculate Ax, Ay, 2 Ay - 2 Ax
Compute decision parameter, p
o
(= 2 Ay - Ax)
Assuming p
k
< 0, the next point will be (x
k
+1, y
k
) and
p
k+1
= p
k
+ 2Ay
Otherwise, plot point (x
k
+1, y
k
+1) and
p
k+1
= p
k
+ 2 Ay - 2 Ax
Repeat step Ax times
Bresenhams Line Algorithm7
E.g. Plot a line with end points (20, 10) and (30, 18).
The slope of line is 0.8.
Calculate Ax (=10), Ay (=8)
Compute decision parameter, p
o
(= 2 Ay - Ax = 6)
Compute 2 Ay (=16), 2 Ay - 2 Ax (= -4)
Assuming p
k
< 0, the next point will be (x
k
+1, y
k
) and
p
k+1
= p
k
+ 2Ay
Otherwise, plot point (x
k
+1, y
k
+1) and
p
k+1
= p
k
+ 2 Ay - 2 Ax
Repeat step Ax times
Bresenhams Line Algorithm8
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.
Bresenhams Line Algorithm9
When the two vertical separations from the line path are
equal (d
1
= d
2
), we choose upper (or lower) of the two
candidate pixels.
Special cases like Ay = 0 (horizontal line); Ax = 0 (vertical
line) and |Ax| = |Ay| (diagonal line) can be loaded
directly into the frame buffer without processing them
through the line plotting algorithm.
Bresenhams Line Algorithm10
For negative slope of a line (|m|<1)
When moving from left to right
P
o
= - 2y - x
If p
o
is ve point will be (x
k+1
, y
k
)
and p
k+1
= p
o
- 2 y
If p
o
is + ve point will be (x
k+1
, y
k-1
)
and p
k+1
= p
o
- 2 y - 2 x

Bresenhams Line Algorithm11
For negative slope of a line (|m|<1)
When moving from right to left
P
o
= 2y + x
If p
o
is ve point will be (x
k-1
, y
k
)
and p
k+1
= p
o
- 2 y
If p
o
is + ve point will be (x
k-1
, y
k+1
)
and p
k+1
= p
o
+ 2 y + 2 x

Bresenhams Line Algorithm12
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
d
1
= x
est
- x
k

d
1
= (1/m)(y
k+1
b) x
k

d
2
= x
k+1
x
est

d
2
= x
k+1
(1/m)(y
k+1
b)
d
1
d
2
= (2/m)(y
k
+ 1) 2x
k
(2b/m) 1
p
k
= y . (d
1
d
2
)
p
k
= 2 x . y
k
- 2 y . x
k
+ 2 x (1-b) - y
d
1

d
2

y = m. x + b
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

Bresenhams Line Algorithm13
For negative slope of a line (|m|>1)
When moving from left to right
p
k
= 2 x . y
k
- 2 y . x
k
+ 2 x (1-b) - y
p
k
= 2 x . y
k
- 2 y . x
k
+ c
Where c = 2 x (1-b) - y
When p
k
0, then d
1
< d
2
point (x
k
, y
k+1
)
When p
k
> 0, then d
1
> d
2
point (x
k+1
, y
k+1
)
Now, p
k+1
= 2 x . y
k+1
- 2 y . x
k+1
+ c
p
k+1
p
k
= 2 x . (y
k+1
y
k
) - 2 y . (x
k+1
x
k
)
p
k+1
= p
k
+2 x . (y
k
+ 1 y
k
) - 2 y . (x
k+1
x
k
)

d
1

d
2

y = m. x + b
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

Bresenhams Line Algorithm14
For negative slope of a line (|m|>1)
When moving from left to right
p
k+1
= p
k
+ 2 x . (y
k
+ 1 y
k
) - 2 y . (x
k+1
x
k
)
p
k+1
= p
k
+ 2 x - 2 y . (x
k+1
x
k
)
Now, if p
k+1
0, then d
1
< d
2
point (x
k
, y
k+1
)
Decision parameter p
k+1
= p
k
+ 2 x
When p
k+1
> 0, then d
1
> d
2
point (x
k+1
, y
k+1
)
Decision parameter p
k+1
= p
k
+ 2 x - 2y
Initial decision parameter p
o
= 2 x - y



d
1

d
2

y = m. x + b
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

Bresenhams Line Algorithm15
For negative slope of a line (|m|>1)
When moving from left to right
Steps:
Initial decision parameter p
o
= 2 x - y
If 0, then point (x
k
, y
k+1
) and
Decision parameter p
k+1
= p
k
+ 2 x
If > 0, then point (x
k+1
, y
k+1
) and
Decision parameter p
k+1
= p
k
+ 2 x - 2y
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


d
1

d
2

y = m. x + b
y
k

y
k+1

y
k+2

y
k+3

x
k
x
k+1
x
k+2
x
k+3

Bresenhams Line Algorithm16
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
p
o
= 2 x + y = 10 - 6 = 4 point (1, 5)
p > 0; p
k+1
= p
k
+ 2 x + 2y = 4 + 10 12 = 2
point (2, 4)
p
2
= 2 + 10 -12 = 0 point (2, 3)
p
3
= p
k
+ 2 x = 0 + 10 = 10 point (3, 2)
p
4
= 10 + 10 - 12 = 8 point (4, 1)
p
5
= 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 (x
c
,y
c
)
This distance relationship is expressed by the Pythagorean
theorem in Cartesian coordinates as
(x x
c
)
2
+ (y y
c
)
2
= r
2
(22)
For position of points on a circle
Move from (x
c
r) to (x
c
+ r) in unit steps
Calculate corresponding y values as:
y = y
c
(r
2
(x
c
x)
2
(23)
x
c

y
c

r
Circle Generating Algorithms1
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 Algorithms2
Another approach is to use polar coordinates r and ,
yielding
x = x
c
+ r Cos (24)
y = y
c
+ 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 Algorithms3
Computation can be reduced either by
Considering symmetry w.r.t. y-axis for segment in 1
st
and
2
nd
quadrant, and then considering symmetry w.r.t. x-axis
for segment in 3
rd
and 4
th
quadrant or
Considering the symmetry between adjacent octants
within a quadrant w.r.t 45
o
line
Therefore calculations are required
for points between x=0 and x=y
and then these are mapped to rest
eight sectors.
45
0

(y, x)
(-x, y)
(-y, x)
(-x, -y)
(x, -y)
(-y, -x) (y, -x)
(x, y)
Circle Generating Algorithm4
Circle Generating Algorithms5
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
Bresenhams 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 (x
c
, y
c
)
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 x
c
to x and y
c
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 Algorithm1
To apply the midpoint method, circle function is
defined as:
f
circle
(x, y) = x
2
+ y
2
r
2
(26)

Such that
f
circle
(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 Algorithm2
Let us consider the midpoint between the two
candidate pixels at sampling position x
k
+1.
After plotting of the pixel at (x
k
, y
k
), next to
determine is whether the pixel at position (x
k
+1, y
k
)
or the one at position (x
k
+1, y
k
-1) is closer to the
circle.
Decision parameter will be:


(27)
Midpoint
x
2
+y
2
-r
2
=0
x
k
x
k
+ 1 x
k
+ 2
y
k
-1
y
k

along a circular path.
|
.
|

\
|
+ =
2
1
, 1
k k circle k
y x f p
( )
2
2
k
2
k
r
2
1
y 1 x |
.
|

\
|
+ + =
Midpoint Circle Algorithm3
If p
k
<0, this midpoint is inside the circle and the pixel
on scan line y
k
is closer to the circle boundary.
Otherwise, the mid position is outside or on the
circle boundary, and we select the pixel on scanline
y
k
-1.
Successive decision parameters are obtained using
incremental calculations. For pixel location (x
k+1
+ 1)
(28)
y
k+1
is either y
k
or y
k-1
depending on the sign of p
k

1 ) y y ( ) y y ( ) 1 x ( 2 p p
k 1 k
2
k
2
1 k k k 1 k
+ + + + =
+ + +
Midpoint Circle Algorithm4
Increments for obtaining p
k+1
are either 2x
k+1
+1 (if p
k

is negative) or (2x
k+1
+ 1 - 2y
k+1
)
Evaluation of the terms 2x
k+1
and 2y
k+1
can also be
done incrementally as
2x
k+1
= 2x
k
+ 2; 2y
k+1
= 2y
k
- 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 Algorithm5
The initial decision parameter is obtained by
evaluating the circle function at the start position
(x
0
, y
0
) = (0, r) as:



(29)
If the radius r is specified as an integer, we can simply
round to p
0
= 1 r (for r an integer).
r p
r r
r f p
cricle
=

|
.
|

\
|
+ =
|
.
|

\
|
=
4
5
2
1
1
2
1
, 1
0
2
2
0
or
Steps
Input radius r, circle center (x
c
, y
c
), and obtain the first point
on the circumference of a circle centered at the origin as (x
0
,
y
0
) = (0, r)
Calculate the initial value of the decision parameter as
p
0
= 5/4 r
At each x
k
position, starting at k = 0, perform the following
test: if p
k
< 0, the next point along the circle centered on (0,0)
is (x
k+1
, y
k
) and p
k+1
= p
k
+ 2x
k+1
+ 1
Otherwise, the next point along the circle is (x
k
+1, y
k
-1) and
p
k+1
= p
k
+ 2x
k+1
+ 1 - 2y
k+1
Where 2x
k+1
= 2x
k
+ 2 and 2y
k+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.
p
o
= 1 r = -9
Initial point (0, 10)
Decision parameters
2x
o
= 0; 2y
o
= 20

BRESENHAMS ALGORITHM
Assume that (x
i
, y
i
) 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 (x
i
+ 1, y
i
) and those of S are
(x
i
+ 1, y
i
-1), the following expression can be developed:
Choosing Pixels in Bresenhams Circle Algorithm
(x
i
+ 1, y
i
)
(x
i
, + 1, y
i
- 1)
T (x
i
, y
i)

S
r
y
x

2
2
)
1
(
i
i
y
x
+
+

( ) ( )
2 2
1 1 + +
i i
y x
BRESENHAMS ALGORITHM1
BRESENHAMS ALGORITHM2
D(t) = (x
i
+ 1)
2
+ y
i
2
- r
2

D(s) = (x
i
+1)
2
+ (y
i
1)
2
r
2

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, d
i
may be defined as
follows:
d
i
= D(t) + D(s)
Therefore
d
i
= 2(x
i
+ 1)
2
+ y
i
2
+ (y
i
1)
2
2r
2
BRESENHAMS ALGORITHM3
When d
i
<0, |D(t)|<|D(s)|, then select pixel T.
When d
i
0, |D(t) |D(s)|, then select pixel S.
The decision variable d
i+1
for the next step:
d
i+1
= 2(x
i+1
+1)
2
+ y
2
i+ 1
+ (y
i+1
-1)
2
2 r
2

Hence
d
i+1
- d
i
= 2(x
i+1
+ 1)
2
+ y
2
i+1
+ (y
i+1
- 1)
2

2(x
i
+ 1)
2
y
2
i
(y
i
1)
2


Since x
i+1
= x
i
+ 1 so,

d
i+1
= d
i
+ 4x
i
+ 2(y
2
i+1
y
2
i
) 2(y
i+1
- y
i
) + 6
BRESENHAMS ALGORITHM4
If T is the chosen pixel (d
i
< 0) then y
i+1
=y
i
and so
d
i+1
= d
i
+ 4x
i
+ 6
If S is the chosen pixel (d
i
0) then y
i+1
= y
i
-1and so
d
i+1
= d
i
+ 4(x
i
y
i
) + 10
Set (0, r) to be the starting pixel coordinates and
compute the base case value d
i
:

d
1
= 2 (0 + 1)
2
+ r
2
+ (r 1)
2
2r
2

= 3- 2r
Example
Given a radius of 10 units.
Compute d
i
= 2(x
i+1
)
2
+ y
i
2
+(y
i-1
)
2
-2r
2.
Set the value as (0,r) as the start point

d
0
= 2(0+1)
2
+ 10
2
+ 10-1)
2
- 2x10
2

= 2+100+81-200
= 183-200
= -17. Or = 3 2r = 3 20 = -17
Example1
As d
0
< 0, y
i+1
=y
i.

So next point (1,10)
d
1
= d
0
+ 4x
i
+ 6.
= - 17+ 4 + 6
= -7
So next point is (2, 10).
d
2
= d
1
+ 4x2+6
= -7+8+6.
=+7.
Example2
So next point (3, 9).
d
3
= d
i
+4(x
i
-y
i
)+10
= 7+4(3-9)+10
= 7-24+10
= -7.
So next point (4, 9)
d
4
= -7+16+6 = 15.
So next point (5, 8).
d
5
= 15+4(5-8)+10 = 13.
Example3
So next point (6,7).
d
6
= 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(x
max
+1)+x

addr(x+1,y)=addr(x,y)+1
addr(x+1,y+1)=addr(x,y)+x
max
+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 (Programmers 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)

You might also like