0% found this document useful (0 votes)
53 views29 pages

Computer Graphics Module-1

This document provides an introduction to computer graphics including: - A brief history tracing foundations to the 1940s Whirlwind Project and SAGE system for military applications. - Definitions of computer graphics as the art of drawing pictures on screens with programming, involving computations, data creation and manipulation to generate and manipulate images. - An overview of typical graphics systems and applications such as interfaces, presentations, mapping, modeling, training simulations, and entertainment. - Descriptions of video display technologies like cathode ray tubes and raster scanning to redraw pictures by directing electron beams across phosphor-coated screens in rows from top to bottom.

Uploaded by

mikiberhanu41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views29 pages

Computer Graphics Module-1

This document provides an introduction to computer graphics including: - A brief history tracing foundations to the 1940s Whirlwind Project and SAGE system for military applications. - Definitions of computer graphics as the art of drawing pictures on screens with programming, involving computations, data creation and manipulation to generate and manipulate images. - An overview of typical graphics systems and applications such as interfaces, presentations, mapping, modeling, training simulations, and entertainment. - Descriptions of video display technologies like cathode ray tubes and raster scanning to redraw pictures by directing electron beams across phosphor-coated screens in rows from top to bottom.

Uploaded by

mikiberhanu41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Mekelle University

EIT-M
School of computing
Computer Science
Courses Title: Computer Graphics

1|Page
Prep and compiled by Luel A
Chapter One
1. Introduction to Computer Graphics and Primitives
1.1 Brief History of Computer Graphics
 The foundations of computer graphics can be traced to artistic and mathematical ``inventions,''

 The history of computer graphics can be dated back to the days of the Whirlwind Project and the
SAGE computer system, which were designed to support military preparedness.

◼ The Whirlwind Project started as an effort to build a flight simulator and SAGE was to
provide an air defense system in the United States to guard against the threat of a nuclear
attack.

◼ The SAGE workstation had a vector display and light pens that operators would use
pinpoint planes flying over regions of the United States.

1.2 Introduction to computer graphics

Today there are very few aspects of our lives not affected by computers. Practically every cash or
monetary transaction that takes place daily involves a computer. In many cases, the same is true of
computer graphics. Whether you see them on television, in newspapers, in weather reports or while at
the doctor’s surgery, computer images are all around you.

“A picture is worth a thousand words” is a well-known saying and highlights the advantages and benefits
of the visual presentation of our data. We are able to obtain a comprehensive overall view of our data
and also study features and areas of particular interest.

A well-chosen graph is able to transform a complex table of numbers into meaningful results. You know
that such graphs are used to illustrate papers, reports and thesis, as well as providing the basis for
presentation material in the form of slides and overhead transparencies. A range of tools and facilities are
available to enable users to visualize their data, and this document provides a brief summary and
overview.

Computer graphics can be used in many disciplines. Charting, Presentations, Drawing, Painting and
Design, Image Processing and Scientific Visualization are some among them.

Definition: Computer graphics is an art of drawing pictures on computer screens with the help of
Programming. It involves computations, creation, and manipulation of data. In other Words, we can say
that computer graphics is a rendering tool for the generation and Manipulation of images
Computer Graphics involves display, manipulation and storage of pictures and experimental data for
proper visualization using computer
Typical graphics system comprises of a host computer with support of fast processor, large memory
frame buffer, Display device, Input device, Output device and interfacing devices
Computer graphics can be divided in to two categories

2|Page
Prep and compiled by Luel A
i. Non Interactive Computer Graphics: In non-interactive computer graphics otherwise known
as passive computer graphics, the observer has no control over the image. Familiar
examples of this type of computer graphics include the titles shown on TV and other forms
of computer art.
ii. Interactive Computer Graphics: Interactive Computer Graphics involves a two way
communication between computer and user. Here the observer is given some control over
the image by providing him with an input device for example the video game controller of the
ping pong game. This helps him to signal his request to the computer. The computer on
receiving signals from the input device can modify the displayed picture appropriately. To the
user it appears that the picture is changing instantaneously in response to his commands. He
can give a series of commands, each one generating a graphical response from the computer.
In this way he maintains a conversation, or dialogue, with the computer.

Interactive computer graphics affects our lives in a number of indirect ways. For example, it
helps to train the pilots of our airplanes. We can create a flight simulator which may help the
pilots to get trained not in a real aircraft but on the grounds at the control of the flight
simulator. The flight simulator is a mockup of an aircraft flight deck, containing all the usual
controls and surrounded by screens on which we have the projected computer generated
views of the terrain visible on takeoff and landing. Flight simulators have many advantages
over the real aircrafts for training purposes, including fuel savings, safety, and the ability to
familiarize the trainee with a large number of the world’s airports

