Unit Ii
Unit Ii
Facilitator: Frank
Course code: CS 8205
Email: [email protected]
Tel:+255757050205
Introduction
Shapes and colors of the objects can be
described internally with pixel arrays or with
sets of basic geometric structures, such as straight
line segments and polygon color areas.
The scene is then displayed either by loading the
pixel arrays into the frame buffer or by scan
converting the basic geometric-structure
specifications into pixel patterns.
Typically, graphics programming packages provide
functions to describe a scene in terms of these basic
geometric structures, referred to as output
primitives, and to group sets of output primitives
into more complex structure.
Output primitive is the basic geometric
structures used to describe scenes.
Each output primitive is specified with input
coordinate data and other information about
the way that object is to be displayed.
Points and straight line segments are the
simplest geometric components of pictures.
Additional output primitives that can be used
to construct a picture include circles and other
conic sections, quadric surfaces, spline
curves and surfaces, polygon color areas,
and character strings.
Scan conversion
A procedure used to digitize or rasterize pixel data
available on frame buffer
The process of representing continuous graphics
object as a collection of discrete pixels is called
scan conversion. For eg a line is defined by its two
end points and the line equation.
Scan-converting a Point
We have already defined that a pixel is collection of
number of points. Thus it does not represent any
mathematical point.
Suppose we wish to display a point C(5.4, 6.5). It
means that we wish to illuminate that pixel, which
contains this point C.
What happens if we try to display C’(5.3, 6.4)?
Well, it also corresponding to the same pixel as
that of C(5.4, 6.5).
Thus we can say that point C(x, y) is
represented by an integer part of X and integer
part of Y. So, we can use the command as
Putpixel(int x, int y);
We normally use right handed Cartesian
coordinate system.
The origin in this system starts at the bottom.
However in case of computer system, due to the
memory organization, the system turns out to
left handed Cartesian system.
Scan-converting a Straight Line
A scan conversion of line locates the
coordinates of the pixels lie on or near an ideal
straight line impaired on 2D raster grid.
A straight line may be defined by two endpoints
and an equation.
The two endpoints are described by and
y k c xk 1
y k 1 c
In general x k & m
m
Disadvantages:
In DDA line drawing algorithm we have to
perform rounding of the float value and this
rounding may cause the line to change
from original pixel position.
Also this rounding requires more time.
Along with the rounding operation it also
involves the floating-point arithmetic
operation, which also requires more time.
Examples
1. Draw a line using DDA using algorithm
i. (2,2) and (9,2)
ii. (2,5) and (2,12)
iii. (5,4) and (12,7)
iv. (5,7) and (10,5)
2. Calculate the points between the starting point
(5, 6) and ending point (8, 12).
Bresenham's Line Algorithm
To remove the drawbacks of DDA
algorithm, Bresenham has given new line
drawing algorithm based on integer
increment/decrement in x and y value.
Sampling at unit x intervals in these examples,
we need to decide which of two possible pixel
positions is closer to the line path at each
sample step.
Figure a Figure b
Starting from the left endpoint shown in Fig. a,
we need to determine at the next sample
position whether to plot the pixel at position
(11, 11) or the one at (11, 12).
Similarly, Fig. b shows-a negative slope-line
path starting from the left endpoint at pixel
position (50, 50). In this one, do we select the
next pixel position as (51,501 or as (51,49)?
These questions are answered with Bresenham's
line algorithm by testing the sign of an integer
parameter, whose value is proportional to the
difference between the separations of the two
pixel positions from the actual line path.
Consider the line having positive slope and
slope value is less than 1.
First the pixel is plotted at co-ordinates
Then the x value is always increased by 1 and
find out whether the y value is incremented by 1 or
not.
So the next pixel position is either
From the line equation we get the original y value
at
as under:
But,
Here from eq. above we can take the decision
whether we have to increase y value or not.
If decision parameter p is < 0 then that
means y is more closer to so we have to
plot
If decision parameter p is > 0 then that
means y is more closer to so we have to
plot
Midpoint =
From
Now
Now let us conclude the initial parameter
For that we have to choose coordinate of starting
point (0,r) put this in (i)
If pk<0 that means midpoint is inside the circle
frank