You are on page 1of 24

COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

COMPUTER GRAPHICS LECTURE NOTES

TOPIC 1: INTRODUCTION TO COMPUTER GRAPHICS

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.

 TECHNICALLY, it’s about the production, manipulation and display of images


using computers

 PRACTICALLY, it’s about movies, games, art, training, advertising,


communication, design, …

COMPUTER GRAPHICS BASICS

I. APPLICATION OF COMPUTER GRAPHICS

Computer Graphics has numerous applications, some of which are listed below:

❑ Computer graphics user interfaces (GUIs) – A graphic, mouse-oriented paradigm


which allows the user to interact with a computer.

❑ Business presentation graphics - "A picture is worth a thousand words".

❑ Cartography - Drawing maps.

❑ Weather Maps – Real-time mapping, symbolic representations.

❑ Satellite Imaging - Geodesic images.

❑ Photo Enhancement - Sharpening blurred photos.

❑ Medical imaging - MRIs, CAT scans, etc. - Non-invasive internal examination.

❑ Engineering drawings - mechanical, electrical, civil, etc. - Replacing the blueprints


of the past.

❑ Typography - The use of character images in publishing - replacing the hard type of
the past. Architecture - Construction plans, exterior sketches - replacing the
blueprints and hand drawings of the past.

❑ Art - Computers provide a new medium for artists.

❑ Training - Flight simulators, computer aided instruction, etc.

❑ Entertainment - Movies and games.

❑ Simulation and modeling - Replacing physical modeling and enactment


Page 1 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

II. COMPONENTS OF COMPUTER GRAPHICS

❑ Modeling: Defining objects in terms of primitives, coordinates and characteristics

❑ Storing: storing scenes and images in memory and on disk

❑ Manipulating: changing the shape, position and characteristics of objects

❑ Rendering: applying physically based procedurs to generate (photorealistic) images


from scenes (using lighting and shading)

❑ Viewing: displaying images from various viewpoints on various devices

III. OUTPUT DEVICES

Computer Graphics can use many different output devices:

Video display devices

a. Cathode Ray Tube (CRT)

b. Liquid Crystal Display (LCD)

c. Plasma panels

d. Thin-film electroluminescent displays

e. Light-emitting diodes (LED)

Hard-copy devices

a. Ink-jet printer

b. Laser printer

c. Film recorder

d. Electrostatic printer

e. Pen plotter

NOTE: The most common display device is the Cathode Ray Tube (CRT) monitor.

IV. CATHODE RAY TUBE ( CRT ) MONITOR

Most common display device today are Characterized by:

❑ Evacuated glass bottle

❑ Extremely high voltage


Page 2 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

❑ Heating element (filament)

❑ Electrons pulled towards anode focusing cylinder

❑ Vertical and horizontal deflection plates

❑ Beam that strikes phosphor coating on front of tube

CRT DIAGRAM

HOW CRT WORKS


◼ The electron gun contains a filament that, when heated, emits a stream of electrons

◼ Electrons are focused with an electromagnet into a sharp beam and directed to a
specific point of the face of the picture tube

◼ The front surface of the picture tube is coated with small phospher dots

◼ When the beam hits a phospher dot it glows with a brightness proportional to the
strength of the beam and how long it is hit

◼ In a CRT the focusing system acts like a light lens with a focal length such that the
center of focus is the screen.

◼ The horizontal and vertical deflectors allow the electron beam to be focused on any
spot on the screen.

◼ The screen is coated with a special organic compound called a phosphor.

For color systems there are groups of three different phosphors, one to produce red
shades, one for green shades, and one for blue shades

Page 3 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

◼ Electrons hit the screen phosphor molecules and cause a ground state to singlet
excited state transition.

Phosphors are characterized by color (usually red, green, or blue) and persistence, which is
the time for the emitted light to decay to 10 % of the initial intensity.

High persistence phosphors allow for a lower refresh rate to avoid flicker,

Phosphers – terms…

❑ Flourescence: Light emitted while the phospher is being struck by electrons

❑ Phospherescence: Light emitted once the electron beam is removed

❑ Persistence: The time from the removal of the excitation to the moment when
phospherescence has decayed to 10% of the initial light output

V. CRT DISPLAY TECHNOLOGIES

There are two ways by which we can display an object on the screen.

a. Raster scan display

b. Random scan display

a. RASTER SCAN DISPLAYS

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.

Page 4 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

NOTE

❑ Raster: A rectangular array of points or dots

❑ Pixel: One dot or picture element of the raster

❑ Scan line: A row of pixels

