Computer Graphics Lecture Notes
Computer Graphics Lecture Notes
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.
Computer Graphics has numerous applications, some of which are listed below:
❑ 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.
c. Plasma panels
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.
CRT DIAGRAM
◼ 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.
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…
❑ Persistence: The time from the removal of the excitation to the moment when
phospherescence has decayed to 10% of the initial light output
There are two ways by which we can display an object on the screen.
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.
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
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
The aspect ratio equals the ratio of vertical pixels/horizontal pixels for an equal length line.
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.
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
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.
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?
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:
NOTE: Simply choosing some pixels to draw often results in the familiar 'jaggies'.
TYPES 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.
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
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
calculate slope m
Case |m|≤1: repeat the following steps until (xn, yn) is reached:
yi+1 = yi + y/ x
xi+1 = xi + 1
Case |m|>1: repeat the following steps until (xn, yn) is reached:
xi+1 = xi + x/ y
yi+1 = yi + 1
❑ 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)
At sample position xk+1 the vertical separations from the mathematical line are
labelled dupper and dlower
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:
y
x(d lower − d upper ) = x(2 ( xk + 1) − 2 yk + 2b − 1)
x
= 2y xk − 2x yk + c
So, a decision parameter pk for the kth step along a line is given by:
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
Remember coordinate changes occur along the x axis in unit steps so we can do everything
with integer calculations
pk +1 = 2y xk +1 − 2x yk +1 + c
Subtracting pk from this we get:
pk +1 − pk = 2y( xk +1 − xk ) − 2x( yk +1 − yk )
But, xk+1 is the same as xk+1 so:
pk +1 = pk + 2y − 2x( yk +1 − yk )
p0 = 2y − x
SUMMARY
calculate x = xn - x0 and y = yn - y0
calculate parameter p0 = 2 y - x
Page 13 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552
if pi < 0
if pi ≥ 0
Page 14 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552
OVERVIEW
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
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
f circ ( x, y ) = x 2 + y 2 − r 2
The equation evaluates as follows:
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)
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
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
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
pk +1 = pk + 2 xk +1 + 1
pk +1 = pk + 2 xk +1 + 1 − 2 yk + 1
❑ 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
Page 18 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552
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:
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)
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:
Page 22 of 24
COMPUTER GRAPHICS LECTURE NOTES Sharon moses 0728918552
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 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.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.
Page 24 of 24