➢ More precisely Computer graphics involves image synthesis:


• How to represent real environments
✓ Geometry: curves, surfaces, volumes
✓ Photometry: light, color, reflectance
• How to build these representations
✓ Interactive: sculpt it
✓ Algorithmic: let it grow (fractals, extraction)
✓ Scanning: via 3D sensing
• Generate primitives
✓ Lines, triangles, quads, patches
✓ Cylinder, spheres
✓ Higher-order primitives
1.3 Application of Computer Graphics
Computer Graphics has numerous applications, some of which are listed below:

➢ Computer graphics user interfaces (GUIs) – A graphic, mouse-oriented paradigm


which allows the user to interact with a computer.
➢ Business presentation graphics - "A picture is worth a thousand words".
➢ Cartography - Drawing maps.
➢ Weather Maps – Real-time mapping, symbolic representations.
➢ Satellite Imaging - Geodesic images.
➢ Photo Enhancement - Sharpening blurred photos.
3|Page
Prep and compiled by Luel A
➢ Medical imaging - MRIs, CAT scans, etc. - Non-invasive internal examination
➢ Engineering drawings - mechanical, electrical, civil, etc. - Replacing the blueprints of the
past.
➢ Typography - The use of character images in publishing - replacing the hard type of the past.
➢ Architecture - Construction plans, exterior sketches - replacing the blueprints and hand
drawings of the past.
➢ Art - Computers provide a new medium for artists.
➢ Training - Flight simulators, computer aided instruction, etc.
➢ Entertainment - Movies and games.
➢ Simulation and modeling - Replacing physical modeling and enactments

1.4 VIDEO DISPLAY DEVICES (Monitors)


Typically, the primary output device in a graphics system is a video monitor. The operation of
most video monitors is based on the standard cathode-ray tube (CRT) design, but several other
technologies exist and solid-state monitors May eventually predominate.
1.4.1 Cathode Ray Tube
The primary output device in a graphical system is the video monitor. The main
Element of a video monitor is the Cathode Ray Tube (CRT), shown in the following
Illustration.
The operation of CRT is very simple:
1. The electron gun emits a beam of electrons (cathode rays).
2. The electron beam passes through focusing and deflection systems that direct it
Towards specified positions on the phosphor-coated screen.
3. When the beam hits the screen, the phosphor emits a small spot of light at each
Position contacted by the electron beam.
4. It redraws the picture by directing the electron beam back over the same screen
Points quickly.

4|Page
Prep and compiled by Luel A
There are two ways (Random scan and Raster scan) by which we can display an object on the screen

1. Raster-scan Displays
In a raster scan system, the electron beam is swept across the screen, one row at a time from top to
bottom. As the electron beam moves across each row, the beam intensity is turned on and off to create
a pattern of illuminated spots.
Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer. This memory area
holds the set of intensity values for all the screen points. Stored intensity values are then retrieved from
the refresh buffer and “painted” on the screen one row (scan line) at a time as shown in the following
illustration. Each screen point is referred to as a pixel (picture element) or pel. At the end of each scan
line, the electron beam returns to the left side of the screen to begin displaying the next scan line.

On some raster-scan systems (and in TV sets), each frame is displayed in two passes using an interlaced
refresh procedure. In the first pass, the beam sweeps across every other scan line from top to bottom.
Then after the vertical retrace, the beam sweeps out the remaining scan lines interlacing of the scan
lines in this way allows us to see the entire screen displayed in one-half the time it would have taken to
sweep across all the lines at once from top to bottom. Interlacing is primarily used with slower
refreshing rates. On an older, 30 frame per second, no interlaced display, for instance, some flicker is
noticeable. But With interlacing, each of the two passes can be accomplished in 1/60th of a second,
which brings the refresh rate nearer to 60 frames per second. This is an effective technique for avoiding
flicker, providing that adjacent scan lines contain similar display information.

