0% found this document useful (0 votes)
20 views

Computer Graphics

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Computer Graphics

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Computer Graphics

It is difficult to display an image of any size on the computer screen. This method is
simplified by using Computer graphics. Graphics on the computer are produced by using
various algorithms and techniques. This tutorial describes how a rich visual experience is
provided to the user by explaining how all these processed by the computer.

Introduction of Computer Graphics


Computer Graphics involves technology to access. The Process transforms and presents
information in a visual form. The role of computer graphics insensible. In today life,
computer graphics has now become a common element in user interfaces, T.V.
commercial motion pictures.

Computer Graphics is the creation of pictures with the help of a computer. The end product
of the computer graphics is a picture it may be a business graph, drawing, and
engineering.

In computer graphics, two or three-dimensional pictures can be created that are used for
research. Many hardware devices algorithm has been developing for improving the speed
of picture generation with the passes of time. It includes the creation storage of models
and image of objects. These models for various fields like engineering, mathematical and
so on.

Today computer graphics is entirely different from the earlier one. It is not possible. It is
an interactive user can control the structure of an object of various input devices.

Definition of Computer Graphics:


It is the use of computers to create and manipulate pictures on a display device. It
comprises of software techniques to create, store, modify, represents pictures.

Why computer graphics used?


Suppose a shoe manufacturing company want to show the sale of shoes for five years.
For this vast amount of information is to store. So a lot of time and memory will be needed.
This method will be tough to understand by a common man. In this situation graphics is a
better alternative. Graphics tools are charts and graphs. Using graphs, data can be
represented in pictorial form. A picture can be understood easily just with a single look.

Interactive computer graphics work using the concept of two-way communication between
computer users. The computer will receive signals from the input device, and the picture
is modified accordingly. Picture will be changed quickly when we apply command.
Application of Computer Graphics
1. Education and Training: Computer-generated model of the physical, financial and
economic system is often used as educational aids. Model of physical systems,
physiological system, population trends or equipment can help trainees to understand the
operation of the system.

For some training applications, particular systems are designed. For example Flight
Simulator.

Flight Simulator: It helps in giving training to the pilots of airplanes. These pilots spend
much of their training not in a real aircraft but on the ground at the controls of a Flight
Simulator.

Advantages:
1. Fuel Saving
2. Safety
3. Ability to familiarize the training with a large number of the world's airports.

2. Use in Biology: Molecular biologist can display a picture of molecules and gain insight
into their structure with the help of computer graphics.

3. Computer-Generated Maps: Town planners and transportation engineers can use


computer-generated maps which display data useful to them in their planning work.

4. Architect: Architect can explore an alternative solution to design problems at an


interactive graphics terminal. In this way, they can test many more solutions that would
not be possible without the computer.

5. Presentation Graphics: Example of presentation Graphics are bar charts, line graphs,
pie charts and other displays showing relationships between multiple parameters.
Presentation Graphics is commonly used to summarize

o Financial Reports
o Statistical Reports
o Mathematical Reports
o Scientific Reports
o Economic Data for research reports
o Managerial Reports
o Consumer Information Bulletins
o And other types of reports
6. Computer Art: Computer Graphics are also used in the field of commercial arts. It is
used to generate television and advertising commercial.

7. Entertainment: Computer Graphics are now commonly used in making motion


pictures, music videos and television shows.

8. Visualization: It is used for visualization of scientists, engineers, medical personnel,


business analysts for the study of a large amount of information.

9. Educational Software: Computer Graphics is used in the development of educational


software for making computer-aided instruction.

10. Printing Technology: Computer Graphics is used for printing technology and textile
design.

Example of Computer Graphics Packages:


1. LOGO
2. COREL DRAW
3. AUTO CAD
4. 3D STUDIO
5. CORE
6. GKS (Graphics Kernel System)
7. PHIGS
8. CAM (Computer Graphics Metafile)
9. CGI (Computer Graphics Interface)

Interactive and Passive Graphics


(a) Non-Interactive or Passive Computer Graphics:
In non-interactive computer graphics, the picture is produced on the monitor, and the user does not
have any controlled over the image, i.e., the user cannot make any change in the rendered image.
One example of its Titles shown on T.V.

Non-interactive Graphics involves only one-way communication between the computer and the
user, User can see the produced image, and he cannot make any change in the image.

(b) Interactive Computer Graphics:


In interactive Computer Graphics user have some controls over the picture, i.e., the user can make
any change in the produced image. One example of it is the ping-pong game.

Interactive Computer Graphics require two-way communication between the computer and the
user. A User can see the image and make any change by sending his command with an input device.
Advantages:
1. Higher Quality
2. More precise results or products
3. Greater Productivity
4. Lower analysis and design cost
5. Significantly enhances our ability to understand data and to perceive trends.

Working of Interactive Computer Graphics:


The modern graphics display is very simple in construction. It consists of three components:

1. Frame Buffer or Digital Memory


2. A Monitor likes a home T.V. set without the tuning and receiving electronics.
3. Display Controller or Video Controller: It passes the contents of the frame buffer to the monitor.

Frame Buffer: A digital frame buffer is large, contiguous piece of computer memory used to hold
or map the image displayed on the screen.

o At a minimum, there is 1 memory bit for each pixel in the raster. This amount of memory is
called a bit plane.
o A 1024 x 1024 element requires 220 (210=1024;220=1024 x 1024)sq.raster or 1,048,576 memory
bits in a single bit plane.
o The picture is built up in the frame buffer one bit at a time.
o ∵ A memory bit has only two states (binary 0 or 1), a single bit plane yields a black and white
(monochrome display).
o As frame buffer is a digital device write raster CRT is an analog device.

Properties of Video Monitor:


1. Persistence: Persistence is the duration of phosphorescence. Different kinds of phosphors are
available for use in CRT. Besides color, a major difference between phosphor in their persistence
how they continue to emit light after the electron beam is removed.

2. Resolution: Use to describe the number of pixels that are used on display image.
3. Aspect Ratio: It is the ratio of width to its height. Its measure is unit in length or number of
pixels.

Aspect Ratio =

Display Processor:
It is interpreter or piece of hardware that converts display processor code into pictures. It
is one of the four main parts of the display processor

Parts of Display Processor

1. Display File Memory


2. Display Processor
3. Display Generator
4. Display Console

Display File Memory: It is used for generation of the picture. It is used for identification
of graphic entities.

Display Controller:

1. It handles interrupt
2. It maintains timings
3. It is used for interpretation of instruction.

Display Generator:

1. It is used for the generation of character.


2. It is used for the generation of curves.

Display Console: It contains CRT, Light Pen, and Keyboard and deflection system.

