CG UNIT 1 - Unit 1 Notes
CG UNIT 1 - Unit 1 Notes
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.
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Use in Biology: Molecular biologist can display a picture of molecules and gain
insight into their structure with the help of computer graphics.
Computer Art: Computer Graphics are also used in the field of commercial arts.
It is used to generate television and advertising commercial.
LOGO
COREL DRAW
AUTO CAD
3D STUDIO
CORE
GKS (Graphics Kernel System)
PHIGS
CAM (Computer Graphics Metafile)
CGI (Computer Graphics Interface)
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
In interactive Computer Graphics user have some controls over the picture, i.e.,
the user can make any change in the produced image.
A User can see the image and make any change by sending his command with an
input device.
Advantages:
Higher Quality
More precise results or products
Greater Productivity
Lower analysis and design cost
Significantly enhances our ability to understand data and to perceive trends.
Resolution: Use to describe the number of pixels that are used on display image.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Aspect Ratio: It is the ratio of width to its height. Its mesuré is unit in length or
number of pixels.
Display File Memory: It is used for generation of the picture. It is used for
identification of graphic entities.
Display Controller:
o It handles interrupt
o It maintains timings
o It is used for interpretation of instruction.
Display Generator:
Display Console: It contains CRT, Light Pen, and Keyboard and deflection
system.
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:
CRT stands for Cathode Ray Tube. CRT is a technology used in traditional
computer monitors and televisions.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Random Scan System uses an electron beam which operates like a pencil to
create a line image on the CRT screen.
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:
Advantages
A CRT has the electron beam directed only to the parts of the screen where an
image is to be drawn.
Produce smooth line drawings.
High Resolution
Disadvantage
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
The raster scan system can store information of each pixel position, so it is
suitable for realistic display of objects.
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:
Advantages
Realistic image
Million Different colors to be generated
Shadow Scenes are possible.
Disadvantages
Low Resolution
Expensive
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Refresh rate depends or resolution Refresh rate does not depend on the picture.
Beam Penetration technology come under it. Shadow mark technology came under this.
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:
Shadow-Mask Method
Advantages:
Inexpensive
Disadvantages:
Only four colors are possible
Quality of pictures is not as good as with another method.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Shadow-Mask Method:
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 CRT has 3 phosphor color dots at each pixel position.
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Working:
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:
Realistic image
Million different colors to be generated
Shadow scenes are possible
Disadvantage:
Relatively expensive compared with the monochrome CRT.
Relatively poor resolution
Convergence Problem
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
Advantage:
No refreshing is needed.
High Resolution
Cost is very less
Disadvantage:
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
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
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).
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Cathode: It consists of fine wires. It delivers negative voltage to gas cells. The
voltage is released along with the negative axis.
Anode: It also consists of line wires. It delivers positive voltage. The voltage is
supplied along positive axis.
Fluorescent cells: It consists of small pockets of gas liquids when the voltage is
applied to this liquid (neon gas) it emits light.
Glass Plates: These plates act as capacitors. The voltage will be applied, the cell
will glow continuously.
Advantage:
High Resolution
Large screen size is also possible.
Less Volume
Less weight
Flicker Free Display
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Disadvantage:
Poor Resolution
Wiring requirement anode and the cathode is complex.
Its addressing is also complex.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Advantage:
Disadvantage:
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.
Keyboard
Mouse
Trackball
Spaceball
Joystick
Light Pen
Digitizer
Touch Panels
Voice Recognition
Image Scanner
Printers
Plotters
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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:
Impact Printers: The printers that print the characters by striking against the ribbon and onto
the papers are known as Impact Printers.
Character Printers
Line Printers
Laser Printers
Inkjet 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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
Head is lying on a wheel and Pins corresponding to characters are like petals of Daisy,
that's why called Daisy wheel printer.
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.
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
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.
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.
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
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Step3: The laser exposed parts of the drum attract an ink powder known as toner.
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.
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.
Painting programs
CAD packages
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Point
Line
Sector
Arc
Ellipse
Rectangle
Polygon
Characters
Filled Regions
Pixel or Pel:
The term pixel is a short form of the picture element. It is also called a point or
dot.
Pixels are generated using commands. Lines, circle, arcs, characters; curves are
drawn with closely spaced pixels.
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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:
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
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.
2. Lines should terminate accurately: Unless lines are plotted accurately, they may
terminate at the wrong place.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
3. Lines should have constant density: Line density is proportional to the no. of dots
displayed divided by the length of the line.
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.
Bresenham's Algorithm
DDA Algorithm:
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
Advantage:
It allows us to detect the change in the value of x and y ,so plotting of same point
twice is not possible.
Disadvantage:
It involves floating point additions rounding off is done. Accumulations of round off
error cause accumulation of error.
Rounding off operations and floating point operations consumes a lot of time.
It is more suitable for generating line using the software. But it is less suited for
hardware implementation.
This algorithm is used for scan converting a line. It was developed by Bresenham.
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.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
The line is best approximated by those pixels that fall the least distance from the
path between P1',P2'.
Advantage:
Disadvantage:
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.
Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
If dx < 0
Then x = x2
y = y2
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2
Step9: Increment x = x + 1
Step11: Go to step 7
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
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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
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
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 and curves with more accurate than DDA
Bresenham's Line Algorithm Algorithm.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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:
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Example: Let we determine a point (2, 7) of the circle then other points will be (2, -7), (-2, -
7), (-2, 7), (7, 2), (-7, 2), (-7, -2), (7, -2)
These seven points are calculated by using the property of reflection. The reflection is
accomplished in the following way:
There are two standards methods of mathematically defining a circle centered at the origin.
The first method defines a circle with the second-order polynomial equation as shown in fig:
y2=r2-x2
Where x = the x coordinate
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
y = the y coordinate
r = the circle radius
With the method, each x coordinate in the sector, from 90° to 45°, is found by stepping x
Algorithm:
xend=
Step2: Test to determine whether the entire circle has been scan-converted.
Step3: Compute y =
Step4: Plot the eight points found by symmetry concerning the center (h, k) at the
current (x, y) coordinates.
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Step5: Increment x = x + i
The second method of defining a circle makes use of polar coordinates as shown in
fig:
Algorithm:
r = circle radius
(h, k) = coordinates of the circle center
i = step size
θ_end=
θ=0
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Step3: Compute
x = r * cos θ y=r*sin?θ
Step4: Plot the eight points, found by symmetry i.e., the center (h, k), at the current
(x, y) coordinates.
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
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
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.
Step4: Calculate d = 3 - 2r
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)
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Step9: Go to step 6
Example: Plot 6 points of circle using Bresenham Algorithm. When radius of circle is 10
units. The circle has centre (50, 50).
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
So P1 (0,0)⟹(50,50)
P2 (1,10)⟹(51,60)
P3 (2,10)⟹(52,60)
P4 (3,9)⟹(53,59)
P5 (4,9)⟹(54,59)
P6 (5,8)⟹(55,58)
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:
Algorithm:
Step1: Put x =0, y =r in equation 2
We have p=1-r
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
y =y - 1 (end if)
x =x+1 (end loop)
Step3: End
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
class bresen
{
float x, y,a, b, r, p;
public:
void get ();
void cal ();
};
void main ()
{
bresen b;
b.get ();
b.cal ();
getch ();
}
Void bresen :: get ()
{
cout<<"ENTER CENTER AND RADIUS";
cout<< "ENTER (a, b)";
cin>>a>>b;
cout<<"ENTER r";
cin>>r;
}
void bresen ::cal ()
{
/* request auto detection */
int gdriver = DETECT,gmode, errorcode;
int midx, midy, i;
/* initialize graphics and local variables */
initgraph (&gdriver, &gmode, " ");
/* read result of initialization */
errorcode = graphresult ();
if (errorcode ! = grOK) /*an error occurred */
{
printf("Graphics error: %s \n", grapherrormsg (errorcode);
printf ("Press any key to halt:");
getch ();
Downloaded by Ho go ([email protected])
lOMoARcPSD|23231139
Output:
Downloaded by Ho go ([email protected])