Refresh procedure:
➢ Horizontal retrace – beam returns to left of screen
➢ Vertical retrace – bean returns to top left corner of screen
➢ Interlaced refresh – display first even-numbered lines, then odd-numbered lines
Permits to see the image in half the time. Useful for slow refresh rates (30 Hz shows as 60 Hz)
2. Random Scan (Vector Scan)
5|Page
Prep and compiled by Luel A
In this technique, the electron beam is directed only to the part of the screen where the picture is to be
drawn rather than scanning from left to right and top to bottom as in raster scan. It is also called vector
display, stroke-writing display, or Calligraphic display. Picture definition is stored as a set of line-drawing
commands in an area of memory Referred to as the refresh display file. To display a specified picture, the
system cycles through the set of commands in the display file, drawing each component line in turn. After
all the line-drawing commands are processed, the system cycles back to The first line command in the list.
Random-scan displays are designed to draw all the component lines of a picture 30 to 60 times each
second
❖ Images are described in terms of line segments rather than pixels

Random-scan systems are designed for line drawing applications and cannot display realistic shaded
scenes. Since picture definition is stored as a set of line drawing instructions and not as a set of intensity
values for all screen points, vector displays generally have higher resolution than raster systems. Also,
vector displays produce smooth line drawings because the CRT beam directly follows the line path. A
raster system, in contrast, produces jagged lines that are plotted as discrete point sets.

1.4.2 Color CRT Monitors


A CRT monitor displays color pictures by using a combination of phosphors that emit different-colored
light. By combining the emitted light from the different phosphors, a range of colors can be generated.
The two basic techniques for producing color displays with a CRT are the beam-penetration method and
the shadow-mask method. The beam-penetration method for displaying color pictures has been used

6|Page
Prep and compiled by Luel A
With random-scan monitors. Two layers of phosphor, usually red and green, are coated onto the inside of
the CRT screen, and the displayed color depends on how far the electron beam penetrates into the
phosphor layers. A beam of slow electrons excites only the outer red layer.

1.4.3 Flat-Panel Displays


Although most graphics monitors are still constructed with CRTs, other technologies are emerging that
may soon replace CRT monitors. The term Bat-panel display refers to a class of video devices that have
reduced volume, weight, and power requirements compared to a CRT. A significant feature of flat-panel
displays is that they are thinner than CRTs, and we can hang them on walls or wear them on our wrists.
Since we can even write on some flat-panel displays, they will soon be available as pocket notepads.
Current uses for flat-panel displays include small TV monitors, calculators, pocket video games, laptop
computers, armrest viewing of movies on airlines, as advertisement boards in elevators, and as graphics
displays in applications requiring rugged, portable monitors.
We can separate flat-panel displays into two categories: emissive displays and none missive displays.
The emissive displays (or emitters) are devices that convert electrical energy into light. Plasma panels,
thin-film electroluminescent displays, and Light-emitting diodes are examples of emissive displays. Flat
CRTs have also been devised, in which electron beams arts accelerated parallel to the screen, then
deflected 90' to the screen. But flat CRTs have not proved to be as successful as other emissive devices.
Non emissive displays (or non-emitters) use optical effects to convert sunlight or light from some other
source into graphics patterns. The most important example of a non-emissive flat-panel display is a
liquid-crystal device.
Liquid crystal display (LCDS): are commonly used in small systems, such as calculators and portable,
laptop computers. These non-emissive devices produce a picture by passing polarized light from the
surroundings or from an internal light source through a liquid-crystal material that can be aligned to
either block or transmit the light.

Summery:

In this chapter, we have surveyed the major hardware and software features of computer graphics
systems. Hardware components include video monitors, hard-copy devices, keyboards, and other devices
for graphics input or output. Graphics software includes special applications packages and general
programming packages. The predominant graphics display device is the raster refresh monitor, based on
television technology. A raster system uses a frame buffer to store intensity in formation for each screen
position (pixel). Pictures are then painted on the screen by retrieving this information from the frame
buffer as the electron beam in the CRT sweeps across each scan line, from top to bottom. Older vector
displays construct pictures by drawing lines between specified line endpoints. Picture information is then
stored as a set of line-drawing instructions.
Many other video display devices are available. In particular, flat-panel display technology is
developing at a rapid rate, and these devices may largely replace raster displays in the near future. At
present, flat-panel displays are commonly used in small systems and in special-purpose systems. Flat-
panel displays include plasma panels and liquid-crystal devices. Although vector monitors can be used to
display high-quality line drawings, improvements in raster display technology have caused vector
monitors to be largely replaced with raster systems.

7|Page
Prep and compiled by Luel A
Chapter two
Graphics output primitive and Attributes
2.1 Output Primitives
A picture can be described in several ways. Assuming we have a raster display, a picture is completely
specified by the set of intensities for the pixel positions in the display. At the other extreme, we can
describe a picture as a set of complex objects, such as trees and terrain or furniture and walls, positioned
at specified coordinate locations within the scene. 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 structures.
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.