The maximum number of points that can be displayed without overlap is called the
resolution.

Usually given as the number of horizontal points versus the number of vertical points

These are called pixels (picture elements),

The aspect ratio equals the ratio of vertical pixels/horizontal pixels for an equal length line.

It sometimes refers to the ratio of the horizontal dimension/vertical dimension

b. RANDOM SCAN DISPLAYS

Random Scan (Vector 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.

Page 5 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

TOPIC 2. LINE DRAWING ALGORITHMS

i. OVERVIEW

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.

Line drawing (Scan conversion) is drawing methods which create (or 'digitise') raster images
according to given picture 'primitives'.

The term is mainly used for drawing methods for 2D picture elements or primitives such as lines,
polygons and text.

Most (straight) lines and curves drawn in computer graphics satisfy equating a function of x and y
with zero.

– For example, we can re-express the line equation y=mx+c as 0=mx+c−y.

Most line and curve drawing methods effectively hunt along a pixel at a time, steering left or right as
needed to find a trail of pixels to be drawn, by calculating which next pixel will keep the relevant
function closest to zero.

A line segment in a scene is defined by the coordinate positions of the line end-points

Page 6 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

But what happens when we try to draw this on a pixel based display?

How do we choose which pixels to turn on?

The screen of a computer is a rectangular grade of pixels.

The computer produces images on raster devices only by turning the approximate pixels ON or OFF.

To draw a line on the screen, we first need to determine which pixels are to be switched ON.

The process of determining which combination of pixels provide the best approximation to the desired
line is called rasterization.

When rasterization is combined with rendering of a picture in a scan-line order, then it is known as
scan-conversion.

Page 7 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

The choice of the pixels is determined by the orientation of the line which is to be drawn:

– There is little difficulty for straight line.

– For other orientation of lines, selection of pixel is a difficult process.

There are four general requirements for line drawing:

– Lines must appear to be straight

– Lines should start and end accurately

– Lines should have constant brightness along their length

– Lines should be drawn rapidly.

NOTE: Simply choosing some pixels to draw often results in the familiar 'jaggies'.

– This is a form of aliasing.

aliasing denotes distortion or noise in images due to approximation.

TYPES OF ALIASING

Three main forms of aliasing:

❑ Outline aliasing

❑ Motion aliasing

❑ Color aliasing

Outline aliasing refers to the unintended jagged appearance of lines, curves or area
boundaries.

motion aliasing The use of integers in scan-conversion methods is usually taken to the
logical extreme of eliminating any use of floating point numbers, thus using only integer
pixel coordinates as parameters of the method.

Colour aliasing is due to colour approximation in pseudo-colour displays.

ii. LINE DRAWING ALGORITHMS

For straight lines, the equation of a straight line is used to determine the pixels:

• y = mx + c

Where:

• M = (y2 – y1)/(x2-x1)

Page 8 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

i. THE DIGITAL DIFFERENTIAL ANALYZER ALGORITHM (DDA)

❑ The digital differential analyzer (DDA) algorithm takes an incremental approach


in order to speed up scan conversion

❑ Simply calculate yk+1 based on yk

❑ As the x coordinates go up by one, the y coordinates simply go up by the slope of


the line

❑ This is the key insight in the DDA algorithm

When the slope of the line is between -1 and 1 begin at the first point in the line and, by
incrementing the x coordinate by 1, calculate the corresponding y coordinates as follows:

yk +1 = yk + m
When the slope is outside these limits, increment the y coordinate by 1 and calculate the
corresponding x coordinates as follows:

1
xk +1 = xk +
m
Again the values calculated by the equations used by the DDA algorithm must be rounded to
match pixel values

Page 9 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

DISADVANTAGES

❑ Accumulation of round-off errors can make the pixelated line drift away
from what was intended

❑ The rounding operations and floating point arithmetic involved are time
consuming

SUMMARY OF DDA ALGORITHM

input line endpoints, (x0,y0) and (xn, yn)

set pixel at position (x0,y0)

calculate slope m

Case |m|≤1: repeat the following steps until (xn, yn) is reached:

yi+1 = yi + y/ x

xi+1 = xi + 1

set pixel at position (xi+1,Round(yi+1))

Case |m|>1: repeat the following steps until (xn, yn) is reached:

xi+1 = xi + x/ y

yi+1 = yi + 1

set pixel at position (Round(xi+1), yi+1)

ii. THE BRESENHAM’S LINE DRAWING ALGORITHM

❑ The Bresenham algorithm is another incremental scan conversion algorithm

❑ The big advantage of this algorithm is that it uses only integer calculations

Move across the x axis in unit intervals and at each step choose between two different y
coordinates

Page 10 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

For example, from position (2, 3) we have to choose between (3, 3) and (3, 4)

We would like the point that is closer to the original line

At sample position xk+1 the vertical separations from the mathematical line are
labelled dupper and dlower

The y coordinate on the mathematical line at xk+1 is:

y = m( xk + 1) + b
So, dupper and dlower are given as follows:

Page 11 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

= m( xk + 1) + b − yk
and:

d upper = ( yk + 1) − y

= yk + 1 − m( xk + 1) − b
We can use these to make a simple decision about which pixel is closer to the mathematical
line

This simple decision is based on the difference between the two pixel positions:

d lower − d upper = 2m( xk + 1) − 2 yk + 2b − 1


Let’s substitute m with ∆y/∆x where ∆x and ∆y are the differences between the end-points:

y
x(d lower − d upper ) = x(2 ( xk + 1) − 2 yk + 2b − 1)
x

= 2y  xk − 2x  yk + 2y + x(2b − 1)

= 2y  xk − 2x  yk + c

So, a decision parameter pk for the kth step along a line is given by:

pk = x(d lower − d upper )


= 2y  xk − 2x  yk + c

Page 12 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

The sign of the decision parameter pk is the same as that of dlower – dupper

If pk is negative, then we choose the lower pixel, otherwise we choose the


upper pixel

Remember coordinate changes occur along the x axis in unit steps so we can do everything
with integer calculations

At step k+1 the decision parameter is given as:

pk +1 = 2y  xk +1 − 2x  yk +1 + c
Subtracting pk from this we get:

pk +1 − pk = 2y( xk +1 − xk ) − 2x( yk +1 − yk )
But, xk+1 is the same as xk+1 so:

pk +1 = pk + 2y − 2x( yk +1 − yk )

where yk+1 - yk is either 0 or 1 depending on the sign of pk

The first decision parameter p0 is evaluated at (x0, y0) is given as:

p0 = 2y − x
SUMMARY

input line endpoints, (x0,y0) and (xn, yn)

calculate x = xn - x0 and y = yn - y0

calculate parameter p0 = 2 y - x

set pixel at position (x0,y0)

Page 13 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

repeat the following steps until (xn, yn) is reached:

if pi < 0

set the next pixel at position (xi +1, yi )

calculate new pi+1 = pi + 2 y

if pi ≥ 0

set the next pixel at position (xi +1, yi + 1 )

calculate new pi+1 = pi + 2(y - x)

Page 14 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

TOPIC 3: CIRCLE GENERATING ALGORITHMS

OVERVIEW

The equation for a circle is:

x2 + y 2 = r 2
where r is the radius of the circle

So, we can write a simple circle drawing algorithm by solving the equation for y at unit x
intervals using:

y =  r 2 − x2
The first thing we can notice to make our circle drawing algorithm more efficient is that
circles centred at (0, 0) have eight-way symmetry

Page 15 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

Similarly to the case with lines, there is an incremental algorithm for drawing circles – the
mid-point circle algorithm

MID-POINT CIRCLE ALGORITHM

In the mid-point circle algorithm we use eight-way symmetry so only ever calculate the
points for the top right eighth of a circle, and then use symmetry to get the rest of the points

Assume that we have just plotted point (xk, yk) The next point is a choice between (xk+1, yk)
and (xk+1, yk-1)

We would like to choose the point that is nearest to the actual circle

So how do we make this choice?

Let’s change the equation of the circle slightly to give us:

f circ ( x, y ) = x 2 + y 2 − r 2
The equation evaluates as follows:

 0, if ( x, y ) is inside the circle boundary



f circ ( x, y ) = 0, if ( x, y ) is on the circle boundary
 0,
 if ( x, y ) is outside the circle boundary

Page 16 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

By evaluating this function at the midpoint between the candidate pixels we can make our
decision

Assuming we have just plotted the pixel at (xk,yk) so we need to choose between (xk+1,yk) and
(xk+1,yk-1)

Our decision variable can be defined as:

pk = f circ ( xk + 1, yk − 1 )
2
= ( xk + 1) 2 + ( yk − 1 ) 2 − r 2
2
If pk < 0 the midpoint is inside the circle and and the pixel at yk is closer to the circle

Otherwise the midpoint is outside and yk-1 is closer

To ensure things are as efficient as possible we can do all of our calculations incrementally

First consider:

(
pk +1 = f circ xk +1 + 1, yk +1 − 1
2
)
= [( xk + 1) + 1] + yk +1 − 1
2
( 2
) −r
2
2

or:

pk +1 = pk + 2( xk + 1) + ( yk2+1 − yk2 ) − ( yk +1 − yk ) + 1
where yk+1 is either yk or yk-1 depending on the sign of pk

The first decision variable is given as:

p0 = f circ (1, r − 1 )
2
= 1 + (r − 1 ) 2 − r 2
2 Page 17 of 24

= 5 −r
4
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

Then if pk < 0 then the next decision variable is given as:

pk +1 = pk + 2 xk +1 + 1

If pk > 0 then the decision variable is:

pk +1 = pk + 2 xk +1 + 1 − 2 yk + 1

The key insights in the mid-point circle algorithm are:

❑ Eight-way symmetry can hugely reduce the work in drawing a


circle

❑ Moving in unit steps along the x axis at each point along the
circle’s edge we need to choose between two possible y
coordinates

❑ So we can figure out how to draw lines and circles

❑ How do we go about drawing polygons?

❑ We use an incremental algorithm known as the scan-line algorithm

Page 18 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

TOPIC 4: POLYGON FILLING// ASSIGNMENT

TOPIC 5: VIEWING AND CLIPPING

OVERVIEW

Clipping:
When we have to display a large portion of the picture, then not only scaling & translation is
necessary, the visible part of picture is also identified. This process is not easy. Certain parts
of the image are inside, while others are partially inside. The lines or elements which are
partially visible will be omitted.

For deciding the visible and invisible portion, a particular process called clipping is used.
Clipping determines each element into the visible and invisible portion. Visible portion is
selected. An invisible portion is discarded.

Types of Lines:
Lines are of three types:

1. Visible: A line or lines entirely inside the window is considered visible


2. Invisible: A line entirely outside the window is considered invisible
3. Clipped: A line partially inside the window and partially outside is clipped. For
clipping point of intersection of a line with the window is determined.

Page 19 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

Clipping can be applied through hardware as well as software. In some computers, hardware
devices automatically do work of clipping. In a system where hardware clipping is not
available software clipping applied.

24.2M
Page 20 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

455
Prime Ministers of India | List of Prime Minister of India (1947-2020)

Following figure show before and after clipping

The window against which object is clipped called a clip window. It can be curved or
rectangle in shape.

Applications of clipping:
1. It will extract part we desire.
2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
5. Operations related to the pointing of an object.
6. For deleting, copying, moving part of an object.

Clipping can be applied to world co-ordinates. The contents inside the window will be
mapped to device co-ordinates. Another alternative is a complete world co-ordinates picture
is assigned to device co-ordinates, and then clipping of viewport boundaries is done.

Types of Clipping:
1. Point Clipping
2. Line Clipping
3. Area Clipping (Polygon)
Page 21 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

4. Curve Clipping
5. Text Clipping
6. Exterior Clipping

Point Clipping:
Point Clipping is used to determining, whether the point is inside the window or not. For this
following conditions are checked.

1. x ≤ xmax
2. x ≥ xmin
3. y ≤ ymax
4. y ≥ ymin

The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then the
point will fall outside the window and will not be considered to be visible.

Line Clipping:
It is performed by using the line clipping algorithm. The line clipping algorithms are:

1. Cohen Sutherland Line Clipping Algorithm


2. Midpoint Subdivision Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm

Page 22 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside
the screen. All lines come under any one of the following categories:

1. Visible
2. Not Visible
3. Clipping Case

1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.

2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such lines
will not display. If any one of the following inequalities is satisfied, then the line is
considered invisible.

3. Clipping Case: If the line is neither visible case nor invisible case. It is considered to be
clipped case. First of all, the category of a line is found based on nine regions given below.
All nine regions are assigned codes. Each code is of 4 bits. If both endpoints of the line have
end bits zero, then the line is considered to be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.

Algorithm

Step 1: Assign a region code for each endpoints.

Step 2: If both endpoints have a region code 0000 then accept this line.

Page 23 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552

Step 3: Else, perform the logical AND operation for both region codes.

Step 3.1: If the result is not 0000, then reject the line.

Step 3.2: Else you need clipping.

Step 3.2.1: Choose an endpoint of the line that is outside the window.

Step 3.2.2: Find the intersection point at the window boundary (base on region code).

Step 3.2.3: Replace endpoint with the intersection point and update the region code.

Step 3.2.4: Repeat step 2 until we find a clipped line either trivially accepted or trivially
rejected.

Step-4: Repeat step 1 for other line

Advantage of Cohen Sutherland Line Clipping:


1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.

Page 24 of 24

You might also like