Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views32 pages

Computer Graphics

Computer graphics is the art of creating visual representations using computers, primarily through pixels, which are the smallest graphical units on a screen. It serves as an effective communication tool, displaying information in easily understandable formats and enabling applications such as user interfaces, simulations, and design. Display devices like CRTs utilize raster and vector scan techniques to produce images, with various architectures supporting efficient graphics processing and rendering.

Uploaded by

temp60413412
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)
9 views32 pages

Computer Graphics

Computer graphics is the art of creating visual representations using computers, primarily through pixels, which are the smallest graphical units on a screen. It serves as an effective communication tool, displaying information in easily understandable formats and enabling applications such as user interfaces, simulations, and design. Display devices like CRTs utilize raster and vector scan techniques to produce images, with various architectures supporting efficient graphics processing and rendering.

Uploaded by

temp60413412
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/ 32

Unit-1 – Basics of Computer Graphics

What is computer Graphics?


Computer graphics is an art of drawing pictures, lines, charts, etc. using computers with the help of
programming. Computer graphics image is made up of number of pixels. Pixel is the smallest addressable
graphical unit represented on the computer screen.

Introduction
• Computer is information processing machine. User needs to communicate with computer and the computer
graphics is one of the most effective and commonly used ways of communication with the user.
• It displays the information in the form of graphical objects such as pictures, charts, diagram and graphs.
• Graphical objects convey more information in less time and easily understandable formats for example
statically graph shown in stock exchange.
• In computer graphics picture or graphics objects are presented as a collection of discrete pixels.
• We can control intensity and color of pixel which decide how picture look like.
• The special procedure determines which pixel will provide the best approximation to the desired picture or
graphics object this process is known as Rasterization.
• The process of representing continuous picture or graphics object as a collection of discrete pixels is
called Scan Conversion.

Advantages of computer graphics


• Computer graphics is one of the most effective and commonly used ways of communication with
computer.
• It provides tools for producing picture of “real-world” as well as synthetic objects such as mathematical
surfaces in 4D and of data that have no inherent geometry such as survey result.
• It has ability to show moving pictures thus possible to produce animations with computer graphics.
• With the use of computer graphics we can control the animation by adjusting the speed, portion of picture
in view the amount of detail shown and so on.
• It provides tools called motion dynamics. In which user can move objects as well as observes as per
requirement for example walk throw made by builder to show flat interior and surrounding.
• It provides facility called update dynamics. With this we can change the shape color and other properties of
object.
• Now in recent development of digital signal processing and audio synthesis chip the interactive graphics can
now provide audio feedback along with the graphical feed backs.

Application of computer graphics


• User interface: - Visual object which we observe on screen which communicates with user is one of the most
useful applications of the computer graphics.
• Plotting of graphics and chart in industry, business, government and educational organizations drawing like
bars, pie-charts, histogram’s are very useful for quick and good decision making.
• Office automation and desktop publishing: - It is used for creation and dissemination of information. It is
used in in-house creation and printing of documents which contains text, tables, graphs and other forms of
drawn or scanned images or picture.
• Computer aided drafting and design: - It uses graphics to design components and system such as automobile
bodies structures of building etc.

1
Unit-1 – Basics of Computer Graphics
• Simulation and animation: - Use of graphics in simulation makes mathematic models and mechanical
systems more realistic and easy to study.
• Art and commerce: - There are many tools provided by graphics which allows used to make their picture
animated and attracted which are used in advertising.
• Process control: - Now a day’s automation is used which is graphically displayed on the screen.
• Cartography: - Computer graphics is also used to represent geographic maps, weather maps,
oceanographic charts etc.
• Education and training: - Computer graphics can be used to generate models of physical, financial and
economic systems. These models can be used as educational aids.
• Image processing: - It is used to process image by changing property of the image.

Display devices
• Display devices are also known as output devices.
• Most commonly used output device in a graphics system is a video monitor.

Cathode-ray-tubes