2.1.1 Points and Lines


Point plotting is accomplished by converting a single coordinate position furnished by an application
program into appropriate operations for the output device in use. With a CRT monitor, for example, the
electron beam is turned on to illuminate the screen phosphor at the selected location. How the electron
beam is positioned depends on the display technology. A random-scan (vector) system stores point-
plotting instructions in the display list, and coordinate values in these instructions are converted to
deflection voltages that position the electron beam at the screen locations to be plotted during each
refresh cycle. For a black and white raster system, on the other hand, a point is plotted by setting the bit
value corresponding to a specified screen position within the frame buffer to 1. Then, as the electron
beam sweeps across each horizontal scan line, it emits a burst of electrons (plots a point) whenever a
value of I is encountered in the frame buffer. With an RGB system, the frame buffer is loaded with the
color codes for the intensities that are to be displayed at the s m n pixel positions.

Line drawing is accomplished by calculating intermediate positions along the line path between two
specified endpoint positions. An output device is then directed to fill in these positions between the
endpoints. For analog devices, such as a vector pen plotter or a random-scan display, a straight line can
be drawn smoothly from one endpoint to the other. Linearly varying horizontal and vertical deflection
voltages are generated that are proportional to the required changes in the x and y directions to produce
the smooth line. Digital devices display a straight line segment by plotting discrete points
Between the two endpoints. Discrete coordinate positions along the line path are calculated from the
equation of the line. For a raster video display, the line color (intensity) is then loaded into the frame
buffer at the corresponding pixel coordinates. Reading from the frame buffer, the video controller then
"plots" the screen pixels. Screen locations are referenced with integer values, so plotted positions
May only approximate actual Line positions between two specified endpoints. A computed line position
of (10.48, 20.51), for example, would be converted to pixel position (10,211. Thus rounding of coordinate
values to integers causes lines to be displayed with a stair step appearance ("the jaggies"). The
characteristic stair step shape of raster lines is particularly noticeable on systems with low resolution, and

8|Page
Prep and compiled by Luel A
we can improve their appearance somewhat by displaying them on high-resolution systems. More
effective techniques for smoothing raster lines are based on adjusting pixel intensities along the line paths.
2.2 LINE-DRAWING ALGORITHMS
The Cartesian slope-intercept equation for a straight line is

(2-1)

With m representing the slope of the line and b as the y intercept.


s
Given that the two end points of a line segment are specified at positions (x1, y1) and (x2, y2), we
can determine values for the slope m and y intercept b with
The following calculations:

(2-2)

Algorithms for displaying straight lines are based on the line equation 2-1 and
The calculations given in Eqs. 2-2.
For any given x interval ∆x along a line, we can compute the corresponding
∆y interval from eq.2-2 as

(2-3)

Similarly, we can obtain the x interval ∆x corresponding to a specified ∆y as

(2-4)
These equations form the basis for determining deflection voltages in analog device

For lines with slope magnitudes I m I < 1, ∆x can be set proportional to a small horizontal deflection
voltage and the corresponding vertical deflection is then set proportional to Ay as calculated from Eq. 3-
4. For lines whose slopes have magnitudes | m | > 1, ∆y can be set proportional to a small vertical
deflection voltage with the corresponding horizontal deflection voltage set proportional to ∆x,
calculated from Eq. 3-5. For lines with m = 1, Ax = Ay and the horizontal and vertical deflections voltages
are equal. In each case, a smooth line with slope m is generated between the specified endpoints.

On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions
are constrained by pixel separations. That is, we must "sample" a line at discrete positions and
determine the nearest pixel to the line at each sampled position.

9|Page
Prep and compiled by Luel A
2.2.1 DDA Algorithm

The digital deferential analyzer (DDA) is a scan-conversion line algorithm based on calculating either ∆y
or ∆x, using Eq. 3-4 or Eq. 3-5. We sample the line at unit intervals in one coordinate and determine
corresponding integer values nearest the line path for the other coordinate.

Consider first a line with positive slope, as shown in Fig. 3-3. If the slope is Less than or equal to 1, we
sample at unit x intervals (∆x = 1) and compute each Successive y value as

2-5

Subscript k takes integer values starting from 1, for the first point, and increases
By 1 until the final endpoint is reached. Since m can be any real number between
0 and 1, the calculated y values must be rounded to the nearest integer. For lines with a positive slope
greater than 1, we reverse the roles of x and y. That is, we sample at unit y intervals (∆y = 1) and
calculate each succeeding x Value as

(2-6)

10 | P a g e
Prep and compiled by Luel A
Equations 3-6 and 3-7 are based on the assumption that lines are to be processed from the left endpoint
to the right endpoint (Fig. 2-6). If this processing Is reversed, so that the starting endpoint is at the right,
then either we have ∆x = -1 and

(2-7)

(2-8)

Equations 2-6 through 2-8 can also be used to calculate pixel positions along a line with negative slope.
If the absolute value of the slope is less than I and the start endpoint is at the left, we set ∆x = 1 and
calculate y values with Eq. 2-6.
When the start endpoint is at the right (for the same slope), we set Ax = -1 and obtain y positions from
Eq. 2-8. Similarly, when the absolute value of a negative slope is greater than 1, we use dy = -1 and Eq. 2-
8 or we use dy = 1 and Eq. 2-7.

Note: ∆x=dx, ∆y=dy

Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm
Which is explained step by step here.

Step 1: Get the input of two end points (X0, Y0) and (X1, Y1).
Step 2: Calculate the difference between two end points.
Dx = X1 - X0
Dy = Y1 - Y0
Step 3: Based on the calculated difference in step-2, you need to identify the number of steps to put
pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
if (dx > dy)
Steps = absolute (dx);
else
Steps = absolute (dy);
Step 4: Calculate the increment in x coordinate and y coordinate.
Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;
step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete the
drawing of the line.
For (int v=0; v < Steps; v++)
{
x = x + Xincrement;

11 | P a g e
Prep and compiled by Luel A
y = y + Yincrement;
putpixel(x,y);
}

2.2.2 Bresenham's Line Drawing Algorithm


An accurate and efficient raster line-generating algorithm, developed by Bresenham, scan converts lines
using only incremental integer calculations that can be adapted to display circles and other curves

To illustrate bresenham's approach, we- first consider the scan-conversion process for lines with
positive slope less than 1. Pixel positions along a line path are then determined by sampling at unit x
intervals. Starting from the left end point (x0, y0) of a given line, we step to each successive column (x
position) and plot the pixel whose scan-line y value is closest to the line path. Figure 3-7 demonstrates
the Kth step in this process. Assuming we have determined that the pixel at (xk, yk) is to be displayed,
we next need to decide which pixel to plot in column Xk+1. Our choices are the pixels at positions (Xk+1,
Yk1) and (xk+1, YK+1).At sampling position xk+l, we label vertical pixel separations from the
mathematical line path as d1, and d2. The y coordinate on the mathematical line at pixel column
position Xk+1 is calculated as

(2-9)

(2-10)
A decision parameter pk for the kth step in the line algorithm can be obtained by rearranging Eq. 2-10 so
that it involves only integer calculations. We accomplish this by substituting m = dy/dx, where dy and dx
are the vertical and horizontal separations of the endpoint positions, and defining:

(2-11)

12 | P a g e
Prep and compiled by Luel A
The sign of pk, is the same as the sign of d1 – d2, since dx > 0 for our example. Parameter c is constant
and has the value 2dy + dx (2b - 1), which is independent of pixel position and will be eliminated in the
recursive calculations for pk.

Figure 2.2

Pixel at yk is closer to the line path than the pixel at yk+1 (that is, d1 < d2,), then decision parameter pk
is negative. In that case, we plot the lower pixel; otherwise, we plot the upper pixel. Coordinate changes
along the line occur in unit steps in either the x or y directions. Therefore, we can obtain the values of
successive decision parameters using incremental integer calculations. At step k + 1, the decision

13 | P a g e
Prep and compiled by Luel A
parameter is evaluated from Eq. 2-11 as

2-12

Where the term yk+1- yk is either 0 or 1, depending on the sign of parameter pk. This recursive
calculation of decision parameters is performed at each integer x position, starting at the left coordinate
endpoint of the line. The first parameter, p, is evaluated from Eq. 3-12 at the starting pixel position
(X0,Y0) and with m evaluated as Ay/Ax

Figure 2-3

Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm for slope m
< 1:
Step 1: Input the two end-points of line, storing the left end-point in (x0, y0).
Step 2: Plot the point (x0, y0).
Step 3: Calculate the constants dx, dy, 2dy, and (2dy – 2dx) and get the first value
For the decision parameter as: 𝑝0= 2𝑑y − 𝑑x
Step 4: At each xk along the line, starting at k = 0, perform the following test:
If pk < 0, the next point to plot is (xk+1, yk) and pk+1= 𝑝k+ 2𝑑y Otherwise,
𝑝k+1= 𝑝k+ 2𝑑y − 2𝑑x
Step 5: Repeat step 4 (dx – 1) times.
For m > 1, find out whether you need to increment x while incrementing y each time.
After solving, the equation for decision parameter pk will be very similar, just the x
And y in the equation gets interchanged.

14 | P a g e
Prep and compiled by Luel A
Example 2-1 Bresenham Line Drawing

To illustrate the algorithm, we digitize the line with endpoints (20, 10) and (30, 18). This line has a slope
of 0.8, with
Dx = 10 , dy = 8
The initial decision parameter has the value

P0 = 2dy-dx = 6

And the increments for calculating successive decision parameters are

2dy = 16, 2dy - 2dx = 4

We plot the initial point (xo, yo) = (20, 10), and determine successive pixel positions along the line path
from the decision parameter as

A plot of the pixels generated along this line path is shown in Fig. 2-4.

15 | P a g e
Prep and compiled by Luel A
2.3 CIRCLE-GENERATING ALGORITHMS

Since the circle is a frequently used component in pictures and graphs, a procedure for generating either
full circles or circular arcs is included in most graphics packages. More generally, a single procedure can
be provided to display either circular or elliptical curves.

2.3.1 Properties of Circles


A circle is defined as the set of points that are all at a given distance r from a center position (x, y). This
distance relationship is expressed by the Pythagorean Theorem in Cartesian coordinates as

(2-13)

We could use this equation to calculate the position of points on a circle circumference by stepping
along the x axis in unit steps from x, - r to x, + r and calculating the corresponding y values at each
position as

(2-14)

But 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 .We could adjust the spacing by interchanging x and y (stepping through y values and
calculating x values) whenever the absolute value of the slope of the circle is greater than 1. But this
simply increases the computation and processing required by the algorithm. Another way to eliminate

16 | P a g e
Prep and compiled by Luel A
the unequal spacing is to calculate points along the circular boundary using polar coordinates r and ɵ.
expressing the circle equation in parametric polar form yields the pair of equations

(2-15)
When a display is generated with these equations using a fixed angular step size, a circle is plotted with
equally spaced points along the circumference. The step size chosen for ɵ depends on the application
and the display device. Larger angular separations along the circumference can be connected with
straight line segments to approximate the circular path. For a more continuous boundary on a raster
display, we can set the step size at l/r. This plots pixel positions that are approximately one unit apart.

Computation can be reduced by considering the symmetry of circles

Bresenham's line algorithm for raster displays is adapted to circle generation by setting up decision
parameters for finding the closest pixel to the circumference at each sampling step. Bresenham's circle

17 | P a g e
Prep and compiled by Luel A
algorithm avoids the square root calculations by comparing the squares of the pixel separation
distances.

A method for direct distance comparison is to test the halfway position between two pixels to
determine if this midpoint is inside or outside the circle boundary. This method is more easily applied to
other conics; and for an integer circle radius, the midpoint approach generates the same pixel positions
as the Brenham circle algorithm

Reading assignment: Bresenham circle algorithm

2.3.1 Midpoint Circle Algorithm

As in the raster line algorithm, we sample at unit intervals and determine the closest pixel position to
the specified circle path at each step. For a given radius r and screen center position (x, y,), we can first
set up our algorithm to calculate pixel positions around a circle path centered at the coordinate origin
(0,O). Then each calculated position (x, y) is moved to its proper screen position by adding 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. 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.

To apply the midpoint method, we define a circle function:

(2-16)

(2-17)

The circle function is the decision parameter in the midpoint algorithm, and we can set up incremental
calculations for this function as we did in the line algorithm.

18 | P a g e
Prep and compiled by Luel A
Midpoint between candidate’s pixels at sampling position Xk+1 along circular path.

(2-18)

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 scan line yk -
1.
Successive decision parameters are obtained using incremental calculations. We obtain a recursive
expression for the next decision parameter by evaluating the circle function at sampling position
Xk+1 + 1 = Xk + 2:

(2-19)

(2-20)

(2-21)

19 | P a g e
Prep and compiled by Luel A
As in Bresenham's line algorithm, the midpoint method calculates pixel positions along the
circumference of a circle using integer additions and subtractions, assuming that the circle parameters
are specified in integer screen coordinates. We can summarize the steps in the midpoint circle algorithm
as follows.

Reading assignment: Ellipse drawing algorithm

20 | P a g e
Prep and compiled by Luel A
2.4 Other curves

Various curve functions are useful in object modeling, animation path specifications, data and function
graphing, and other graphics applications. Commonly encountered curves include conics, trigonometric
and exponential functions, probability distributions, general polynomials, and spline functions. Displays
of these curves can be generated with methods similar to those discussed for the circle and ellipse
functions. We can obtain positions along curve paths directly from explicit representations y = f(x) or
from parametric forms alternatively, we could apply the incremental midpoint method to plot curves
described with implicit functions f (x, y) = 1).
A straightforward method for displaying a specified curve function is to approximate it with straight
line segments. Parametric representations are useful in this case for obtaining equally spaced line
endpoint positions along the curve path. We can also generate equally spaced positions from an explicit
representation by choosing the independent variable according to the slope of the curve. Where the
slope of y = f(x) has a magnitude less than 1, we choose x as the independent variable and calculate y
values at equal x increments. To obtain equal spacing where the slope has a magnitude greater than 1,
we use the inverse function, x = f -1 (y, and calculate values of x at equal y steps.

2.5 Polygon Filling Algorithm


Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with particular
colors, you need to determine the pixels falling on the border of the polygon and those which fall inside
the polygon. In this lecture, we will see how we can fill polygons using different techniques.

Figure2-6: Polygon
2.5.1 Scan Line Algorithm
This algorithm works by intersecting scanline with polygon edges and fills the polygon between pairs of
intersections. The following steps depict how this algorithm works.

Step 1 − Find out the Ymin and Ymax from the given polygon.

21 | P a g e
Prep and compiled by Luel A
Figure 2-7

Step 2 − Scanline intersects with each edge of the polygon from Ymin to Ymax. Name each intersection
point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3.

Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. (p0, p1), (p1, p2), and (p2,
p3).

Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.

2.5.2 Flood Fill Algorithm

Sometimes we come across an object where we want to fill the area and its boundary with different
colors. We can paint such objects with a specified interior color instead of searching for particular
boundary color as in boundary filling algorithm.

Instead of relying on the boundary of the object, it relies on the fill color. In other words, it replaces the
interior color of the object with the fill color. When no more pixels of the original interior color exist, the
algorithm is completed.

Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in the pixels. But
instead of looking for the boundary color, it is looking for all adjacent pixels that are a part of the interior.

22 | P a g e
Prep and compiled by Luel A
Figure 2-8

2.5.3 Boundary Fill Algorithm

The boundary fill algorithm works as its name. This algorithm picks a point inside an object and starts to
fill until it hits the boundary of the object. The color of the boundary and the color that we fill should be
different for this algorithm to work.

In this algorithm, we assume that color of the boundary is same for the entire object. The boundary fill
algorithm can be implemented by 4-connected pixels or 8-connected pixels

23 | P a g e
Prep and compiled by Luel A
2.5.3.1 4-Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We are putting the pixels above,
below, to the right, and to the left side of the current pixels and this process will continue until we find a
boundary with different color.

Algorithm

Step 1 − Initialize the value of seed point (seedx, seedy), fcolor and dcol.

Step 2 − Define the boundary values of the polygon.

Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the
boundary pixels reached.

If getpixel(x, y) = dcol then repeat step 4 and 5

Step 4 − Change the default color with the fill color at the seed point.

setPixel(seedx, seedy, fcol)

Step 5 − Recursively follow the procedure with four neighborhood points.

FloodFill (seedx – 1, seedy, fcol, dcol)


FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)

