You are on page 1of 125

`

Computer Graphics

UNIT-1
OVERVIEW OF COMPUTER
GRAPHICS

1
Computer Graphics
Definitioin: 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.


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.


The special procedure determines which pixel will provide the best
approximation to the desired picture or graphics object this process is known
as Rasterization.

2
Pixel: is the smallest addressable graphical unit represented on the
computer screen.
Image: is a visual representation of something. ...

An image is a picture that has been created or copied and stored in
electronic form.

An image can be described in terms of vector graphics or raster graphics.

An image stored in raster form is sometimes called a bitmap.

Object: In computer graphics, an object refers to an item within a graphic,
such as a graphic circle or a square.

6
Rastor aind Vector Zoom

7
8
9
10
Disadvantages of Random scan
display
19
Architecture of Raster Scan Display
Termiinology related to raster scain

23
29
Applicatioins of Computer Graphics
User iinterface: Visual object which we observe on screen which
communicates with user is one of the most useful applications of
the computer graphics.
Data Represeintatioin: 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.
Ofce automatioin aind desktop publishiing: - 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 draftiing aind desigin: - It uses graphics to
design components and system such as automobile bodies
structures of building etc.

30
Simulatioin aind ainimatioin: - Use of graphics in simulation
makes mathematic models and mechanical systems more
realistic and easy to study.
Art aind commerce: - There are many tools provided by
graphics which allows used to make their picture animated
and attracted which are used in advertising.
Process cointrol: - 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.
Educatioin aind traiiniing: - Computer graphics can be used
to generate models of physical, fnancial and economic
systems. These models can be used as educational aids.
Image processiing: - It is used to process image by changing
property of the image.
31

Virtual Reality (VR) is the use of computer technology to create a
simulated environment. Unlike traditional user interfaces, VR
places the user inside an experience.


Instead of viewing a screen in front of them, users are
immersed and able to interact with 3D worlds.


By simulating as many senses as possible, such as vision,
hearing, touch, even smell, the computer is transformed into
a gatekeeper to this artificial world. The only limits to near-real
VR experiences are the availability of content and
cheap computing power.
3D Computer Graphics

In the 2D system, we use only two coordinates X and Y but in 3D,
an extra coordinate Z is added.


3D graphics techniques and their application are fundamental to
the entertainment, games, and computer-aided design industries.

It is a continuing area of research in scientifc visualization.



Furthermore, 3D graphics components are now a part of almost
every personal computer and, although traditionally intended for
graphics-intensive software such as games, they are increasingly
being used by other applications.

33
34
Liine Segmeint iin Computer Graphics

35
36
Circle iin Computer Graphics

A circle is a set of points in the XY-plane at a fxed distance from


the center point(x,y).
Ceintre of the circle: The centre point is called the centre of the
circle.

Radius of the circle:radius is one-half the measure of the


diameter.
r= d/2

Circumfereince: The length of the circle is called circumference.


C= π x d or C=2πr

37
Arc: Continuous part of the circle is called arc.
Chord: A line segment within a circle that touches two
points on the circle is called chord.

38
GLS University
Faculty of Computer Applications & Information Technology
Sub: Computer Graphics
Unit-1

Topic: Cathode Ray Tube


Advantages:
a) They operate at any resolution, geometry and aspect ratio without the need for rescaling the
image.
b) CRTs run at the highest pixel resolutions generally available.
c) Produce a very dark black and the highest contrast levels normally available. Suitable for use
even in dimly lit or dark environments.
d) CRTs produce the very best color and gray-scale and are the reference standard for all
professional calibrations. They have a perfectly smooth gray-scale with an infinite number of
intensity levels. Other display technologies are expected to reproduce the natural power-law
Gamma curve of a CRT, but can only do so approximately.
e) CRTs have fast response times and no motion artifacts. Best for rapidly moving or changing
images.
f) CRTs are less expensive than comparable displays using other display technologies.
Disadvantages:
a) The CRT's Gaussian beam profile produces images with softer edges that are not as sharp as an
LCD at its native resolution. Imperfect focus and color registration also reduce sharpness. Generally
sharper than LCDs at other than native resolutions.
b) All color CRTs produce annoying Moiré patterns. Many monitors include Moiré reduction, which
normally doesn't eliminate the Moiré interference patterns entirely.
c) Subject to geometric distortion and screen regulation problems. Also affected by magnetic fields
from other equipment including other CRTs.
d) Relatively bright but not as bright as LCDs. Not suitable for very brightly lit environments.
e) Some CRTs have a rounded spherical or cylindrical shape screen. Newer CRTs are flat.
f) CRTs give off electric, magnetic and electromagnetic fields. There is considerable controversy as
to whether any of these pose a health hazard, particularly magnetic fields. The most authoritative
scientific studies conclude that they are not harmful but some people remain unconvinced.
g) They are large, heavy, and bulky. They consume a lot of electricity and produce a lot of heat.
`

