CG - Unit - 1
CG - Unit - 1
INTRODUCTION TO
C OMPUTER G RAPHICS
INTRODUCTION OF
C OMPUTER G RAPHIC S
The Process of transformation and
presentation of information in a visual form.
Training:
Specialised system for training like simulators can be
used for training the candidates in a way that can be
grasped in a short span of time with better
understanding. Creation of training modules using
computer graphics is simple and very useful.
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.
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.
APPLICATIONS OF
C OMPU TER G RAPHIC S
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
Financial Reports
Statistical Reports
Mathematical Reports
Scientific Reports
Economic Data for research reports
Managerial Reports
Consumer Information Bulletins
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
It presents the instruction set of the system, its design motivations and the
Geometry System architecture.
Very Large Scale Integration
By incorporating millions of transistors
into a single chip, integrated circuits (ICs)
are produced.
vlsi
The X Window System (X11) is an open
source, cross platform, client-server
computer software system that provides a
GUI in a distributed network environment.
(0,0) X Axis +X
Locator Devices
When queried, locator devices return a position
and/or orientation.
Tablet
Data Gloves
Keyboard
Image Scanners
Trackers
Scanners
Light Pens Touch Panels
MIDI devices
Camera/Vision Based
We want to draw a rectangle, how
do we describe it to a computer?
1. Define a set
(7,9) (14,9)
of points
(vertices) in 2D
space.
2. Given a set
of vertices, (7,3) (14,3)
draw lines
between
consecutive
vertices.
Vertex (pl. Vertices) - a point in 2 or 3 dimensional space.
1. Bitmap: Record every position
Bitmap - a rectangular array of bits mapped one-to-one with pixels.
2. Vector display: Position
relative
Vector display system - graphical output system that was based on strokes
(as opposed to pixels). Also known as: random, calligraphic, or stroke
displays.
Most common method is the VERTEX
method. Define the object as a set of points with
connectivity information.
Why is connectivity important?
Representing Objects
v 4 e 4
7 3
7 9
14 9
14 3
1 2 (7,9) (14,9)
2 3
3 4
4 1
(7,3) (14,3)
2. Graphics Mode :
In this mode display screen consists of an array of
pixels. Number of different shapes of an object can be
displayed.
2. M ODES
Basic Concept in Computer
Graphics
Pixel
- The most basic addressable image
element in a screen
CRT - Color triad (RGB phosphor dots)
LCD - Single color element
Pixel :
a pixel is the smallest piece of information in an image.
Pixels are normally arranged in a regular 2D grid,
and are often represented using dots or squares.
R E S O LU TION
Actual resolution is determined by
the video controller.
⚫ Most monitors can operate at several different
resolutions. They are
⚫ 640 X 480
⚫ 800 X 600
⚫ 1024 X 768
⚫ 1152 X 864
⚫ 1280 X 1024
As the resolution increases, image on
the screen gets smaller.
ASPECT RATIO
Aspect ratio ->horizontal and vertical sizes of computer
graphics.
Aspect ratio plays an important role in resizing. During resizing, the
aspect ratio must remain same in order to keep the image undistorted.
A distorted aspect ratio leads to stretching of the image.
Screen Resolution - measure of number of
pixels on a screen (x by y)
x - Horizontal screen resolution
y - Vertical screen resolution
e.g. 640 x 480, 1024 x 768 etc
number of pixels across the length and
width of a digital image
Dots per inch is a measure of spatial
printing, video or image scanner dot
density, in particular the number of
individual dots that can be placed in a line
within the span of 1 inch.
PPI describes the resolution in pixels of a digital
image whereas DPI describes the amount of ink
dots on a printed image.
Pitch - Size of a pixel, distance from center
to center of individual pixels.
Rasterisation
and televisions.
firing electrons from the back of the tube
straight-line segments.
Each line segment is drawn on the screen by
the first line and design all the lines of the image 30
to 60 time each second.
The process is shown in fig:
2. Shadow-Mask Method
C OLOR C R T M ONITORS
1. BEAM PENETRATION
M ETHOD:
The Beam-Penetration method has been used with random-
scan monitors.
In this method, the C RT 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.
2.S HADOW-M ASK M ETHOD:
Shadow Mask Method is commonly used in Raster-Scan
System because they produce a much wider range of
colors than the beam-penetration method.
It is used in the majority of color TV sets and monitors.
Construction: A shadow mask C RT has 3 phosphor color
dots at each pixel position.
One phosphor dot emits: red light
Another emits: green light
Third emits: blue light
This type of C RT 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 {to manage to go through or into something वस्तु में से
गुज़र जाना }with small round holes in a triangular pattern.
Figure shows the delta-delta shadow mask method
commonly used in color C RT system.
प्रकाशाचे ध्रुवीकरण
What is meant by polarization of light?
Hint: Polarisation of light is a property
shown by transverse waves. The light
waves which travel only in a single plane
are known as polarized light waves. The
process of transforming unpolarized light
waves to polarized light waves is called
the polarisation of light.
Polarization, in Physics, is defined as a
phenomenon caused due to the wave
nature of electromagnetic radiation.
A polarizer is a material which allows
passing the light from it having a certain
direction only.
Light with remaining angle is blocked.
Also divided into pixels, but without an
electron gun firing at a screen, LCDs have
cells that either allow light to flow
through, or block it.
High Resolution
Disadvantages:
Random-Scan monitors cannot display realistic
shades scenes.
ADVANTAGES AND
DISADVANTAGES
DIRECT VIEW S TORAG E
TU BES:
DVST terminals also use the random scan approach to
generate the image on the C RT 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
pattern.
Flood gun or Secondary
L E D (LIG HT E MITTING
DIODE):
L C D (LIQU ID C RYSTAL
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.
L C D 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.
Reflective Projection System Transmittive Projection
System
3D Display
3D Object
Graphics Memory 16
Original
colors
256 colors
LEDs work on the principle of Electroluminescence.
On passing a current through the diode, minority charge carriers and majority
charge carriers recombine at the junction.
On recombination, energy is released in the form of photons.
INTRODUCTION TO O PEN G L
OpenGL (Open Graphics Library) is a software interface to graphics
hardware.
The interface consists of over 250 different function calls which can be
used to draw complex two and three-dimensional scenes from simple
geometric primitives such as points, lines, and polygons.
There are also routines for rendering the scenes with control over
lighting, object surface properties, transparency, anti- aliasing and texture
mapping.
It is much easier to use and more portable but far less featured than the GLX
library. Functions performed include window definition, window control, and
monitoring of keyboard and mouse input.
GLUT also has limited support for creating pop-up menus. If you are going
to use the GLUT library you will need use #include <GL/glut.h> instead of
#include
Routines in the OpenGL graphics library can be called from
most major languages.
which you can use for many of the things which OpenGL
itself does not support.
OpenGL Utility Library (GLU)
The GLU is included with OpenGL and built using low-level OpenGL
commands.
It contains routines for setting up viewing and projection matrices,
polygonal tesselation and surface rendering.
When using the GLU library you will need to #include
<GL/glu.h> in your program. GLU routines begin with the prefix glu.
OpenGL Extension to the X Window System (GLX)OpenGL does not
include any routines for handling windowing operations so the GLX was
developed to fill this gap with regard to the X Window System.
Using GLX, you can enable your OpenGL programs to draw into a
window under the X Window System. GLX routines begin with the
prefix glx.
L IN ES AND L IN E
S EGM EN TS:
Above equation justify that slope between any point on
the line and point (x1, y1) is the same as the slope
between (x1, y1) and (x2, y2). Slope is usually denoted
by m and is defined as the change in height divided by
the change in width for any two points on the line.
Slope m is defined in equation form as follows:
There is a difference between line and line segment. The lines can
extend forever both forward and backward direction but a line
segment is a piece of line lying in between two end points P1 and
P2. If the end points are P1 = (x1, y1) and (x1, y1) = (x2, y2) and
these two points yield a equation y = mx +b then point P3 = (x3,
y3) lies on the segment if y3 = m x3 + b, x3 is in between x1 and
x2 and y3 is in between y1 and y2. We can identify where two
lines are intersecting. Two lines are crossing or intersecting
means they share common point. That point satisfies the equation
for both the lines. The intersection point is given by below
equation:
3) VECTORS AND VECTOR
G EN ERATION:
Vector has a single direction and length.
A vector is denoted by [Dx, Dy], where Dx
indicates how far to move in x-axis
direction and Dy indicates how far to
move in y-axis direction. Vectors specify
how far and in what direction to move,
but don’t specify from where to start.
If vector V1 = [Dx1, Dy1] and
= [Dx1 + Dx2, Dy1 + Dy2 ]
vector V2 = [Dx2, Dy2]
by Pythagorean
theorem.
ALGO RITHMS
DDA stands for Digital Differential Analyzer.
Step-01:
Calculate Δ X, Δ Y and M from the given input.
These parameters are calculated as-
Δ X = X n – X0
Δ Y =Y n – Y 0 DDA
M = ΔY / ΔX
Step-02:
Find the number of steps or points in between
the starting and ending coordinates.
if (absolute (ΔX) > absolute (ΔY))
Steps = absolute (ΔX);
else
Step-01:
Calculate Δ X, Δ Y and M from the given input.
ΔX = Xn – X0 = 8 – 5 = 3
Δ Y =Y n – Y 0 = 12 – 6 = 6
M = ΔY / ΔX = 6 / 3 = 2
Step-02:
Calculate the number of steps.
ΔY
=6
Step-03:
As M > 1, so case-03 is satisfied.
satisfied.
Problem-02:
Solution-
Given-
Starting coordinates = (X 0 , Y0 ) = (5, 6)
Ending coordinates = (X n , Y n ) = (13, 10)
Step-01:
Calculate Δ X, Δ Y and M from the given input.
Δ X = X n – X 0 = 13 – 5 = 8
Δ Y =Y n – Y 0 = 10 – 6 = 4
M = Δ Y / Δ X = 4 / 8 = 0.50
Step-02:
Calculate the number of steps.
ΔX
=8
Step-03:
As M < 1, so case-01 is satisfied.
satisfied.
To chooses the next one between the bottom pixel S and top pixel T.
If S is chosen(case 1)
We have xi+1=xi+1 and yi+1=yi
If T is chosen(case 2)
We have xi+1=xi+1 and yi+1=yi+1
Procedure-
Given-
Starting coordinates = (X , Y )
0 0
Ending coordinates = (X n , Yn )
ΔX = X – X
n 0
Δ Y =Y n – Y 0
Step-02:
Solution-
Given-
Step-01:
Calculate Δ X and Δ Y from the given input.
Δ X = X – X = 14 – 9 = 5
n 0
Δ Y =Y n – Y 0 = 22 – 18 = 4
Step-02:
Calculate the decision parameter.
P k = 2ΔY – Δ X
=2x4–5
=3
So, decision parameter P k = 3
Step-03:
As P k >= 0, so case-02 is satisfied.
Thus,
P k + 1 = P k + 2 Δ Y – 2 Δ X = 3 + (2 x 4) – (2 x 5) = 1
X k + 1 = X k + 1 = 9 + 1 = 10
Y k + 1 = Y k + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is
reached or number of iterations equals to 4 times.
(Number of iterations = Δ X – 1 = 5 – 1 = 4)
Problem-02:
Calculate the points between the starting coordinates
(20, 10) and ending coordinates (30, 18).
Solution-
Given-
Starting coordinates = (X 0 , Y0 ) = (20, 10)
Ending coordinates = (X n , Y n ) = (30, 18)
Step-01:
Calculate Δ X and Δ Y from the given input.
Δ X = X n – X 0 = 30 – 20 = 10
Δ Y =Y n – Y 0 = 18 – 10 = 8
Step-02:
Calculate the decision parameter.
Pk
= 2ΔY – ΔX
= 2 x 8 – 10
=6
So, decision parameter P k = 6
Step-03:
As P k >= 0, so case-02 is satisfied.
Thus,
P k + 1 = P k + 2 Δ Y – 2 Δ X = 6 + (2 x 8) – (2 x 10) = 2
X k + 1 = X k + 1 = 20 + 1 = 21
Y k + 1 = Y k + 1 = 10 + 1 = 11
Similarly, Step-03 is executed until the end point is reached or
number of iterations equals to 9 times.
(Number of iterations = Δ X – 1 = 10 – 1 = 9)
A D VAN TAG ES O F B R E S E N H AM L I N E
D R AWIN G A L G O R ITH M -
The advantages of Bresenham Line Drawing Algorithm
are-
It is easy to implement.
Algorithm.
The points generated by this algorithm are more accurate
than D DA Algorithm.
It uses fixed points only.
M ID P O I N T C IR C L E D R AWIN G
A L G O R ITH M -
Procedure-
Given-
Centre point of Circle = (X 0 , Y0)
Radius of Circle = R
The points generation using Mid Point Circle Drawing
Algorithm involves the following steps-
Step-01:
Assign the starting point coordinates (X 0 , Y0) as-
X0 = 0
Y0 = R
Step-02:
Calculate the value of initial decision parameter P 0 as-
P0 = 1 – R
Step-03:
Suppose the current point is (X , Y ) and the next
k k
point is (X k+1 , Y k+1 ).
Find the next point of the first octant depending
on the
value of decision parameter P k .
Follow the below two cases-
Step-04:
If the given centre point (X , Y ) is not (0, 0), then
0 0
do the following and plot the point-
X
plot = X c + X 0
Y plot = Y c + Y 0
Here, (X c , Yc ) denotes the current value of X and
Y coordinates.
Step-05:
Keep repeating Step-03 and Step-04 until X plot >=
Y plot .
Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry
property of circle.
This is depicted by the following figure-
P R AC T I C E P RO B L E M S BASED O N MID
P O I N T C I R C L E D R AW I N G
A LG O R I T H M -
Problem-01:
Given the centre point coordinates (0, 0) and radius as 10,
generate all the points to form a circle.
Solution-
Given-
Centre Coordinates of Circle (X 0 , Y0 ) = (0, 0)
Radius of Circle = 10
Step-01:
Assign the starting point coordinates (X 0 , Y0 ) as-
X0 = 0
Y 0 = R = 10
Step-02:
Calculate the value of initial decision parameter
P 0 as-
P0 = 1 – R
P 0 = 1 – 10
P 0 = -9
Step-03:
As P initial < 0, so case-01 is satisfied.
Thus,
Xk + 1 = X k + 1 = 0 + 1 = 1
Y k + 1 = Y k = 10
P k + 1 = P k + 2 x X k + 1 + 1 = -9 + (2 x 1) + 1 = -6
Step-04:
This step is not applicable here as the given centre point
coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until X k + 1 >= Y k + 1 as follows-
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by
swapping X and Y coordinates.
Now, the points for rest of the part are generated by following the signs of other
quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
The advantages of Mid Point Circle Drawing
Algorithm are-
It is a powerful and efficient algorithm.
equation of circle X 2 + Y 2 = R 2 .
It is easy to implement from the programmer’s
perspective.
This algorithm is used to generate curves on
raster displays.
A D VAN TAG ES O F M ID P O I N T C I R C L E
D R AWIN G A L G O R ITH M -
The disadvantages of Mid Point Circle Drawing
Algorithm are-
Accuracy of the generating points is an issue in
this algorithm.
The circle generated by this algorithm is not
smooth.
This algorithm is time consuming.
Step-02:
Calculate the value of initial decision parameter P 0 as-
P =3–2xR
Step-03:
Suppose the current point is (X k , Y k ) and the next point is (X k+1 , Yk+1 ).
Find the next point of the first octant depending on the value of decision
parameter P k .
Follow the below two cases-
Step-04:
If the given centre point (X 0 , Y0) is not (0, 0), then do the
following and plot the point-
X plot = X c + X 0
Y plot = Y c + Y 0
Here, (X c , Yc) denotes the current value of X and Y
coordinates.
Step-05:
Keep repeating Step-03 and Step-04 until Xplot => Y plot .
Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight
symmetry property of circle.
Problem-01:
Given the centre point coordinates (0, 0) and radius as 8,
generate all the points to form a circle.
Solution-
Given-
Centre Coordinates of Circle (X 0 , Y0) = (0, 0)
Radius of Circle = 8
Step-01:
Assign the starting point coordinates (X 0 , Y0) as-
X0 = 0
Y0 = R = 8
Step-02:
Calculate the value of initial decision parameter P 0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P 0 = -13
Step-03:
As P initial < 0, so case-01 is satisfied.
Thus,
Xk + 1 = X k + 1 = 0 + 1 = 1
Yk + 1 = Y k = 8
P k + 1 = P k + 4 x X k + 1 + 6 = -13 + (4 x 1) + 6 = -3
Step-04:
Step-05:
Step-03 is executed similarly until X k + 1 >= Y k + 1 as
follows-
Algorithm calculates all the points of octant-1 and
terminates.
Now, the points of octant-2 are obtained using the
mirror effect by swapping X and Y coordinates.
Now, the points for rest of the part are generated by following the signs
of other quadrants.
The other points can also be generated by calculating each octant
separately.
Here, all the points have been generated with respect to quadrant-1-
A D VAN TAG ES O F B R E S E N H AM C IR C L E
D R AWIN G A L G O R ITH M -
The advantages of Bresenham Circle Drawing
Algorithm are-
The entire algorithm is based on the simple
equation of circle X 2 + Y 2 = R 2 .
It is easy to implement.
The disadvantages of Bresenham Circle
Drawing Algorithm are-
Like Mid Point Algorithm, accuracy of the
generating points is an issue in this
algorithm.
This algorithm suffers when used to
generate
complex and high graphical images.
There is no significant enhancement with
respect to performance.
D ISA D VAN TAG ES O F B R E S E N H AM C IR C L E
D R AWIN G A L G O R ITH M -
ALIASIN G
In computer graphics, the process by which smooth
curves and other lines become jagged because the
resolution of the graphics device or file is not high
enough to represent a smooth curve.
In the line drawing algorithms, we have seen that