Step 6 − Exit

24 | P a g e
Prep and compiled by Luel A
There is a problem with this technique. Consider the case as shown below where we tried to fill the
entire region. Here, the image is filled only partially. In such cases, 4-connected pixels technique cannot
be used.

Figure 2-10

2.5.3.2 8-Connected Polygon


In this technique 8-connected pixels are used as shown in the figure. We are putting pixels above,
below, right and left side of the current pixels as we were doing in 4-connected technique. In addition to
this, we are also putting pixels in diagonals so that entire area of the current pixel is covered. This
process will continue until we find a boundary with different color.

Figure 2-11

25 | P a g e
Prep and compiled by Luel A
Algorithm

Step 1 − Initialize the value of seed point (seedx, seedy), fcolor and dcol.

Step 2 − Define the boundary values of the polygon.

Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the
boundary pixels reached

If getpixel(x,y) = dcol then repeat step 4 and 5

Step 4 − Change the default color with the fill color at the seed point.

setPixel(seedx, seedy, fcol)

Step 5 − Recursively follow the procedure with four neighbourhood points

FloodFill (seedx – 1, seedy, fcol, dcol)


FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)

Step 6 − Exit

The 4-connected pixel technique failed to fill the area as marked in the following figure which
won’t happen with the 8-connected technique.