Computer Graphics

UNIT-2
GRAPHICS PRIMITIVES

1
Line Styles


Different Line styles are used to differentiate each of the line from one
another.

Dashed line an

be generated by inter-dash spaces beween the dashes.

2
Line Attributes

3
4
5
Different colours is also used with different shapes
of pens and brushes.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Antialiasing


In computer graphics, antialiasing is a software technique for diminishing
jaggies - stairstep-like lines that should be smooth.


Jaggies occur because the output device, the monitor or printer, doesn't have a
high enough resolution to represent a smooth line.


Antialiasing reduces the prominence of jaggies by surrounding the stairsteps
with intermediate shades of gray (for gray-scaling devices) or color (for color
devices).


Although this reduces the jagged appearance of the lines, it also makes them
fuzzier.

23
The errors caused by aliasing are called artefacts. Common aliasing artefacts
include jagged profiles, disappearing or improperly rendered fine detail, and
disintegrating textures.

24
Errors by Antialiasing

Jagged profless

The picture on the left shows the sampling grid superimposed on
the original scene.


The picture on the right is the rendered image.


A jagged profile is quite evident in the rendered image. Also
known as "jaggies", jagged silhouettes are probably the most
familiar effect caused by aliasing.

25
26
Improperly Rendered


The original scene on the left shows a group of small polygons. In
the rendered scene, one of the two red rectangles disappears entirely,
and the other doubles in width.


Two of the orange triangles disappear. Although the two yellow
triangles are identical in size, one is larger than the other in the
rendered image.

27
28
Disintegrating textures


This is a checkered texture on a plane. The checkers should become
smaller as the distance from the viewer increases.


However, the checkers become larger or irregularly shaped when
their distance from the viewer becomes too great.


Simply increasing the resolution will not remove this artefact.
Increasing the resolution will only move the artefact closer to the
horizon.

29
30
31
32
Line Drawing Algorithms-
In computer graphics, popular algorithms used to generate lines are-

1. Digital Differential Analyzer (DDA) Line Drawing Algorithm


2. Bresenham Line Drawing Algorithm
3. Mid Point Line Drawing Algorithm

DDA Algorithm-
DDA Algorithm is the simplest line drawing algorithm.

Given the starting and ending coordinates of a line,

DDA Algorithm attempts to generate the points between the starting and ending coordinates.

Procedure-

Given-
• Starting coordinates = (X0, Y0)
• Ending coordinates = (Xn, Yn)

The points generation using DDA Algorithm involves the following steps-

Step-01:

Calculate ΔX, ΔY and M from the given input.X, ΔX, ΔY and M from the given input.Y and M from the given input.
These parameters are calculated as-
• ΔX, ΔY and M from the given input.X = Xn – X0
• ΔX, ΔY and M from the given input.Y =Yn – Y0
• M = ΔX, ΔY and M from the given input.Y / ΔX, ΔY and M from the given input.X
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
if (absolute (ΔX, ΔY and M from the given input.X) > absolute (ΔX, ΔY and M from the given input.Y))
Steps = absolute (ΔX, ΔY and M from the given input.X);
else
Steps = absolute (ΔX, ΔY and M from the given input.Y);

Step-03:
Suppose the current point is (Xp, Yp) and the next point is (Xp+1, Yp+1).

Find the next point by following the below three cases-

Step-04:
Keep repeating Step-03 until the end point is reached or the number of generated new points
(including the starting and ending points) equals to the steps count.
PRACTICE PROBLEMS BASED ON DDA ALGORITHM

Problem-01:
Calculate the points between the starting point (5, 6) and ending point (8, 12).

Solution-
Given-
• Starting coordinates = (X0, Y0) = (5, 6)
• Ending coordinates = (Xn, Yn) = (8, 12)