Fig. 1.1: - Cathode ray tube.

• It is an evacuated glass tube.


• An electron gun at the rear of the tube produce a beam of electrons which is directed towards the screen of
the tube by a high voltage typically 15000 to 20000 volts
• Inner side screen is coated with phosphor substance which gives light when it is stroked bye electrons.
• Control grid controls velocity of electrons before they hit the phosphor.
• The control grid voltage determines how many electrons are actually in the electron beam. The negative the
control voltage is the fewer the electrons that pass through the grid.
• Thus control grid controls Intensity of the spot where beam strikes the screen.
• The focusing system concentrates the electron beam so it converges to small point when hits the phosphor
coating.
• Deflection system directs beam which decides the point where beam strikes the screen.
• Deflection system of the CRT consists of two pairs of parallel plates which are vertical and horizontal
deflection plates.
• Voltage applied to vertical and horizontal deflection plates is control vertical and horizontal deflection
respectively.
• There are two techniques used for producing images on the CRT screen:
2
Unit-1 – Basics of Computer Graphics
1. Vector scan/Random scan display.
2. Raster scan display.

Vector scan/Random scan display

CPU

I/O Port

Display
buffer (Interaction (Display
memory data) command)

Display controller CRT

Keyboard Mouse

Fig. 1.2: - Architecture of a vector display.

• Vector scan display directly traces out only the desired lines on CRT.
• If we want line between point p1 & p2 then we directly drive the beam deflection circuitry which focus
beam directly from point p1 to p2.
• If we do not want to display line from p1 to p2 and just move then we can blank the beam as we move it.
• To move the beam across the CRT, the information about both magnitude and direction is required. This
information is generated with the help of vector graphics generator.
• Fig. 1.2 shows architecture of vector display. It consists of display controller, CPU, display buffer memory and
CRT.
• Display controller is connected as an I/O peripheral to the CPU.
• Display buffer stores computer produced display list or display program.
• The Program contains point & line plotting commands with end point co-ordinates as well as character
plotting commands.
• Display controller interprets command and sends digital and point co-ordinates to a vector generator.
• Vector generator then converts the digital co-ordinate value to analog voltages for beam deflection circuits
that displace an electron beam which points on the CRT’s screen.
• In this technique beam is deflected from end point to end point hence this techniques is also called random
scan.
• We know as beam strikes phosphors coated screen it emits light but that light decays after few milliseconds
and therefore it is necessary to repeat through the display list to refresh the screen at least 30 times per
second to avoid flicker.
• As display buffer is used to store display list and used to refreshing, it is also called refresh buffer.

3
Unit-1 – Basics of Computer Graphics
Raster scan display

CPU

I/O Port