Figure 2-12

26 | P a g e
Prep and compiled by Luel A
2.5.4 Inside-outside Test

This method is also known as counting number method. While filling an object, we often need to
identify whether particular point is inside the object or outside it. There are two methods by which we
can identify whether particular point is inside an object or outside.

• Odd-Even Rule
• Nonzero winding number rule

2.5.4.1 Odd-Even Rule

In this technique, we will count the edge crossing along the line from any point (x,y) to infinity. If the
number of interactions is odd, then the point (x,y) is an interior point; and if the number of interactions
is even, then the point (x,y) is an exterior point. The following example depicts this concept.

Figure 2-13

From the above figure, we can see that from the point (x,y), the number of interactions point on the left
side is 5 and on the right side is 3. From both ends, the number of interaction points is odd, so the point
is considered within the object.

2.5.4.2 Nonzero Winding Number Rule

This method is also used with the simple polygons to test the given point is interior or not. It can
be simply understood with the help of a pin and a rubber band. Fix up the pin on one of the edge
of the polygon and tie-up the rubber band in it and then stretch the rubber band along the edges
of the polygon.

When all the edges of the polygon are covered by the rubber band, check out the pin which has
been fixed up at the point to be test. If we find at least one wind at the point consider it within the
polygon, else we can say that the point is not inside the polygon.

