Chapter 01
Overview of Computer Graphics System
Computer graphics is commonly seen as a computer science branch that deals with
the computerized image fusion theory and technology. As simple as a triangle
outline, a computer-generated image may represent a scene. The computer has
become a powerful tool for producing images quickly and economically. When a
computer is used to create images, the same process is followed as creating images
manually. The process’s primary computational steps give a boost to several
important computer graphics areas.
The term computer graphics has been used to define “almost everything on the
computer, including text or sound.” Generally, the term computer graphics refer to
the following things:
Computer representation and manipulation of image data.
Various technologies for creating and manipulating images.
Computer graphics study is a sub-field of computer science that studies methods
for digitally incorporating and manipulating visual content.
Definition of Computer Graphics
Computer graphics can be a series of images which is most often called a video or
single image. Computer graphics is the technology that concerns with designs and
pictures on computers. That’s why, computer graphics are visual representations of
data shown on a monitor made on a computer. “Computer graphics is the use of a
computer to define, store, manipulate, interrogate, and represent the pictorial
output.” An image in computer graphics is made up of a number of pixels.
Types of Computer Graphics
There are two kinds of computer graphics are–
Interactive Computer Graphics
Non-Interactive Computer Graphics
Interactive Computer Graphics
In interactive computer graphics, users have some controls over the image, i.e., the
user can make any changes to the image produced. Interactive Computer Graphics
involves computer-user two-way communication.
For Example:
Ping-pong game.
Drawing on touch screens.
Display weather forecast or other moving charts/graphs on the screen.
Animating pictures or graphics in movies.
Graphics animation in video games.
Non- Interactive Computer Graphics
Non-interactive computer graphics are also known as passive computer graphics. It
is a type of computer graphics in which the user has no control over the image. The
photo is completely controlled by the instructions of the program, not by the user.
For Example:
Screen savers.
Map representation of the data.
Graphic elements are used in the text, document, and PDF presentation.
Static images are used in mobile applications and websites.
Business graphics are used as brochures, business cards, menu of the hotel.
Representation of graphics
We can represent the graphics by following two ways:
1. Raster (Bitmap) Graphics
2. Vector Graphics
1. Raster Graphics: In raster graphics, the image is presented as a rectangular grid
of colored squares. Raster images are also called bitmap images. Bitmap images
are stored as the collection of small individual dots called pixels. Bitmap images
require high resolution and anti-aliasing for a smooth appearance.
For example– Paint, Photoshop, etc.
2. Vector Graphics: In vector graphics, the image is represented in the form of
continuous geometric objects: line, curve, etc. Vector images are not based on pixel
pattern. They use mathematical formulas to draw line and curves. The lines and
curves can be combined to create an image.
For Example– PowerPoint, Corel Draw, etc.
Difference between Raster and Vector Graphics:
Cathode Ray Tube
CRT stands for Cathode ray tube. It is a technology which is used in traditional
computer monitor and television. Cathode ray tube is a particular type of vacuum
tube that displays images when an electron beam collides on the radiant surface.
The primary output device in a graphical system is the video monitor.
Component of CRT:
Electron Gun: The electron gun is made up of several elements, mainly a
heating filament (heater) and a cathode. The electron gun is a source of electrons
focused on a narrow beam facing the CRT.
Focusing & Accelerating Anodes: These anodes are used to produce a narrow
and sharply focused beam of electrons.
Horizontal & Vertical Deflection Plates: These plates are used to guide the path
of the electron the beam. The plates produce an electromagnetic field that bends
the electron beam through the area as it travels.
Phosphorus-coated Screen: The phosphorus coated screen is used to produce
bright spots when the high-velocity electron beam hits it.
Color CRT Monitor: It is similar to a CRT monitor. The basic idea behind the
color CRT monitor is to combine three basic colors- Red, Green, and Blue. By
using these three colors, we can produce millions of different colors.
Line Drawing Algorithms
The Line drawing algorithm is a graphical algorithm which is used to represent the
line segment on discrete graphical media, i.e., printer and pixel-based media.
A line contains two points. The point is an important element of a line.
Properties of a Line Drawing Algorithm:
There are the following properties of a good Line Drawing Algorithm.
An algorithm should be precise: Each step of the algorithm must be adequately
defined.
Finiteness: An algorithm must contain finiteness. It means the algorithm stops
after the execution of all steps.
Easy to understand: An algorithm must help learners to understand the solution
in a more natural way.
Correctness: An algorithm must be in the correct manner.
Effectiveness: The steps of an algorithm must be valid and efficient.
Uniqueness: All steps of an algorithm should be clearly and uniquely defined,
and the result should be based on the given input.
Input: A good algorithm must accept at least one or more input.
Equation of the straight line
We can define a straight line with the help of the following equation.
y= mx + a
Where,
(x, y) = axis of the line.
m = Slope of the line.
a = Interception point
Let us assume we have two points of the line (p1, q1) and (p2, q2).
Now, we will put values of the two points in straight line equation, and we get
y = mx + a
q2 = mp2 + a …(1)
q1 = mp1 + a …(2) We have from equation (1) and (2)
q2 – q1 = mp2 – mp1
q2 – q1 = m (p2 –p1)
The value of m = (q2 – q1)/ (p2 –p1)
m = ▲q / ▲p
Algorithms of Line Drawing
There are following algorithms used for drawing a line:
DDA (Digital Differential Analyzer) Line Drawing Algorithm
Bresenham’s Line Drawing Algorithm
Mid-Point Line Drawing Algorithm
DDA (Digital Differential Analyzer) Line Drawing Algorithm
The Digital Differential Analyzer helps us to interpolate the variables on an
interval from one point to another point. We can use the digital Differential
Analyzer algorithm to perform rasterization on polygons, lines, and triangles.
Digital Differential Analyzer algorithm is also known as an incremental method of
scan conversion. In this algorithm, we can perform the calculation in a step by step
manner. We use the previous step result in the next step.
Formula:
m= dy/dx ;
dy =y2 -y1
dx =x2-x1
1) if 0<m≤1 then x1=x0+1, y1=y0+m
2) if -1≤m≤0 then x1=x0-1, y1=y0-m
3) if m<1 then x1=x0+1/m, y1=y0+1
4) if m<=-1 then x1=x0-1/m, y1=y0-1
Advantages of Digital Differential Analyzer
It is a simple algorithm to implement.
It is a faster algorithm than the direct line equation.
We cannot use the multiplication method in Digital Differential Analyzer.
Digital Differential Analyzer algorithm tells us about the overflow of the point
when the point changes its location.
Disadvantages of Digital Differential Analyzer
The floating-point arithmetic implementation of the Digital Differential Analyzer
is time-consuming.
The method of round-off is also time-consuming.
Sometimes the point position is not accurate.
Algorithm of Bresenham’s Line Drawing Algorithm
This algorithm was introduced by “Jack Elton Bresenham” in 1962. This algorithm
helps us to perform scan conversion of a line. It is a powerful, useful, and accurate
method. We use incremental integer calculations to draw a line. The integer
calculations include addition, subtraction, and multiplication.
Formula of Bresenham’s Line Drawing Algorithm
Step 1: we consider Starting point as (x1, y1) and ending point (x2, y2).
Step 2: Now, we have to calculate ▲x and ▲y.
▲x = x2-x1
▲y = y2-y1
m = ▲y/▲x
Step 3: Now, we will calculate the decision parameter Pk with following formula.
Pk = 2▲y-▲x
Step 4: The initial coordinates of the line are (x k, yk), and the next coordinates are
(xk+1, yk+1). Now, we are going to calculate two cases for decision parameter Pk
Case 1: If Pk < 0
Then
Pk+1 =Pk +2▲y
xk+1= xk +1
yk+1= yk
Case 2: If Pk ≥ 0
Then
Pk+1 =Pk +2▲y-2▲x
xk+1 =xk +1
yk+1 =yk +1
Step 5: We will repeat step 5 until we found the ending point of the line.
Example: A line has a starting point (9,18) and ending point (14,22). Apply
Bresenham’s Line Drawing algorithm to plot a line.
Solution: We have two coordinates,
Starting Point = (x1, y1) = (9,18)
Ending Point = (x2, y2) = (14,22)
Step 1: First, we calculate ▲x, ▲y.
▲x = x2 – x1 = 14-9 = 5
▲y = y2 – y1 = 22-18 = 4
Step 2: Now, we are going to calculate the decision parameter (Pk)
Pk= 2▲y-▲x
=2*4–5=3
The value of Pk = 3
Step 3: Now, we will check both the cases.
If Pk >= 0 Then Case 2 is satisfied.
Thus
Pk+1 = Pk+2▲y-2▲x =3+ (2 * 4) – (2 * 5) = 1
xk+1 =xk +1 = 9 + 1 = 10
yk+1 = yk +1 = 18 +1 = 19
Step 4: Now move to next step. We will calculate the coordinates until we reach
the end point of the line.
The Coordinates of drawn lines are-
P1 = (9, 18)
P2 = (10, 19)
P3 = (11, 20)
P4 =(12, 20)
P5 = (13, 21)
P6 = (14, 22)
Advantages of Bresenham’s Line Drawing Algorithm
It is simple to implement because it only contains integers.
It is quick and incremental
It is fast to apply but not faster than the Digital Differential Analyzer (DDA)
algorithm.
The pointing accuracy is higher than the DDA algorithm.
Disadvantages of Bresenham’s Line Drawing Algorithm
The Bresenham’s Line drawing algorithm only helps to draw the basic line.
The resulted draw line is not smooth.