The raster scan system is a combination of some processing units. It consists of the
control processing unit (CPU) and a particular processor called a display controller.
Display Controller controls the operation of the display device. It is also called a video
controller.

Working: The video controller in the output circuitry generates the horizontal and vertical
drive signals so that the monitor can sweep. Its beam across the screen during raster
scans.

As fig showing that 2 registers (X register and Y register) are used to store the coordinate
of the screen pixels. Assume that y values of the adjacent scan lines increased by 1 in an
upward direction starting from 0 at the bottom of the screen to ymax at the top and along
each scan line the screen pixel positions or x values are incremented by 1 from 0 at the
leftmost position to xmax at the rightmost position.

The origin is at the lowest left corner of the screen as in a standard Cartesian coordinate
system.

At the start of a Refresh Cycle:

X register is set to 0 and y register is set to ymax. This (x, y') address is translated into a
memory address of frame buffer where the color value for this pixel position is stored.

The controller receives this color value (a binary no) from the frame buffer, breaks it up
into three parts and sends each element to a separate Digital-to-Analog Converter (DAC).
These voltages, in turn, controls the intensity of 3 e-beam that are focused at the (x, y)
screen position by the horizontal and vertical drive signals.

This process is repeated for each pixel along the top scan line, each time incrementing
the X register by Y.

As pixels on the first scan line are generated, the X register is incremented throughx max.

Then x register is reset to 0, and y register is decremented by 1 to access the next scan
line.

Pixel along each scan line is then processed, and the procedure is repeated for each
successive scan line units pixels on the last scan line (y=0) are generated.

For a display system employing a color look-up table frame buffer value is not directly
used to control the CRT beam intensity.

It is used as an index to find the three pixel-color value from the look-up table. This lookup
operation is done for each pixel on every display cycle.

As the time available to display or refresh a single pixel in the screen is too less, accessing
the frame buffer every time for reading each pixel intensity value would consume more
time what is allowed:

Multiple adjacent pixel values are fetched to the frame buffer in single access and stored
in the register.

After every allowable time gap, the one-pixel value is shifted out from the register to control
the warm intensity for that pixel.

The procedure is repeated with the next block of pixels,and so on, thus the whole group
of pixels will be processed.

Display Devices:
The most commonly used display device is a video monitor. The operation of most video
monitors based on CRT (Cathode Ray Tube). The following display devices are used:

1. Refresh Cathode Ray Tube


2. Random Scan and Raster Scan
3. Color CRT Monitors
4. Direct View Storage Tubes
5. Flat Panel Display
6. Lookup Table

Cathode Ray Tube (CRT):


CRT stands for Cathode Ray Tube. CRT is a technology used in traditional computer
monitors and televisions. The image on CRT display is created by firing electrons from the
back of the tube of phosphorus located towards the front of the screen.

Once the electron heats the phosphorus, they light up, and they are projected on a screen.
The color you view on the screen is produced by a blend of red, blue and green light.

Components of CRT:
Main Components of CRT are:

1. Electron Gun: Electron gun consisting of a series of elements, primarily a heating


filament (heater) and a cathode. The electron gun creates a source of electrons which are
focused into a narrow beam directed at the face of the CRT.

2. Control Electrode: It is used to turn the electron beam on and off.

3. Focusing system: It is used to create a clear picture by focusing the electrons into a
narrow beam.

4. Deflection Yoke: It is used to control the direction of the electron beam. It creates an
electric or magnetic field which will bend the electron beam as it passes through the area.
In a conventional CRT, the yoke is linked to a sweep or scan generator. The deflection
yoke which is connected to the sweep generator creates a fluctuating electric or magnetic
potential.
5. Phosphorus-coated screen: The inside front surface of every CRT is coated with
phosphors. Phosphors glow when a high-energy electron beam hits them.
Phosphorescence is the term used to characterize the light given off by a phosphor after
it has been exposed to an electron beam.

Random Scan and Raster Scan Display:


Random Scan Display:
Random Scan System uses an electron beam which operates like a pencil to create a line
image on the CRT screen. The picture is constructed out of a sequence of straight-line
segments. Each line segment is drawn on the screen by directing the beam to move from
one point on the screen to the next, where its x & y coordinates define each point. After
drawing the picture. The system cycles back to the first line and design all the lines of the
image 30 to 60 time each second. The process is shown in fig:

Random-scan monitors are also known as vector displays or stroke-writing displays or


calligraphic displays.

Advantages:
1. A CRT has the electron beam directed only to the parts of the screen where an image is
to be drawn.
2. Produce smooth line drawings.
3. High Resolution

Disadvantages:
1. Random-Scan monitors cannot display realistic shades scenes.

Raster Scan Display:


A Raster Scan Display is based on intensity control of pixels in the form of a rectangular
box called Raster on the screen. Information of on and off pixels is stored in refresh buffer
or Frame buffer. Televisions in our house are based on Raster Scan Method. The raster
scan system can store information of each pixel position, so it is suitable for realistic
display of objects. Raster Scan provides a refresh rate of 60 to 80 frames per second.

Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are called
picture elements or pixels. Beam refreshing is of two types. First is horizontal retracing
and second is vertical retracing. When the beam starts from the top left corner and reaches
the bottom right scale, it will again return to the top left side called at vertical retrace. Then
it will again more horizontally from top to bottom call as horizontal retracing shown in fig:

Advertisement

Types of Scanning or travelling of beam in Raster Scan

1. Interlaced Scanning
2. Non-Interlaced Scanning

In Interlaced scanning, each horizontal line of the screen is traced from top to bottom. Due
to which fading of display of object may occur. This problem can be solved by Non-
Interlaced scanning. In this first of all odd numbered lines are traced or visited by an
electron beam, then in the next circle, even number of lines are located.

For non-interlaced display refresh rate of 30 frames per second used. But it gives flickers.
For interlaced display refresh rate of 60 frames per second is used.

Advantages:
1. Realistic image
2. Million Different colors to be generated
3. Shadow Scenes are possible.

Disadvantages:
1. Low Resolution
2. Expensive

Differentiate between Random and Raster Scan Display:

Random Scan Raster Scan


1. It has high Resolution 1. Its resolution is low.

2. It is more expensive 2. It is less expensive

3. Any modification if needed is easy 3.Modification is tough

4. Solid pattern is tough to fill 4.Solid pattern is easy to fill

5. Refresh rate depends or resolution 5. Refresh rate does not depend on the picture.

6. Only screen with view on an area is


6. Whole screen is scanned.
displayed.

7. Beam Penetration technology come under it. 7. Shadow mark technology came under this.

8. It does not use interlacing method. 8. It uses interlacing

9. It is restricted to line drawing applications 9. It is suitable for realistic display.

Color CRT Monitors:


The CRT Monitor display by using a combination of phosphors. The phosphors are
different colors. There are two popular approaches for producing color displays with a
CRT are:

1. Beam Penetration Method


2. Shadow-Mask Method

1. Beam Penetration Method:


The Beam-Penetration method has been used with random-scan monitors. In this method,
the CRT screen is coated with two layers of phosphor, red and green and the displayed
color depends on how far the electron beam penetrates the phosphor layers. This method
produces four colors only, red, green, orange and yellow. A beam of slow electrons excites
the outer red layer only; hence screen shows red color only. A beam of high-speed
electrons excites the inner green layer. Thus screen shows a green color.
Advantages:
1. Inexpensive

Disadvantages:
1. Only four colors are possible
2. Quality of pictures is not as good as with another method.

2. Shadow-Mask Method:
o Shadow Mask Method is commonly used in Raster-Scan System because they
produce a much wider range of colors than the beam-penetration method.
o It is used in the majority of color TV sets and monitors.
Construction: A shadow mask CRT has 3 phosphor color dots at each pixel position.

o One phosphor dot emits: red light


o Another emits: green light
o Third emits: blue light
This type of CRT has 3 electron guns, one for each color dot and a shadow mask grid just
behind the phosphor coated screen.

Shadow mask grid is pierced with small round holes in a triangular pattern.
Figure shows the delta-delta shadow mask method commonly used in color CRT system.

Working: Triad arrangement of red, green, and blue guns.

The deflection system of the CRT operates on all 3 electron beams simultaneously; the 3
electron beams are deflected and focused as a group onto the shadow mask, which
contains a sequence of holes aligned with the phosphor- dot patterns.

When the three beams pass through a hole in the shadow mask, they activate a dotted
triangle, which occurs as a small color spot on the screen.

The phosphor dots in the triangles are organized so that each electron beam can activate
only its corresponding color dot when it passes through the shadow mask.

Inline arrangement: Another configuration for the 3 electron guns is an Inline


arrangement in which the 3

electron guns and the corresponding red-green-blue color dots on the screen, are aligned
along one scan line rather of in a triangular pattern.

This inline arrangement of electron guns in easier to keep in alignment and is commonly
used in high-resolution color CRT's.
Advantage:
1. Realistic image
2. Million different colors to be generated
3. Shadow scenes are possible

Disadvantage:
1. Relatively expensive compared with the monochrome CRT.
2. Relatively poor resolution
3. Convergence Problem

Direct View Storage Tubes:


DVST terminals also use the random scan approach to generate the image on the CRT
screen. The term "storage tube" refers to the ability of the screen to retain the image which
has been projected against it, thus avoiding the need to rewrite the image constantly.

Function of guns: Two guns are used in DVST

1. Primary guns: It is used to store the picture pattern.


2. Flood gun or Secondary gun: It is used to maintain picture display.
Advantage:
1. No refreshing is needed.
2. High Resolution
3. Cost is very less

Disadvantage:
1. It is not possible to erase the selected part of a picture.
2. It is not suitable for dynamic graphics applications.
3. If a part of picture is to modify, then time is consumed.

Flat Panel Display:


The Flat-Panel display refers to a class of video devices that have reduced volume, weight
and power requirement compare to CRT.

Example: Small T.V. monitor, calculator, pocket video games, laptop computers, an
advertisement board in elevator.

1. Emissive Display: The emissive displays are devices that convert electrical energy
into light. Examples are Plasma Panel, thin film electroluminescent display and LED (Light
Emitting Diodes).
2. Non-Emissive Display: The Non-Emissive displays use optical effects to convert
sunlight or light from some other source into graphics patterns. Examples are LCD (Liquid
Crystal Device).

Plasma Panel Display:


Plasma-Panels are also called as Gas-Discharge Display. It consists of an array of small
lights. Lights are fluorescent in nature. The essential components of the plasma-panel
display are:

1. Cathode: It consists of fine wires. It delivers negative voltage to gas cells. The voltage is
released along with the negative axis.
2. Anode: It also consists of line wires. It delivers positive voltage. The voltage is supplied
along positive axis.
3. Fluorescent cells: It consists of small pockets of gas liquids when the voltage is applied
to this liquid (neon gas) it emits light.
4. Glass Plates: These plates act as capacitors. The voltage will be applied, the cell will glow
continuously.

The gas will slow when there is a significant voltage difference between horizontal and
vertical wires. The voltage level is kept between 90 volts to 120 volts. Plasma level does
not require refreshing. Erasing is done by reducing the voltage to 90 volts.

Each cell of plasma has two states, so cell is said to be stable. Displayable point in plasma
panel is made by the crossing of the horizontal and vertical grid. The resolution of the
plasma panel can be up to 512 * 512 pixels.

Figure shows the state of cell in plasma panel display:

Advantage:
1. High Resolution
2. Large screen size is also possible.
3. Less Volume
4. Less weight
5. Flicker Free Display
Disadvantage:
1. Poor Resolution
2. Wiring requirement anode and the cathode is complex.
3. Its addressing is also complex.

LED (Light Emitting Diode):


In an LED, a matrix of diodes is organized to form the pixel positions in the display and
picture definition is stored in a refresh buffer. Data is read from the refresh buffer and
converted to voltage levels that are applied to the diodes to produce the light pattern in
the display.

LCD (Liquid Crystal Display):


Liquid Crystal Displays are the devices that produce a picture by passing polarized light
from the surroundings or from an internal light source through a liquid-crystal material that
transmits the light.

LCD uses the liquid-crystal material between two glass plates; each plate is the right angle
to each other between plates liquid is filled. One glass plate consists of rows of conductors
arranged in vertical direction. Another glass plate is consisting of a row of conductors
arranged in horizontal direction. The pixel position is determined by the intersection of the
vertical & horizontal conductor. This position is an active part of the screen.

Liquid crystal display is temperature dependent. It is between zero to seventy degree


Celsius. It is flat and requires very little power to operate.
Advantage:
1. Low power consumption.
2. Small Size
3. Low Cost

Disadvantage:
1. LCDs are temperature-dependent (0-70°C)
2. LCDs do not emit light; as a result, the image has very little contrast.
3. LCDs have no color capability.
4. The resolution is not as good as that of a CRT.

Look-Up Table:
Image representation is essentially the description of pixel colors. There are three primary
colors: R (red), G (green) and B (blue). Each primary color can take on intensity levels
produces a variety of colors. Using direct coding, we may allocate 3 bits for each pixel,
with one bit for each primary color. The 3-bit representation allows each primary to vary
independently between two intensity levels: 0 (off) or 1 (on). Hence each pixel can take
on one of the eight colors.

Bit 1:r Bit 2:g Bit 3:b Color name

0 0 0 Black

0 0 1 Blue

0 1 0 Green

0 1 1 Cyan

1 0 0 Red

1 0 1 Magenta

1 1 0 Yellow

1 1 1 White
A widely accepted industry standard uses 3 bytes, or 24 bytes, per pixel, with one byte for
each primary color. The way, we allow each primary color to have 256 different intensity
levels. Thus a pixel can take on a color from 256 x 256 x 256 or 16.7 million possible
choices. The 24-bit format is commonly referred to as the actual color representation.

Lookup Table approach reduces the storage requirement. In this approach pixel values
do not code colors directly. Alternatively, they are addresses or indices into a table of color
values. The color of a particular pixel is determined by the color value in the table entry
that the value of the pixel references. Figure shows a look-up table with 256 entries. The
entries have addresses 0 through 255. Each entry contains a 24-bit RGB color value. Pixel
values are now 1-byte. The color of a pixel whose value is i, where 0 <i<255, is persistence
by the color value in the table entry whose address is i. It reduces the storage requirement
of a 1000 x 1000 image to one million bytes plus 768 bytes for the color values in the look-
up table.

Input Devices
The Input Devices are the hardware that is used to transfer transfers input to the computer.
The data can be in the form of text, graphics, sound, and text. Output device display data
from the memory of the computer. Output can be text, numeric data, line, polygon, and
other objects.
These Devices include:

1. Keyboard
2. Mouse
3. Trackball
4. Spaceball
5. Joystick
6. Light Pen
7. Digitizer
8. Touch Panels
9. Voice Recognition
10. Image Scanner

Keyboard:
The most commonly used input device is a keyboard. The data is entered by pressing the
set of keys. All keys are labeled. A keyboard with 101 keys is called a QWERTY keyboard.

The keyboard has alphabetic as well as numeric keys. Some special keys are also
available.

1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2. Alphabetic keys: a to z (lower case), A to Z (upper case)
3. Special Control keys: Ctrl, Shift, Alt
4. Special Symbol Keys: ; , " ? @ ~ ? :
5. Cursor Control Keys: ↑ → ← ↓
6. Function Keys: F1 F2 F3....F9.
7. Numeric Keyboard: It is on the right-hand side of the keyboard and used for fast entry of
numeric data.

Function of Keyboard:
1. Alphanumeric Keyboards are used in CAD. (Computer Aided Drafting)
2. Keyboards are available with special features line screen co-ordinates entry, Menu
selection or graphics functions, etc.
3. Special purpose keyboards are available having buttons, dials, and switches. Dials are
used to enter scalar values. Dials also enter real numbers. Buttons and switches are used
to enter predefined function values.

Advantage:
1. Suitable for entering numeric data.
2. Function keys are a fast and effective method of using commands, with fewer errors.

Disadvantage:
1. Keyboard is not suitable for graphics input.

Mouse:
A Mouse is a pointing device and used to position the pointer on the screen. It is a small
palm size box. There are two or three depression switches on the top. The movement of
the mouse along the x-axis helps in the horizontal movement of the cursor and the
movement along the y-axis helps in the vertical movement of the cursor on the screen.
The mouse cannot be used to enter text. Therefore, they are used in conjunction with a
keyboard.

Advantage:
1. Easy to use
2. Not very expensive

Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in notebook or laptop
computer, instead of a mouse. This is a ball which is half inserted, and by changing fingers
on the ball, the pointer can be moved.
Advantage:
1. Trackball is stationary, so it does not require much space to use it.
2. Compact Size

Spaceball:
It is similar to trackball, but it can move in six directions where trackball can move in two
directions only. The movement is recorded by the strain gauge. Strain gauge is applied
with pressure. It can be pushed and pulled in various directions. The ball has a diameter
around 7.5 cm. The ball is mounted in the base using rollers. One-third of the ball is an
inside box, the rest is outside.

Applications:
1. It is used for three-dimensional positioning of the object.
2. It is used to select various functions in the field of virtual reality.
3. It is applicable in CAD applications.
4. Animation is also done using spaceball.
5. It is used in the area of simulation and modeling.

Joystick:
A Joystick is also a pointing device which is used to change cursor position on a monitor
screen. Joystick is a stick having a spherical ball as its both lower and upper ends as
shown in fig. The lower spherical ball moves in a socket. The joystick can be changed in
all four directions. The function of a joystick is similar to that of the mouse. It is mainly
used in Computer Aided Designing (CAD) and playing computer games.
Light Pen
Light Pen (similar to the pen) is a pointing device which is used to select a displayed menu
item or draw pictures on the monitor screen. It consists of a photocell and an optical
system placed in a small tube. When its tip is moved over the monitor screen, and pen
button is pressed, its photocell sensing element detects the screen location and sends the
corresponding signals to the CPU.

Uses:
1. Light Pens can be used as input coordinate positions by providing necessary
arrangements.
2. If background color or intensity, a light pen can be used as a locator.
3. It is used as a standard pick device with many graphics system.
4. It can be used as stroke input devices.
5. It can be used as valuators

Digitizers:
The digitizer is an operator input device, which contains a large, smooth board (the
appearance is similar to the mechanical drawing board) & an electronic tracking device,
which can be changed over the surface to follow existing lines. The electronic tracking
device contains a switch for the user to record the desire x & y coordinate positions. The
coordinates can be entered into the computer memory or stored or an off-line storage
medium such as magnetic tape.
Advantages:
1. Drawing can easily be changed.
2. It provides the capability of interactive graphics.

Disadvantages:
1. Costly
2. Suitable only for applications which required high-resolution graphics.

Touch Panels:
Touch Panels is a type of display screen that has a touch-sensitive transparent panel
covering the screen. A touch screen registers input when a finger or other object comes
in contact with the screen.

When the wave signals are interrupted by some contact with the screen, that located is
recorded. Touch screens have long been used in military applications.

Voice Systems (Voice Recognition):


Voice Recognition is one of the newest, most complex input techniques used to interact
with the computer. The user inputs data by speaking into a microphone. The simplest form
of voice recognition is a one-word command spoken by one person. Each command is
isolated with pauses between the words.

Voice Recognition is used in some graphics workstations as input devices to accept voice
commands. The voice-system input can be used to initiate graphics operations or to enter
data. These systems operate by matching an input against a predefined dictionary of
words and phrases.

Advantage:
1. More efficient device.
2. Easy to use
3. Unauthorized speakers can be identified

Disadvantages:
1. Very limited vocabulary
2. Voice of different operators can't be distinguished.

Image Scanner
It is an input device. The data or text is written on paper. The paper is feeded to scanner.
The paper written information is converted into electronic format; this format is stored in
the computer. The input documents can contain text, handwritten material, picture extra.

By storing the document in a computer document became safe for longer period of time.
The document will be permanently stored for the future. We can change the document
when we need. The document can be printed when needed.

Scanning can be of the black and white or colored picture. On stored picture 2D or 3D
rotations, scaling and other operations can be applied.

Types of image Scanner:


1. Flat Bed Scanner: It resembles a photocopy machine. It has a glass top on its top.
Glass top in further covered using a lid. The document to be scanned is kept on glass
plate. The light is passed underneath side of glass plate. The light is moved left to right.
The scanning is done the line by line. The process is repeated until the complete line is
scanned. Within 20-25 seconds a document of 4" * 6" can be scanned.

2. Hand Held Scanner: It has a number of LED's (Light Emitting Diodes) the LED's are
arranged in the small case. It is called a Hand held Scanner because it can be kept in
hand which performs scanning. For scanning the scanner is moved over document from
the top towards the bottom. Its light is on, while we move it on document. It is dragged
very slowly over document. If dragging of the scanner over the document is not proper,
the conversion will not correct.
Output Devices

It is an electromechanical device, which accepts data from a computer and translates


them into form understand by users.

Following are Output Devices:

1. Printers
2. Plotters

Printers:
Printer is the most important output device, which is used to print data on paper.

Types of Printers: There are many types of printers which are classified on various
criteria as shown in fig:

1. Impact Printers: The printers that print the characters by striking against the ribbon
and onto the papers are known as Impact Printers.

These Printers are of two types:

1. Character Printers
2. Line Printers
2. Non-Impact Printers: The printers that print the characters without striking against the
ribbon and onto the papers are called Non-Impact Printers. These printers print a complete
page at a time, therefore, also known as Page Printers.

Page Printers are of two types:

1. Laser Printers
2. Inkjet Printers

Dot Matrix Printers:


Dot matrix has printed in the form of dots. A printer has a head which contains nine pins.
The nine pins are arranged one below other. Each pin can be activated independently. All
or only the same needles are activated at a time. When needless is not activated, and
then the tip of needle stay in the head. When pin work, it comes out of the print head. In
nine pin printer, pins are arranged in 5 * 7 matrixes.

Advantage:
1. Dot Matrix Printers prints output as dots, so it can print any shape of the character. This
allows the printer to print special character, charts, graphs, etc.
2. Dot Matrix Printers come under the category of impact printers. The printing is done when
the hammer pin strikes the inked ribbon. The impressions are printed on paper. By placing
multiple copies of carbon, multiple copies of output can be produced.
3. It is suitable for printing of invoices of companies.

Daisy Wheel Printers:


Head is lying on a wheel and Pins corresponding to characters are like petals of Daisy,
that's why called Daisy wheel printer.
Advantage:
1. More reliable than DMPs
2. Better Quality

Disadvantage:
1. Slower than DMPs

Drum Printers:
These are line printers, which prints one line at a time. It consists of a drum. The shape of
the drum is cylindrical. The drum is solid and has characters embossed on it in the form
of vertical bands. The characters are in circular form. Each band consists of some
characters. Each line on drum consists of 132 characters. Because there are 96 lines so
total characters are (132 * 95) = 12, 672.

Drum contains a number of hammers also.

Chain Printers:
These are called as line printers. These are used to print one line at a line. Basically, chain
consists of links. Each link contains one character. Printers can follow any character set
style, i.e., 48, 64 or 96 characters. Printer consists of a number of hammers also.

Advantages:
1. Chain or Band if damaged can be changed easily.
2. It allows printing of different form.
3. Different Scripts can be printed using this printer.

Disadvantages:
1. It cannot print charts and graphs.
2. It cannot print characters of any shape.
3. Chain Printers is impact printer, hammer strikes so it is noisy.

Non-Impact Printers:
Inkjet Printers:
These printers use a special link called electrostatic ink. The printer head has a special
nozzle. Nozzle drops ink on paper. Head contains up to 64 nozzles. The ink dropped is
deflected by the electrostatic plate. The plate is fixed outside the nozzle. The deflected ink
settles on paper.

Advantages:
1. These produce high quality of output as compared to the dot matrix.
2. A high-quality output can be produced using 64 nozzles printed.
3. Inkjet can print characters in a variety of shapes.
4. Inkjet can print special characters.
5. The printer can print graphs and charts.

Disadvantages:

1. Inkjet Printers are slower than dot matrix printers.


2. The cost of inkjet is more than a dot matrix printer.

Laser Printers:
These are non-impact page printers. They use laser lights to produces the dots needed
to form the characters to be printed on a page & hence the name laser printers.

The output is generated in the following steps:

Step1: The bits of data sent by processing unit act as triggers to turn the laser beam on
& off.

Step2: The output device has a drum which is cleared & is given a positive electric charge.
To print a page the modulated laser beam passing from the laser scans back & forth the
surface of the drum. The positive electric charge on the drum is stored on just those parts
of the drum surface which are exposed to the laser beam create the difference in electric
which charges on the exposed drum surface.
Step3: The laser exposed parts of the drum attract an ink powder known as toner.

Step4: The attracted ink powder is transferred to paper.

Step5: The ink particles are permanently fixed to the paper by using either heat or
pressure technique.

Step6: The drum rotates back to the cleaner where a rubber blade cleans off the excess
ink & prepares the drum to print the next page.

Plotters
Plotters are a special type of output device. It is suitable for applications:

1. Architectural plan of the building.


2. CAD applications like the design of mechanical components of aircraft.
3. Many engineering applications.

Advantage:
1. It can produce high-quality output on large sheets.
2. It is used to provide the high precision drawing.
3. It can produce graphics of various sizes.
4. The speed of producing output is high.

Drum Plotter:
It consists of a drum. Paper on which design is made is kept on the drum. The drum can
rotate in both directions. Plotters comprised of one or more pen and penholders. The
holders are mounted perpendicular to drum surface. The pens are kept in the holder,
which can move left to the right as well as right to the left. The graph plotting program
controls the movement of pen and drum.

Flatbed Plotter:
It is used to draw complex design and graphs, charts. The Flatbed plotter can be kept over
the table. The plotter consists of pen and holder. The pen can draw characters of various
sizes. There can be one or more pens and pen holding mechanism. Each pen has ink of
different color. Different colors help to produce multicolor design of document. The area
of plotting is also variable. It can vary A4 to 21'*52'.

It is used to draw

1. Cars
2. Ships
3. Airplanes
4. Shoe and dress designing
5. Road and highway design

Graphics Software:
There are two types of Graphics Software.

1. General Purpose Packages: Basic Functions in a general package include those for
generating picture components (straight lines, polygons, circles and other figures), setting
color and intensity values, selecting views, and applying transformations.
Example of general purpose package is the GL (Graphics Library), GKS, PHIGS, PHIGS+
etc.

2. Special Purpose Packages: These packages are designed for non programmers, so
that these users can use the graphics packages, without knowing the inner details.

Example of special purpose package is

1. Painting programs
2. Package used for business purpose
3. Package used for medical systems.
4. CAD packages

Scan Conversion Definition


It is a process of representing graphics objects a collection of pixels. The graphics objects
are continuous. The pixels used are discrete. Each pixel can have either on or off state.

The circuitry of the video display device of the computer is capable of converting binary
values (0, 1) into a pixel on and pixel off information. 0 is represented by pixel off. 1 is
represented using pixel on. Using this ability graphics computer represent picture having
discrete dots.

Any model of graphics can be reproduced with a dense matrix of dots or points. Most
human beings think graphics objects as points, lines, circles, ellipses. For generating
graphical object, many algorithms have been developed.

Advantage of developing algorithms for scan conversion


1. Algorithms can generate graphics objects at a faster rate.
2. Using algorithms memory can be used efficiently.
3. Algorithms can develop a higher level of graphical objects.

Examples of objects which can be scan converted


1. Point
2. Line
3. Sector
4. Arc
5. Ellipse
6. Rectangle
7. Polygon
8. Characters
9. Filled Regions

The process of converting is also called as rasterization. The algorithms implementation


varies from one computer system to another computer system. Some algorithms are
implemented using the software. Some are performed using hardware or firmware. Some
are performed using various combinations of hardware, firmware, and software.

Pixel or Pel:
The term pixel is a short form of the picture element. It is also called a point or dot. It is
the smallest picture unit accepted by display devices. A picture is constructed from
hundreds of such pixels. Pixels are generated using commands. Lines, circle, arcs,
characters; curves are drawn with closely spaced pixels. To display the digit or letter matrix
of pixels is used.

The closer the dots or pixels are, the better will be the quality of picture. Closer the dots
are, crisper will be the picture. Picture will not appear jagged and unclear if pixels are
closely spaced. So the quality of the picture is directly proportional to the density of pixels
on the screen.

Pixels are also defined as the smallest addressable unit or element of the screen. Each
pixel can be assigned an address as shown in fig:

Different graphics objects can be generated by setting the different intensity of pixels and
different colors of pixels. Each pixel has some co-ordinate value. The coordinate is
represented using row and column.

P (5, 5) used to represent a pixel in the 5th row and the 5th column. Each pixel has some
intensity value which is represented in memory of computer called a frame buffer. Frame
Buffer is also called a refresh buffer. This memory is a storage area for storing pixels
values using which pictures are displayed. It is also called as digital memory. Inside the
buffer, image is stored as a pattern of binary digits either 0 or 1. So there is an array of 0
or 1 used to represent the picture. In black and white monitors, black pixels are
represented using 1's and white pixels are represented using 0's. In case of systems
having one bit per pixel frame buffer is called a bitmap. In systems with multiple bits per
pixel it is called a pixmap.

Scan Converting a Point


Each pixel on the graphics display does not represent a mathematical point. Instead, it
means a region which theoretically can contain an infinite number of points. Scan-
Converting a point involves illuminating the pixel that contains the point.

Example: Display coordinates points as shown in fig would both


be represented by pixel (2, 1). In general, a point p (x, y) is represented by the integer part
of x & the integer part of y that is pixels [(INT (x), INT (y).
Scan Converting a Straight Line
A straight line may be defined by two endpoints & an equation. In fig the two endpoints
are described by (x1,y1) and (x2,y2). The equation of the line is used to determine the x, y
coordinates of all the points that lie between these two endpoints.

Using the equation of a straight line, y = mx + b where m = & b = the y interrupt, we


can find values of y by incrementing x from x =x1, to x = x2. By scan-converting these
calculated x, y values, we represent the line as a sequence of pixels.

Properties of Good Line Drawing Algorithm:


1. Line should appear Straight: We must appropriate the line by choosing addressable
points close to it. If we choose well, the line will appear straight, if not, we shall produce
crossed lines.
The lines must be generated parallel or at 45° to the x and y-axes. Other lines cause a
problem: a line segment through it starts and finishes at addressable points, may happen
to pass through no another addressable points in between.

2. Lines should terminate accurately: Unless lines are plotted accurately, they may
terminate at the wrong place.

3. Lines should have constant density: Line density is proportional to the no. of dots
displayed divided by the length of the line.

To maintain constant density, dots should be equally spaced.

4. Line density should be independent of line length and angle: This can be done by
computing an approximating line-length estimate and to use a line-generation algorithm
that keeps line density constant to within the accuracy of this estimate.

5. Line should be drawn rapidly: This computation should be performed by special-


purpose hardware.
Algorithm for line Drawing:
1. Direct use of line equation
2. DDA (Digital Differential Analyzer)
3. Bresenham's Algorithm

Direct use of line equation:


It is the simplest form of conversion. First of all scan P1 and P2 points. P1 has co-ordinates
(x1',y1') and (x2' y2' ).

Then m = (y2',y1')/( x2',x1') and b =

If value of |m|≤1 for each integer value of x. But do not consider

If value of |m|>1 for each integer value of y. But do not consider

Example: A line with starting point as (0, 0) and ending point (6, 18) is given. Calculate
value of intermediate points and slope of line.

Solution: P1 (0,0) P7 (6,18)

x1=0
y1=0
x2=6
y2=18

We know equation of line is


y =m x + b
y = 3x + b..............equation (1)

put value of x from initial point in equation (1), i.e., (0, 0) x =0, y=0
0 = 3 x 0 + b
0 = b ⟹ b=0

put b = 0 in equation (1)


y = 3x + 0
y = 3x

Now calculate intermediate points


Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
Let x = 6 ⟹ y = 3 x 6 ⟹ y = 18
So points are P1 (0,0)
P2 (1,3)
P3 (2,6)
P4 (3,9)
P5 (4,12)
P6 (5,15)
P7 (6,18)

Algorithm for drawing line using equation:


Step1: Start Algorithm

Step2: Declare variables x1,x2,y1,y2,dx,dy,m,b,

Step3: Enter values of x1,x2,y1,y2.


The (x1,y1) are co-ordinates of a starting point of the line.
The (x2,y2) are co-ordinates of a ending point of the line.

Step4: Calculate dx = x2- x1

Step5: Calculate dy = y2-y1

Step6: Calculate m =

Step7: Calculate b = y1-m* x1

Step8: Set (x, y) equal to starting point, i.e., lowest point and xendequal to largest value of
x.

If dx < 0
then x = x2
y = y2
xend= x1
If dx > 0
then x = x1
y = y1
xend= x2
Step9: Check whether the complete line has been drawn if x=x end, stop

Step10: Plot a point at current (x, y) coordinates

Step11: Increment value of x, i.e., x = x+1

Step12: Compute next value of y from equation y = mx + b

Step13: Go to Step9.

Program to draw a line using LineSlope Method


1. #include <graphics.h>
2. #include <stdlib.h>
3. #include <math.h>
4. #include <stdio.h>
5. #include <conio.h>
6. #include <iostream.h>
7.
8. class bresen
9. {
10. float x, y, x1, y1, x2, y2, dx, dy, m, c, xend;
11. public:
12. void get ();
13. void cal ();
14. };
15. void main ()
16. {
17. bresen b;
18. b.get ();
19. b.cal ();
20. getch ();
21. }
22. Void bresen :: get ()
23. {
24. print ("Enter start & end points");
25. print ("enter x1, y1, x2, y2");
26. scanf ("%f%f%f%f",sx1, sx2, sx3, sx4)
27. }
28. void bresen ::cal ()
29. {
30. /* request auto detection */
31. int gdriver = DETECT,gmode, errorcode;
32. /* initialize graphics and local variables */
33. initgraph (&gdriver, &gmode, " ");
34. /* read result of initialization */
35. errorcode = graphresult ();
36. if (errorcode ! = grOK) /*an error occurred */
37. {
38. printf("Graphics error: %s \n", grapherrormsg (errorcode);
39. printf ("Press any key to halt:");
40. getch ();
41. exit (1); /* terminate with an error code */
42. }
43. dx = x2-x1;
44. dy=y2-2y1;
45. m = dy/dx;
46. c = y1 - (m * x1);
47. if (dx<0)
48. {
49. x=x2;
50. y=y2;
51. xend=x1;
52. }
53. else
54. {
55. x=x1;
56. y=y1;
57. xend=x2;
58. }
59. while (x<=xend)
60. {
61. putpixel (x, y, RED);
62. y++;
63. y=(x*x) +c;
64. }
65. }
OUTPUT:

Enter Starting and End Points


Enter (X1, Y1, X2, Y2) 200 100 300 200

DDA Algorithm
DDA stands for Digital Differential Analyzer. It is an incremental method of scan
conversion of line. In this method calculation is performed at each step but by using results
of previous steps.

Suppose at step i, the pixels is (xi,yi)

The line of equation for step i


yi=mxi+b......................equation 1

Next value will be


yi+1=mxi+1+b.................equation 2

m =
yi+1-yi=∆y.......................equation 3
yi+1-xi=∆x......................equation 4
yi+1=yi+∆y
∆y=m∆x
yi+1=yi+m∆x
∆x=∆y/m
xi+1=xi+∆x
xi+1=xi+∆y/m

Case1: When |M|<1 then (assume that x1<x2)


x= x1,y=y1 set ∆x=1
yi+1=y1+m, x=x+1
Until x = x2</x

Case2: When |M|<1 then (assume that y1<y2)


x= x1,y=y1 set ∆y=1

xi+1= , y=y+1
Until y → y2</y

Advantage:

1. It is a faster method than method of using direct use of line equation.


2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and y ,so plotting of same point twice is not possible.
4. This method gives overflow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.

Disadvantage:

1. It involves floating point additions rounding off is done. Accumulations of round off error cause accumulation of error.
2. Rounding off operations and floating point operations consumes a lot of time.
3. It is more suitable for generating line using the software. But it is less suited for hardware implementation.

DDA Algorithm:

Step1: Start Algorithm


Step2: Declare x1,y1,x2,y2,dx,dy,x,y as integer variables.

Step3: Enter value of x1,y1,x2,y2.

Step4: Calculate dx = x2-x1

Step5: Calculate dy = y2-y1

Step6: If ABS (dx) > ABS (dy)


Then step = abs (dx)
Else

Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1

Step8: Set pixel (x, y)

Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))

Step10: Repeat step 9 until x = x2

Step11: End Algorithm

Advertisement

Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How many points will
needed to generate such line?

Solution: P1 (2,3) P11 (6,15)

x1=2
y1=3
x2= 6
y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12

m=

For calculating next value of x takes x = x +


Program to implement DDA Line Drawing Algorithm:
1. #include<graphics.h>
2. #include<conio.h>
3. #include<stdio.h>
4. void main()
5. {
6. intgd = DETECT ,gm, i;
7. float x, y,dx,dy,steps;
8. int x0, x1, y0, y1;
9. initgraph(&gd, &gm, "C:\\TC\\BGI");
10. setbkcolor(WHITE);
11. x0 = 100 , y0 = 200, x1 = 500, y1 = 300;
12. dx = (float)(x1 - x0);
13. dy = (float)(y1 - y0);
14. if(dx>=dy)
15. {
16. steps = dx;
17. }
18. else
19. {
20. steps = dy;
21. }
22. dx = dx/steps;
23. dy = dy/steps;
24. x = x0;
25. y = y0;
26. i = 1;
27. while(i<= steps)
28. {
29. putpixel(x, y, RED);
30. x += dx;
31. y += dy;
32. i=i+1;
33. }
34. getch();
35. closegraph();
36. }
Output:

Symmetrical DDA:
The Digital Differential Analyzer (DDA) generates lines from their differential equations.
The equation of a straight line is

The DDA works on the principle that we simultaneously increment x and y by small steps
proportional to the first derivatives of x and y. In this case of a straight line, the first
derivatives are constant and are proportional to ∆x and ∆y . Therefore, we could generate
a line by incrementing x and y by ϵ ∆x and ϵ ∆y, where ϵ is some small quantity. There are
two ways to generate points

1. By rounding to the nearest integer after each incremental step, after rounding we display
dots at the resultant x and y.
2. An alternative to rounding the use of arithmetic overflow: x and y are kept in registers
that have two parts, integer and fractional. The incrementing values, which are both less
than unity, are repeatedly added to the fractional parts and whenever the results
overflows, the corresponding integer part is incremented. The integer parts of the x and y
registers are used in plotting the line. In the case of the symmetrical DDA, we choose ε=2 -
n
,where 2n-1≤max (|∆x|,|∆y|)<2π

A line drawn with the symmetrical DDA is shown in fig:

Example: If a line is drawn from (0, 0) to (10, 5) with a symmetrical DDA

1. How many iterations are performed?

2. How many different points will be generated?

Solutions: Given: P1 (0,0) P2 (10,5)


x1=0
y1=0
x2=10
y2=5
dx = 10 - 0 = 10
dy = 5 - 0 = 0

P1 (0,0) will be considered starting points


P3 (1,0.5) point not plotted
P4 (2, 1) point plotted
P5 (3, 1.5) point not plotted
P6 (4,2) point plotted
P7 (5,2.5) point not plotted
P8 (6,3) point plotted
P9 (7,3.5) point not plotted
P10 (8, 4) point plotted
P11 (9,4.5) point not plotted
P12 (10,5) point plotted

Following Figure show line plotted using these points.

Bresenham's Line Algorithm


This algorithm is used for scan converting a line. It was developed by Bresenham. It is an
efficient method because it involves only integer addition, subtractions, and multiplication
operations. These operations can be performed very rapidly so lines can be generated
quickly.

In this method, next pixel selected is that one who has the least distance from true line.

The method works as follows:

Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our may to the night,
one pixel position at a time in the horizontal direction toward P 2'(x2',y2').

Once a pixel in choose at any step

The next pixel is

1. Either the one to its right (lower-bound for the line)


2. One top its right and up (upper-bound for the line)

The line is best approximated by those pixels that fall the least distance from the path
between P1',P2'.
To chooses the next one between the bottom pixel S and top pixel T.
If S is chosen
We have xi+1=xi+1 and yi+1=yi
If T is chosen
We have xi+1=xi+1 and yi+1=yi+1

The actual y coordinates of the line at x = xi+1is


y=mxi+1+b

The distance from S to the actual line in y direction


s = y-yi

The distance from T to the actual line in y direction


t = (yi+1)-y

Now consider the difference between these 2 distance values


s-t

When (s-t) <0 ⟹ s < t

The closest pixel is S

When (s-t) ≥0 ⟹ s < t

The closest pixel is T


This difference is
s-t = (y-yi)-[(yi+1)-y]
= 2y - 2yi -1

Substituting m by and introducing decision variable


di=△x (s-t)

di=△x (2 (xi+1)+2b-2yi-1)
=2△xyi-2△y-1△x.2b-2yi△x-△x
di=2△y.xi-2△x.yi+c

Where c= 2△y+△x (2b-1)

We can write the decision variable di+1 for the next slip on
di+1=2△y.xi+1-2△x.yi+1+c
di+1-di=2△y.(xi+1-xi)- 2△x(yi+1-yi)

Since x_(i+1)=xi+1,we have


di+1+di=2△y.(xi+1-xi)- 2△x(yi+1-yi)

Special Cases

If chosen pixel is at the top pixel T (i.e., di≥0)⟹ yi+1=yi+1


di+1=di+2△y-2△x

If chosen pixel is at the bottom pixel T (i.e., di<0)⟹ yi+1=yi


di+1=di+2△y

Finally, we calculate d1
d1=△x[2m(x1+1)+2b-2y1-1]
d1=△x[2(mx1+b-y1)+2m-1]

Since mx1+b-yi=0 and m = , we have


d1=2△y-△x

Advantage:
1. It involves only integer arithmetic, so it is simple.

2. It avoids the generation of duplicate points.

3. It can be implemented using hardware because it does not use multiplication and
division.
4. It is faster as compared to DDA (Digital Differential Analyzer) because it does not
involve floating point calculations like DDA Algorithm.

Disadvantage:
1. This algorithm is meant for basic line drawing only Initializing is not a part of
Bresenham's line algorithm. So to draw smooth lines, you should want to look into a
different algorithm.

Bresenham's Line Algorithm:


Step1: Start Algorithm

Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy

Step3: Enter value of x1,y1,x2,y2


Where x1,y1are coordinates of starting point
And x2,y2 are coordinates of Ending point

Step4: Calculate dx = x2-x1


Calculate dy = y2-y1
Calculate i1=2*dy
Calculate i2=2*(dy-dx)
Calculate d=i1-dx

Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
If dx < 0
Then x = x2
y = y2
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2

Step6: Generate point at (x,y)coordinates.

Step7: Check if whole line is generated.


If x > = xend
Stop.

Step8: Calculate co-ordinates of the next pixel


If d < 0
Then d = d + i1
If d ≥ 0
Then d = d + i2
Increment y = y + 1

Step9: Increment x = x + 1

Step10: Draw a point of latest (x, y) coordinates


Step11: Go to step 7

Step12: End of Algorithm

Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find intermediate
points.

Solution: x1=1
y1=1
x2=8
y2=5
dx= x2-x1=8-1=7
dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8
I2=2*(∆y-∆x)=2*(4-7)=-6
d = I1-∆x=8-7=1

x y d=d+I1 or I2

1 1 d+I2=1+(-6)=-5

2 2 d+I1=-5+8=3

3 2 d+I2=3+(-6)=-3

4 3 d+I1=-3+8=5

5 3 d+I2=5+(-6)=-1

6 4 d+I1=-1+8=7

7 4 d+I2=7+(-6)=1

8 5
Program to implement Bresenham's Line Drawing Algorithm:
1. #include<stdio.h>
2. #include<graphics.h>
3. void drawline(int x0, int y0, int x1, int y1)
4. {
5. int dx, dy, p, x, y;
6. dx=x1-x0;
7. dy=y1-y0;
8. x=x0;
9. y=y0;
10. p=2*dy-dx;
11. while(x<x1)
12. {
13. if(p>=0)
14. {
15. putpixel(x,y,7);
16. y=y+1;
17. p=p+2*dy-2*dx;
18. }
19. else
20. {
21. putpixel(x,y,7);
22. p=p+2*dy;}
23. x=x+1;
24. }
25. }
26. int main()
27. {
28. int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
29. initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
30. printf("Enter co-ordinates of first point: ");
31. scanf("%d%d", &x0, &y0);
32. printf("Enter co-ordinates of second point: ");
33. scanf("%d%d", &x1, &y1);
34. drawline(x0, y0, x1, y1);
35. return 0;
36. }
Output:
Differentiate between DDA Algorithm and Bresenham's Line
Algorithm:

DDA Algorithm Bresenham's Line Algorithm

1. DDA Algorithm use floating point, i.e., Real 1. Bresenham's Line Algorithm use fixed point,
Arithmetic. i.e., Integer Arithmetic

2. DDA Algorithms uses multiplication & division 2.Bresenham's Line Algorithm uses only
its operation subtraction and addition its operation

3. Bresenham's Algorithm is faster than DDA


3. DDA Algorithm is slowly than Bresenham's
Algorithm in line because it involves only addition
Line Algorithm in line drawing because it uses
& subtraction in its calculation and uses only
real arithmetic (Floating Point operation)
integer arithmetic.

4. DDA Algorithm is not accurate and efficient as 4. Bresenham's Line Algorithm is more accurate
Bresenham's Line Algorithm. and efficient at DDA Algorithm.

5. Bresenham's Line Algorithm can draw circle


5.DDA Algorithm can draw circle and curves but
and curves with more accurate than DDA
are not accurate as Bresenham's Line Algorithm
Algorithm.

You might also like