Step-01:
Calculate ΔX, ΔY and M from the given input.X, ΔX, ΔY and M from the given input.Y and M from the given input.
• ΔX, ΔY and M from the given input.X = Xn – X0 = 8 – 5 = 3
• ΔX, ΔY and M from the given input.Y =Yn – Y0 = 12 – 6 = 6
• M = ΔX, ΔY and M from the given input.Y / ΔX, ΔY and M from the given input.X = 6 / 3 = 2

Step-02:
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.X|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 < |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.Y|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 = 3 < 6, so number of steps = ΔX, ΔY and M from the given input.Y = 6

Step-03:
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)


5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
7.5 11 (8, 11)
8 12 (8, 12)
Problem-02:

Calculate the points between the starting point (5, 6) and ending point (13, 10).

Solution-

Given-
• Starting coordinates = (X0, Y0) = (5, 6)
• Ending coordinates = (Xn, Yn) = (13, 10)

Step-01:

Calculate ΔX, ΔY and M from the given input.X, ΔX, ΔY and M from the given input.Y and M from the given input.
• ΔX, ΔY and M from the given input.X = Xn – X0 = 13 – 5 = 8
• ΔX, ΔY and M from the given input.Y =Yn – Y0 = 10 – 6 = 4
• M = ΔX, ΔY and M from the given input.Y / ΔX, ΔY and M from the given input.X = 4 / 8 = 0.50
Step-02:

Calculate the number of steps.


As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.X|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 > |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.Y|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 = 8 > 4, so number of steps = ΔX, ΔY and M from the given input.X = 8

Step-03:

As M < 1, so case-01 is satisfied.


Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)


5 6 6 6.5 (6, 7)
7 7 (7, 7)
8 7.5 (8, 8)
9 8 (9, 8)
10 8.5 (10, 9)
11 9 (11, 9)
12 9.5 (12, 10)
13 10 (13, 10)
Problem-03:

Calculate the points between the starting point (1, 7) and ending point (11, 17).

Solution-

Given-
• Starting coordinates = (X0, Y0) = (1, 7)
• Ending coordinates = (Xn, Yn) = (11, 17)

Step-01:

Calculate ΔX, ΔY and M from the given input.X, ΔX, ΔY and M from the given input.Y and M from the given input.
• ΔX, ΔY and M from the given input.X = Xn – X0 = 11 – 1 = 10
• ΔX, ΔY and M from the given input.Y =Yn – Y0 = 17 – 7 = 10
• M = ΔX, ΔY and M from the given input.Y / ΔX, ΔY and M from the given input.X = 10 / 10 = 1

Step-02:

Calculate the number of steps.


As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.X|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 = |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6ΔX, ΔY and M from the given input.Y|ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6 = 10 = 10, so number of steps = ΔX, ΔY and M from the given input.X = ΔX, ΔY and M from the given input.Y = 10

Step-03:

As M = 1, so case-02 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)


1 7 2 8 (2, 8)
3 9 (3, 9)
4 10 (4, 10)
5 11 (5, 11)
6 12 (6, 12)
7 13 (7, 13)
8 14 (8, 14)
9 15 (9, 15)
10 16 (10, 16)
11 17 (11, 17)

Advantages of DDA Algorithm-

The advantages of DDA Algorithm are-


• It is a simple algorithm.
• It is easy to implement.
• It avoids using the multiplication operation which is costly in terms of time complexity.
Disadvantages of DDA Algorithm-

The disadvantages of DDA Algorithm are-


• There is an extra overhead of using round off( ) function.
• Using round off( ) function increases time complexity of the algorithm.
• Resulted lines are not smooth because of round off( ) function.
• The points generated by this algorithm are not accurate.

Practice Questions

• Draw a line using DDA algorithm from (0,0) to (4,6)


• Draw a line using DDA algorithm from (2,3) to (9,8)
• Draw a line using DDA algorithm from (1,1) to (8,7)
1
2
`

Computer Graphics

UNIT-3
POLYGON

1
POLYGON

2
Types Of POLYGON

3
4
5
6
7
8
9
Winding Number method

10
11
12
13
Scan line Fill Method

14
15
16
17
`

18
19
Boundary Fill Algorithm

20
21
22
8 connected pixel position

23
4 connected pixel position

24
25
26
27
28
29
30
31
32
Flood-Fill Algorithm

33
34
35
36
37
38
39
40
41
42
Difference between Flood fill and Boundary
Fill

43

You might also like