CG Unit-1 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Computer Graphics

Rohit Rana
Assistant Professor
CSE/IT Dept.
Vidya College of Engineering

1
Introduction

Computer graphics is an art of drawing pictures on


computer screens with the help of programming. It
involves computations, creation, and manipulation of data.
In other words, we can say that computer graphics is a
rendering tool for the generation and manipulation of
images.

2
Cathode Ray Tube
The primary output device in a graphical system is the video monitor. The main element
of a video monitor is the Cathode Ray Tube CRT, shown in the following illustra on.
The opera on of CRT is very simple −
• The electron gun emits a beam of electrons cathode rays.
• The electron beam passes through focusing and de ec on systems that direct it
towards speci ed posi ons on the phosphor-coated screen.
• When the beam hits the screen, the phosphor emits a small spot of light at each
posi on contacted by the electron beam.
• It redraws the picture by direc ng the electron beam back over the same screen
points quickly.

3
ti
ti
fi
ti
ti
fl
ti
ti
CRT

4
There are two ways Random scan and Raster scan by which we
can display an object on the screen.
Raster Scan
In a raster scan system, the electron beam is swept across the screen, one row at a
time from top to bottom. As the electron beam moves across each row, the beam
intensity is turned on and off to create a pattern of illuminated spots.
Picture definition is stored in memory area called the Refresh Buffer or Frame
Buffer. This memory area holds the set of intensity values for all the screen points.
Stored intensity values are then retrieved from the refresh buffer and “painted” on
the screen one row scan line at a time as shown in the following illustration.
Each screen point is referred to as a pixel picture element or pel.
At the end of each scan line, the electron beam returns to the left side of the
screen to begin displaying the next scan line.

5
6
Random Scan Vect Scan
In this technique, the electron beam is directed only to the part of the screen
where the picture is to be drawn rather than scanning from left to right and
top to bottom as in raster scan. It is also called vector display, stroke-
writing display, or calligraphic display.
Picture definition is stored as a set of line-drawing commands in an area of
memory referred to as the refresh display file. To display a specified
picture, the system cycles through the set of commands in the display file,
drawing each component line in turn. After all the line-drawing commands
are processed, the system cycles back to the first line command in the list.
Random-scan displays are designed to draw all the component lines of a
picture 30 to 60 times each second.

7
or
8
Differentiate between Random and Raster Scan Display:

9
Application of Computer Graphics
Computer Graphics has numerous applications, some of which are listed below −

Education and Training: Computer-generated model of the physical, nancial and economic system is
often used as educational aids. Model of physical systems, physiological system, population trends or
equipment can help trainees to understand the operation of the system.
For some training applications, particular systems are designed. For example Flight Simulator.

Flight Simulator: It helps in giving training to the pilots of airplanes. These pilots spend much of their
training not in a real aircraft but on the ground at the controls of a Flight Simulator.
Advantages:
1. Fuel Saving
2. Safety
3. Ability to familiarize the training with a large number of the world's airports.

10

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

Computer-Generated Maps: Town planners and transportation engineers can use computer-generated
maps which display data useful to them in their planning work.
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.

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
◦ Scienti c Reports
◦ Economic Data for research reports
◦ Managerial Reports
◦ Consumer Information Bulletins
◦ And other types of reports

11
fi
Computer Art: Computer Graphics are also used in the eld of commercial arts. It is used to generate
television and advertising commercial.
Entertainment: Computer Graphics are now commonly used in making motion pictures, music videos and
television shows.
Visualization: It is used for visualization of scientists, engineers, medical personnel, business analysts for
the study of a large amount of information.
Educational Software: Computer Graphics is used in the development of educational software for making
computer-aided instruction.
Printing Technology: Computer Graphics is used for printing technology and textile design.
Example of Computer Graphics Packages:
1. LOGO
2. COREL DRAW
3. AUTO CAD
4. 3D STUDIO
5. CORE
6. GKS (Graphics Kernel System)
7. PHIGS
8. CAM (Computer Graphics Meta le)
9. CGI (Computer Graphics Interface)
12
fi
fi
Types of Computer Graphics
Interactive and Passive Graphics
Non-Interactive or Passive Computer Graphics:
In non-interactive computer graphics, the picture is produced on the monitor, and the user does not
have any controlled over the image, i.e., the user cannot make any change in the rendered image.
One example of its Titles shown on T.V.
Non-interactive Graphics involves only one-way communication between the computer and the user,
User can see the produced image, and he cannot make any change in the image.
Interactive Computer Graphics:
In interactive Computer Graphics user have some controls over the picture, i.e., the user can make
any change in the produced image. One example of it is the ping-pong game.
Interactive Computer Graphics require two-way communication between the computer and the user.
A User can see the image and make any change by sending his command with an input device.