(Interaction (Display
data) command

Keyboard
Display controller
Mouse

00000000000000000
00000111111100000 CRT
00000000100000000 Video controller T
00000000100000000
00000000100000000

Refresh buffer

Fig. 1.3: - Architecture of a raster display.

• Fig. 1.3 shows the architecture of Raster display. It consists of display controller, CPU, video controller,
refresh buffer, keyboard, mouse and CRT.
• The display image is stored in the form of 1’s and 0’s in the refresh buffer.
• The video controller reads this refresh buffer and produces the actual image on screen.
• It will scan one line at a time from top to bottom & then back to the top.

Horizontal
Vertical OFF ON Retrace
Retrace

Fig. 1.4: - Raster scan CRT.

• In this method the horizontal and vertical deflection signals are generated to move the beam all over the
screen in a pattern shown in fig. 1.4.
• Here beam is swept back & forth from left to the right.
• When beam is moved from left to right it is ON.

4
Unit-1 – Basics of Computer Graphics
• When beam is moved from right to left it is OFF and process of moving beam from right to left after
completion of row is known as Horizontal Retrace.
• When beam is reach at the bottom of the screen. It is made OFF and rapidly retraced back to the top left to
start again and process of moving back to top is known as Vertical Retrace.
• The screen image is maintained by repeatedly scanning the same image. This process is known as
Refreshing of Screen.
• In raster scan displays a special area of memory is dedicated to graphics only. This memory is called
Frame Buffer.
• Frame buffer holds set of intensity values for all the screen points.
• That intensity is retrieved from frame buffer and display on screen one row at a time.
• Each screen point referred as pixel or Pel (Picture Element).
• Each pixel can be specified by its row and column numbers.
• It can be simply black and white system or color system.
• In simple black and white system each pixel is either ON or OFF, so only one bit per pixel is needed.
• Additional bits are required when color and intensity variations can be displayed up to 24-bits per pixel are
included in high quality display systems.
• On a black and white system with one bit per pixel the frame buffer is commonly called a Bitmap. And for
systems with multiple bits per pixel, the frame buffer is often referred as a Pixmap.

Difference between random scan and raster scan

5
Base of Difference Raster Scan System Random Scan System

Electron Beam The electron beam is swept across the The electron beam is directed only to the
screen, one row at a time, from top to parts of screen where a picture is to be
bottom. drawn.

Resolution Its resolution is poor because raster Its resolution is good because this system
system in contrast produces zigzag lines produces smooth lines drawings because CRT
that are plotted as discrete point sets. beam directly follows the line path.

Picture Definition Picture definition is stored as a set of Picture definition is stored as a set of line
intensity values for all screen points, drawing instructions in a display file.
called pixels in a refresh buffer area.

Realistic Display The capability of this system to store These systems are designed for line- drawing
intensity values for pixel makes it well and can’t display realistic shaded scenes.
suited for the realistic display of scenes
contain shadow and color pattern.

Draw an Image Screen points/pixels are used to draw an Mathematical functions are used to draw an
image. image.
Unit-1 – Basics of Computer Graphics
Raster graphics systems

Simple raster graphics system

CPU System Video


Monitor Memory Controller

System Bus

I/O Devices

Fig. 1.14: - Architecture of a simple raster graphics system.

• Raster graphics systems having additional processing unit like video controller or display controller.
• Here frame buffer can be anywhere in the system memory and video controller access this for refresh the
screen.
• In addition to video controller more processors are used as co-processors to accelerate the system in
sophisticated raster system.

Raster graphics system with a fixed portion of the system memory reserved for
the frame buffer

CPU System Frame Video Monitor


Memory Buffer Controller

System bus

I/O Devices

Fig. 1.15: - Architecture of a raster graphics system with a fixed portion of the system memory reserved for the
frame buffer.

13
Unit-1 – Basics of Computer Graphics
• A fixed area of the system memory is reserved for the frame buffer and the video controller can directly
access that frame buffer memory.
• Frame buffer location and the screen position are referred in Cartesian coordinates.
• For many graphics monitors the coordinate origin is defined at the lower left screen corner.
• Screen surface is then represented as the first quadrant of the two dimensional systems with positive X-
value increases as left to right and positive Y-value increases bottom to top.

Basic refresh operation of video controller

Raster Scan Horizontal and Vertical


Generator Deflection Voltages

X Y
register register

Memory Address Pixel


register Intensity

Frame Buffer

Fig. 1.16: - Basic video controller refresh operation.

• Two registers are used to store the coordinates of the screen pixels which are X and Y
• Initially the X is set to 0 and Y is set to Ymax.
• The value stored in frame buffer for this pixel is retrieved and used to set the intensity of the CRT beam.
• After this X register is incremented by one.
• This procedure is repeated till X becomes equals to Xmax.
• Then X is set to 0 and Y is decremented by one pixel and repeat above procedure.
• This whole procedure is repeated till Y is become equals to 0 and complete the one refresh cycle. Then
controller reset the register as top –left corner i.e. X=0 and Y=Ymax and refresh process start for next refresh
cycle.
• Since screen must be refreshed at the rate of 60 frames per second the simple procedure illustrated in figure
cannot be accommodated by typical RAM chips.
• To speed up pixel processing video controller retrieves multiple values at a time using more numbers of
registers and simultaneously refresh block of pixel.
• Such a way it can speed up and accommodate refresh rate more than 60 frames per second.

14
Unit-1 – Basics of Computer Graphics
Raster-graphics system with a display processor

Display Frame Video Monitor


Processor Buffer Controller
Memory

CPU Display System


Processor Memory

System Bus

I/O Devices

Fig. 1.17: - Architecture of a raster-graphics system with a display processor.

• One way to designing raster system is having separate display coprocessor.


• Purpose of display processor is to free CPU from graphics work.
• Display processors have their own separate memory for fast operation.
• Main work of display processor is digitalizing a picture definition given into a set of pixel intensity values for
store in frame buffer.
• This digitalization process is scan conversion.
• Display processor also performs many other functions such as generating various line styles (dashed,
dotted, or solid). Display color areas and performing some transformation for manipulating object.
• It also interfaces with interactive input devices such as mouse.
• For reduce memory requirements in raster scan system methods have been devised for organizing the frame
buffer as a line list and encoding the intensity information.
• One way to do this is to store each scan line as a set of integer pair one number indicate number of adjacent
pixels on the scan line that are having same intensity and second stores intensity value this technique is
called run-length encoding.
• A similar approach is when pixel. Intensity is changes linearly, encoded the raster as a set of rectangular
areas (cell encoding).
• Disadvantages of encoding is when run length is small it requires more memory then original frame buffer.
• It also difficult for display controller to process the raster when many sort runs are involved.

15
Unit-1 – Basics of Computer Graphics

Random- scan system

Monitor
CPU System Display
Memory Processor

System Bus

I/O Devices

Fig. 1.18: - Architecture of a simple random-scan system.

• An application program is input & stored in the system memory along with a graphics package.
• Graphics commands in the application program are translated by the graphics package into a display file
stored in the system memory.
• This display file is used by display processor to refresh the screen.
• Display process goes through each command in display file. Once during every refresh cycle.
• Sometimes the display processor in random scan system is also known as display processing unit or a
graphics controller.
• In this system graphics platform are drawn on random scan system by directing the electron beam along the
component times of the picture.
• Lines are defined by coordinate end points.
• This input coordinate values are converts to X and Y deflection voltages.
• A scene is then drawn one line at a time.

Graphics input devices

Keyboards
• Keyboards are used as entering text strings. It is efficient devices for inputting such a non-graphics data as
picture label.
• Cursor control key’s & function keys are common features on general purpose keyboards.
• Many other application of key board which we are using daily used of computer graphics are
commanding & controlling through keyboard etc.

Mouse
• Mouse is small size hand-held box used to position screen cursor.
• Wheel or roller or optical sensor is directing pointer on the according to movement of mouse.
• Three buttons are placed on the top of the mouse for signaling the execution of some operation.
• Now a day’s more advance mouse is available which are very useful in graphics application for example Z
mouse.

Trackball and Spaceball


• Trackball is ball that can be rotated with the finger or palm of the hand to produce cursor movement.
16
Unit-1 – Basics of Computer Graphics
• Potentiometer attached to the ball, measure the amount and direction of rotation.
• They are often mounted on keyboard or Z mouse.
• Space ball provide six-degree of freedom i.e. three dimensional.
• In space ball strain gauges measure the amount of pressure applied to the space ball to provide input for
spatial positioning and orientation as the ball is pushed or pulled in various directions.
• Space balls are used in 3D positioning and selection operations in virtual reality system, modeling,
animation, CAD and other application.

Joysticks
• A joy stick consists of small vertical lever mounted on a base that is used to steer the screen cursor around.
• Most joy sticks selects screen positioning according to actual movement of stick (lever).
• Some joy sticks are works on pressure applied on sticks.
• Sometimes joy stick mounted on keyboard or sometimes used alone.
• Movement of the stick defines the movement of the cursor.
• In pressure sensitive stick pressure applied on stick decides movement of the cursor. This pressure is
measured using strain gauge.
• This pressure sensitive joy sticks also called as isometric joy sticks and they are non movable sticks.

Data glove
• Data glove is used to grasp virtual objects.
• The glow is constructed with series of sensors that detect hand and figure motions.
• Electromagnetic coupling is used between transmitter and receiver antennas which used to provide position
and orientation of the hand.
• Transmitter & receiver Antenna can be structured as a set of three mutually perpendicular coils forming 3D
Cartesian coordinates system.
• Input from the glove can be used to position or manipulate object in a virtual scene.

Digitizer
• Digitizer is common device for drawing painting or interactively selecting coordinates position on an object.
• One type of digitizers is graphics tablet which input two dimensional coordinates by activating hand cursor
or stylus at selected position on a flat surface.
• Stylus is flat pencil shaped device that is pointed at the position on the tablet.

Image Scanner
• Image Scanner scan drawing, graph, color, & black and white photos or text and can stored for computer
processing by passing an optical scanning mechanism over the information to be stored.
• Once we have internal representation of a picture we can apply transformation.
• We can also apply various image processing methods to modify the picture.
• For scanned text we can apply modification operation.

Touch Panels
• As name suggest Touch Panels allow displaying objects or screen-position to be selected with the touch or
finger.
• A typical application is selecting processing option shown in graphical icons.

17
Unit-1 – Basics of Computer Graphics
• Some system such as a plasma panel are designed with touch screen
• Other system can be adapted for touch input by fitting transparent touch sensing mechanism over a screen.
• Touch input can be recorded with following methods.
1. Optical methods
2. Electrical methods
3. Acoustical methods

Optical method
• Optical touch panel employ a line of infrared LEDs along one vertical and one horizontal edge.
• The opposite edges of the edges containing LEDs are contain light detectors.
• When we touch at a particular position the line of light path breaks and according to that breaking line
coordinate values are measured.
• In case two line cuts it will take average of both pixel positions.
• LEDs operate at infrared frequency so it cannot be visible to user.

Electrical method
• An electrical touch panel is constructed with two transparent plates separated by small distance.
• One is coated with conducting material and other is coated with resistive material.
• When outer plate is touch it will come into contact with internal plate.
• When both plates touch it creates voltage drop across the resistive plate that is converted into
coordinate values of the selected position.

Acoustical method
• In acoustical touch panel high frequency sound waves are generated in horizontal and vertical direction
across a glass plates.
• When we touch the screen the waves from that line are reflected from finger.
• These reflected waves reach again at transmitter position and time difference between sending and
receiving is measure and converted into coordinate values.

Light pens
• Light pens are pencil-shaped device used to select positions by detecting light coming from points on the
CRT screen.
• Activated light pens pointed at a spot on the screen as the electron beam lights up that spot and generate
electronic pulse that causes the coordinate position of the electron beam to be recorded.

Voice systems
• It is used to accept voice command in some graphics workstations.
• It is used to initiate graphics operations.
• It will match input against predefined directory of words and phrases.
• Dictionary is setup for a particular operator by recording his voice.
• Each word is speak several times and then analyze the word and establishes a frequency pattern for that
word along with corresponding function need to be performed.
• When operator speaks command it will match with predefine dictionary and perform desired action.

18
Unit-1 – Basics of Computer Graphics

Graphics software and standard


• There are mainly two types of graphics software:
1. General programming package
2. Special-purpose application package

General programming package

• A general programming package provides an extensive set of graphics function that can be used in high level
programming language such as C or FORTRAN.
• It includes basic drawing element shape like line, curves, polygon, color of element transformation etc.
• Example: - GL (Graphics Library).

Special-purpose application package

• Special-purpose application package are customize for particular application which implement required
facility and provides interface so that user need not to vory about how it will work (programming). User can
simply use it by interfacing with application.
• Example: - CAD, medical and business systems.

Coordinate representations
• Except few all other general packages are designed to be used with Cartesian coordinate specifications.
• If coordinate values for a picture are specified is some other reference frame they must be converted to
Cartesian coordinate before giving input to graphics package.
• Special-purpose package may allow use of other coordinates which suits application.
• In general several different Cartesian reference frames are used to construct and display scene.
• We can construct shape of object with separate coordinate system called modeling coordinates or
sometimes local coordinates or master coordinates.
• Once individual object shapes have been specified we can place the objects into appropriate positions called
world coordinates.
• Finally the World-coordinates description of the scene is transferred to one or more output device reference
frame for display. These display coordinates system are referred to as “Device Coordinates” or “Screen
Coordinates”.
• Generally a graphic system first converts the world-coordinates position to normalized device coordinates. In
the range from 0 to 1 before final conversion to specific device coordinates.
• An initial modeling coordinates position ( Xmc,Ymc) in this illustration is transferred to a device coordinates
position(Xdc,Ydc) with the sequence ( Xmc,Ymc)🡪 ( Xwc,Ywc)🡪 ( Xnc,Ync)🡪 ( Xdc,Ydc).

Graphic Function
• A general purpose graphics package provides user with Varity of function for creating and manipulating
pictures.
• The basic building blocks for pictures are referred to as output primitives. They includes character, string, and
geometry entities such as point, straight lines, curved lines, filled areas and shapes defined with arrays of
color points.
• Input functions are used for control & process the various input device such as mouse, tablet, etc.
• Control operations are used to controlling and housekeeping tasks such as clearing display screen etc.
• All such inbuilt function which we can use for our purpose are known as graphics function
19
Unit-1 – Basics of Computer Graphics
Software Standard
• Primary goal of standardize graphics software is portability so that it can be used in any hardware systems &
avoid rewriting of software program for different system
• Some of these standards are discuss below

Graphical Kernel System (GKS)

• This system was adopted as a first graphics software standard by the international standard organization
(ISO) and various national standard organizations including ANSI.
• GKS was originally designed as the two dimensional graphics package and then later extension was
developed for three dimensions.

PHIGS (Programmer’s Hierarchical Interactive Graphic Standard)

• PHIGS is extension of GKS. Increased capability for object modeling, color specifications, surface
rendering, and picture manipulation are provided in PHIGS.
• Extension of PHIGS called “PHIGS+” was developed to provide three dimensional surface shading
capabilities not available in PHIGS.
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.

Algorithm for line Drawing:

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

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
P2'(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

Differentiate between DDA Algorithm and Bresenham's Line Algorithm:

DDA Algorithm Bresenham's Line Algorithm

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

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

3. DDA Algorithm is slowly than 3. Bresenham's Algorithm is faster than DDA


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

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

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

Defining a Circle:
Circle is an eight-way symmetric figure. The shape of circle is the same
in all quadrants. In each quadrant, there are two octants. If the calculation of the
point of one octant is done, then the other seven points can be calculated easily
by using the concept of eight-way symmetry.
For drawing, circle considers it at the origin. If a point is P1(x, y), then the other
seven points will be
So we will calculate only 45°arc. From which the whole circle can be
determined easily.
If we want to display circle on screen then the putpixel function is used for eight
points as shown below:
putpixel (x, y, color)
putpixel (x, -y, color)
putpixel (-x, y, color)
putpixel (-x, -y, color)
putpixel (y, x, color)
putpixel (y, -x, color)
putpixel (-y, x, color)
putpixel (-y, -x, color
Bresenham's Circle Algorithm:
Scan-Converting a circle using Bresenham's algorithm works as
follows: Points are generated from 90° to 45°, moves will be made only in the
+x & -y directions as shown in fig:

The best approximation of the true circle will be described by those pixels in the
raster that falls the least distance from the true circle. We want to generate the
points from

90° to 45°. Assume that the last scan-converted pixel is P1 as shown in fig. Each
new point closest to the true circle can be found by taking either of two actions.
1. Move in the x-direction one unit or
2. Move in the x- direction one unit & move in the negative y-direction one
unit.
Let D (Si) is the distance from the origin to the true circle squared minus the
distance to point P3 squared. D (Ti) is the distance from the origin to the true
circle squared minus the distance to point P2 squared. Therefore, the following
expressions arise.
D (Si)=(xi-1+1)2+ yi-12 -r2
D (Ti)=(xi-1+1)2+(yi-1 -1)2-r2
Since D (Si) will always be +ve & D (Ti) will always be -ve, a decision variable
d may be defined as follows:

di=D (Si )+ D (Ti)


Therefore,
di=(xi-1+1)2+ yi-12 -r2+(xi-1+1)2+(yi-1 -1)2-r2
From this equation, we can drive initial values of di as
If it is assumed that the circle is centered at the origin, then at the first step x = 0
& y = r.
Therefore,
di=(0+1)2+r2 -r2+(0+1)2+(r-1)2-r2
=1+1+r2-2r+1-r2
= 3 - 2r
Thereafter, if d_i<0,then only x is incremented.
xi+1=xi+1 di+1=di+ 4xi+6
& if di≥0,then x & y are incremented
xi+1=xi+1 yi+1 =yi+ 1
di+1=di+ 4 (xi-yi)+10

Bresenham's Circle Algorithm:


Step1: Start Algorithm
Step2: Declare p, q, x, y, r, d variables
p, q are coordinates of the center of the circle
r is the radius of the circle
Step3: Enter the value of r
Step4: Calculate d = 3 - 2r
Step5: Initialize x=0
&nbsy= r
Step6: Check if the whole circle is scan converted
If x > = y
Stop
Step7: Plot eight points by using concepts of eight-way symmetry. The center is
at (p, q). Current active pixel is (x, y).
putpixel (x+p, y+q)
putpixel (y+p, x+q)
putpixel (-y+p, x+q)
putpixel (-x+p, y+q)
putpixel (-x+p, -y+q)
putpixel (-y+p, -x+q)
putpixel (y+p, -x+q)
putpixel (x+p, -y-q)
Step8: Find location of next pixels to be scanned
If d < 0
then d = d + 4x + 6
increment x = x + 1
If d ≥ 0
then d = d + 4 (x - y) + 10
increment x = x + 1
decrement y = y - 1
Step9: Go to step 6
Step10: Stop Algorithm
MidPoint Circle Algorithm
It is based on the following function for testing the spatial relationship between
the arbitrary point (x, y) and a circle of radius r centered at the origin:

Now, consider the coordinates of the point halfway between pixel T and pixel S

This is called midpoint (xi+1,yi- ) and we use it to define a decision parameter:

Pi=f (xi+1,yi- ) = (xi+1)2+(yi- )2-r2 ...............equation 2


If Pi is -ve ⟹midpoint is inside the circle and we choose pixel T
If Pi is+ve ⟹midpoint is outside the circle (or on the circle)and we choose pixel
S.
The decision parameter for the next step is:

Pi+1=(xi+1+1)2+(yi+1- )2- r2............equation 3


Since xi+1=xi+1, we have

If pixel T is choosen ⟹Pi<0


We have yi+1=yi
If pixel S is choosen ⟹Pi≥0
We have yi+1=yi-1

We can continue to simplify this in n terms of (xi,yi) and get

Now, initial value of Pi (0,r)from equation 2

We can put ≅1
∴r is an integer
So, P1=1-r

Algorithm:
Step1: Put x =0, y =r in equation 2
We have p=1-r
Step2: Repeat steps while x ≤ y
Plot (x, y)
If (p<0)
Then set p = p + 2x + 3
Else
p = p + 2(x-y)+5
y =y - 1 (end if)
x =x+1 (end loop)
Step3: End

You might also like