27 | P a g e
Prep and compiled by Luel A
In another alternative method, give directions to all the edges of the polygon. Draw a scan line
from the point to be test towards the left most of X direction.

• Give the value 1 to all the edges which are going to upward direction and all other -1 as
direction values.
• Check the edge direction values from which the scan line is passing and sum up them.
• If the total sum of this direction value is non-zero, then this point to be tested is an
interior point, otherwise it is an exterior point.
• In the above figure, we sum up the direction values from which the scan line is passing
then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior
point.

2.6 Attributes of output primitives


Attributes of output primitive
• any parameter that affects the way a primitive is to be displayed is referred to as an attribute
parameter
• Some attribute parameters, such as color and size, determine the fundamental characteristics of
a primitive. Others specify how the primitive is to be displayed under special conditions
LINE ATTRIBUTES: Basic attributes of a straight line segment are its type, its width, and its color Line
type: Possible selections for the line-type attribute include solid lines, dashed lines, and dotted lines.
CURVE ATTRIBUTES: Parameters for curve attributes are the same as those for line segments. We can
display curves with varying colors, widths, dot dash patterns, and available pen or brush options.
Methods for adapting curve-drawing algorithms to accommodate Attribute selections are similar to
those for line drawing.

28 | P a g e
Prep and compiled by Luel A
Summary
Three methods that can be used to plot pixel positions along a straight-line path are the DDA
algorithm, Bresenham's algorithm, and the midpoint method. For straight lines, Bresenham's algorithm
and the midpoint method are identical and are the most efficient Frame-buffer access in these methods
can also be performed efficiently by incrementally calculating memory addresses. Any of the line-
generating algorithm can be adapted to a parallel implementation by partitioning line segments. Circles
and ellipse can be efficiently and accurately scan converted using midpoint methods and taking curve
symmetry into account. Other conic sections, parabolas and hyperbolas, can be plotted with similar
methods. Spline curves, which are piecewise continuous polynomials, are widely used in design
Applications. Parallel implementation of curve generation can be accomplished by partitioning the curve
paths.
We have explored the various attributes that control the appearance of displayed primitives.
Procedures for displaying primitives use attribute settings to adjust the output of algorithms for line-
generation, area-filling, and Text-string displays.
The basic line attributes are line type, line color, and line width. Specifications for line type include
solid, dashed, and dotted lines. Line-color specifications can be given in terms of RGB components, which
control the intensity of the three electron guns in an RGB monitor. Specifications for line width are given
in terms of multiples of a standard, one-pixel-wide line. These attributes can be applied to both straight
lines and curves.
To reduce the size of the frame buffer, some raster systems use a separate color lookup table. This
limits the number of colors that .can be displayed to the size of the lookup table. Full color systems are
those that provide 24 bits per pixel and no separate color lookup table.

29 | P a g e
Prep and compiled by Luel A

You might also like