13
Frame Buffer: A digital frame buffer is large, contiguous piece of computer
memory used to hold or map the image displayed on the screen.
• At a minimum, there is 1 memory bit for each pixel in the raster. This
amount of memory is called a bit plane.
• A 1024 x 1024 element requires 220 (210=1024;220=1024 x 1024)sq.raster
or 1,048,576 memory bits in a single bit plane.
• The picture is built up in the frame buffer one bit at a time.
• ∵ A memory bit has only two states (binary 0 or 1), a single bit plane yields
a black and white (monochrome display).
• As frame buffer is a digital device write raster CRT is an analog device.

14
Line Generation Algorithm
A line connects two points. It is a basic element in graphics. To draw a line, you need
two points between which you can draw a line. In the following three algorithms, we
refer the one point of line as X0, Y0 and the second point of line as X1, Y1.

DDA Algorithm (Digital Differential Analyzer)


DDA algorithm is the simple line generation algorithm which is explained step by step here.

Step 1 − Get the input of two end points (X0, Y0) and (X1, Y1).

Step 2 − Calculate the difference between two end points.


dx = X1 - X0
dy = Y1 - Y0

Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps to put
pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.

15
if (absolute(dx) > absolute(dy))
Steps = absolute(dx);
else
Steps = absolute(dy);

Step 4 − Calculate the increment in x coordinate and y coordinate.


Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;

Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and complete
the drawing of the line.
for(int v=0; v < Steps; v++)
{
x = x + Xincrement;
y = y + Yincrement;
putpixel(Round(x), Round(y));
}

16
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 over ow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.
Disadvantage:
1. It involves oating point additions rounding off is done. Accumulations of round off
error cause accumulation of error.
2. Rounding off operations and oating 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.
fl
fl
fl
Bresenham’s Line Generation
The Bresenham algorithm is another incremental scan conversion algorithm.
The big advantage of this algorithm is that, it uses only integer calculations.
Moving across the x axis in unit intervals and at each step choose between
two different y coordinates.

For example, as shown in the following illustration, from position 2,3 you need to
choose between 3,3 and 3,4. You would like the point that is closer to the original
line.

18
1. Input the two end-points of line, storing the left end-point in (x0,y0)(x0,y0).

2. Plot the point (x0,y0).

3. Calculate the constants ∆x, ∆y, 2∆y, and 2∆y–2∆x and get the first value for the decision
parameter as −

p0=2∆y−∆x

4. At each Xk along the line, starting at k = 0, perform the following test −

If pk < 0, the next point to plot is (xk+1,yk) and

pk+1=pk+2∆y

Otherwise, the next point to plot is (xk+1,yk+1) and

pk+1=pk+2∆y-2∆x

5. Repeat step 4 ∆x times.


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

20
Differentiate between DDA Algorithm and Bresenham's Line Algorithm:

21
De ning a Circle:
Circle is an eight-way symmetric gure. 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. 22
fi
fi
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)

23
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 re ection. The re ection is accomplished in
the following way:
The re ection is accomplished by reversing x, y co-ordinates.

24
fl
fl
fl
Midpoint Circle Algorithm:
1. Input radius r and circle center (xc, yc) and obtain the rst point on the circumference of a circle
centred on the origin as:-
(x0, y0) = (0, r)
2. Calculate the initial value of the decision parameter as:-
5
p∘ = − r
4
3. At each xk position, starting at k = 0, perform the following test: If pk < 0, the next point along the
circle centered on (0,0) is (xk+1, yk) and
pk+1 = pk + 2xk+1 + 1
Otherwise, the next point along the circle is (xk+1, yk-1) and
pk+1 = pk + 2xk+1 + 1 - 2yk+1
Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk - 2.

25
fi
4. Determine symmetry point in the other seven octants.

5. Move each calculated pixel position (x, y) onto the circular path centred on (xc, yc) and plot
the coordinate values:

x = x + xc, y = y+yc

6. Repeat step 3 through 5 until x ≥ y.


Thank you

You might also like