Unit-I New Notes
Unit-I New Notes
Graphics Hardware
Hardcopy Technologies, Display Technologies, Raster-Scan Display Systems, The Video Controller, Random-
Scan Display Processor, Input Devices for Operator Interaction, Image
Scanners, Antialiasing.
Clipping
Cohen- Sutherland Algorithm, Cyrus-Beck Algorithm, Midpoint Subdivision algorithm.
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 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.
Advantages:
1. Higher Quality
2. More precise results or products
3. Greater Productivity
4. Lower analysis and design cost
5. Significantly enhances our ability to understand data and to perceive trends.
Fig: Conceptual Framework for interactive graphics
● Graphics library/package is intermediary between application and display hardware (Graphics System)
● Application program maps application objects to views (images) of those objects by calling on graphics
library. Application model may contain lots of non-graphical data (e.g., non-geometric object properties)
● User interaction results in modification of model and/or image
● This hardware and software framework is more than 4 decades old but is still useful.
Application Model
- represents the data, objects, or scene elements to be drawn
Application Program
- creates, stores into, and retrieves data from the application model
- handles user input
- produces view by sending information to the graphics system
- program calls special functions to perform graphics operations
- functions are part of some graphics software library (written by others)
Video Memory
- RAM dedicated to the GPU
- designed to be accessed faster than system memory
- may contain texture data, vectors, overlays, GPU programs
Frame buffer
- dedicated memory storing intensity values for each screen pixel
- values retrieved from memory (or buffer) and displayed on screen
- collection of pixel values represent a single frame on the screen
- special type of memory chips enabling fast redisplay of contents
- size of memory (in bits) for each pixel referred to as the depth
- the greater the depth, the more information associated with each pixel information can include color,
transparency, depth,
- additional bits increase number of possible values (colors)
Programming environment
Graphics Software
- user code combined with function calls to perform interactive, 3D graphics tasks
- functions part of software library called an API ( Application Programming Interface)
- example includes OpenGL, Microsoft's Direct3D (part of DirectX)
- device-independent packages, promotes application-program portability
Graphics API
- Interface between graphics application program and graphics hardware
- Functions perform some basic three-dimensional computer graphics operations
- Contains different types of functions representing stages of drawing 3D objects
Primitive functions
- Specify what to display
- Define low-level display objects (also called primitives)
- Includes points, lines, line segments, polygons, pixels, text, curves, surfaces
Attribute functions
- Specify how to display primitives
- Govern appearance on the screen
- Can include color, patterns, fonts, texture
Viewing functions
- Specify a synthetic camera viewing the scene
- Can include position, orientation, type of projection, clipping, lens
Transformation functions
- Specify how objects are moved (or transformed)
- Can include scaling, rotation, translation
- Employs heavy use of 4x4 matrix transformations
Input functions
- Specify how to handle user input
- Used for interactive applications
- Specify how to deal with devices such as keyboard, mouse, game controller
Control functions
- Specify general operational functionality
- Examples include initializing the graphics system, communicating with window system, error processing
Raster-Scan
The electron beam is swept across the screen one row at a time from top to bottom. As it moves across each row,
the beam intensity is turned on and off to create a pattern of illuminated spots. This scanning process is called
refreshing. Each complete scanning of a screen is normally called a frame.
The refreshing rate, called the frame rate, is normally 60 to 80 frames per second, or described as 60 Hz to 80
Hz.
Picture definition is stored in a memory area called the frame buffer. This frame buffer stores the intensity values
for all the screen points. Each screen point is called a pixel (picture element).
On black and white systems, the frame buffer storing the values of the pixels is called a bitmap. Each entry in the
bitmap is a 1-bit data which determine the on (1) and off (0) of the intensity of the pixel.
On color systems, the frame buffer storing the values of the pixels is called a pixmap. A pixmap stores and
displays a graphical image as a rectangular array of pixel color values. (The term "pixmap" is short for
"pixel map".) A pixmap that uses only a single bit to denote the color of each pixel (resulting in a
monochrome image) is often referred to as a bitmap. Bitmap is also sometimes used to refer to any pixmap.
(Though nowadays many graphics libraries name it as bitmap too). Each entry in the pixmap occupies a number
of bits to represent the color of the pixel. For a true color display, the number of bits for each entry is 24 (8 bits
per red/green/blue channel, each channel 28=256 levels of intensity value, ie. 256 voltage settings for each of the
red/green/blue electron guns).
Resolution: Use to describe the number of pixels that are used on display image.
Refresh Rate:
To maintain a stable image, the electron beam must sweep the entire surface of the screen and then return to
redraw it several times per second. This process says Refreshing. Refresh Rate is the number of times per second
that the screen refreshes. It measures in Hertz (Hz).A high refresh rate is important in providing a clear picture
and avoiding eye fatigue. An image appears on screen when electron beams strike the surface of the screen in a
zig-zag pattern. A refresh rate is the number of times a screen is redrawn in one second and is measured in Hertz
(Hz). Therefore, a monitor with a refresh rate of 85 Hz is redrawn 85 times per second. A monitor should be
“flicker-free meaning that the image is redrawn quickly enough so that the user cannot detect flicker, a source of
eye strain. Today, a refresh rate of 75 Hz or above is considered to be flicker-free
If the same monitor is set to a resolution of 1600 x 1200, then the equation will be as follows:
fV = 76
Interlacing:
Interlacing is a technique of improving the picture quality of a video signal without consuming extra bandwidth.
In this technique, each frame is displayed in the passes, In the first pass, the beam sweeps across every other scan
line from top to bottom. In the second pass, the beam sweeps out the remaining scan lines.
Aspect Ratio:
The Aspect Ratio is the ratio of the number of X pixels to the number of Y pixels. The standard aspect ratio for
PCs is 4:3. Some common resolutions, the respective number of pixels and standard aspect ratio are given below:
Aspect Ratio =
Resolution Number of Pixels Aspect Ratio
320x240 76800 4:3
640x480 307200 4:3
800x600 480000 4:3
1024x768 786432 4:3
1280x720 921600 16:9
1920x1080 2073600 16:9
Display Controller
For a raster display device reads the frame buffer and generates the control signals for the screen, ie. the signals
for horizontal scanning and vertical scanning. Most display controllers include a color map (or video look-up
table). The major function of a color map is to provide a mapping between the input pixel value to the output
color.
Anti-Aliasing
On dealing with integer pixel positions, jagged or stair step appearances happen very usually. This distortion of
information due to under sampling is called aliasing. A number of antialiasing methods have been developed to
compensate this problem.
4. In area sampling, pixel intensities are calculated proportional to areas of overlap of each pixel with objects to
be displayed. Here pixel color is computed based on the overlap of scene’s objects with a pixel area.
For example: Suppose, a line passes through two pixels. The pixel covering bigger portion(90%) of line
displays 90% intensity while less area(10%) covering pixel displays 10-15% intensity. If pixel area overlaps
with different color areas, then the final pixel color is taken as an average of colors of the overlap area. This
method is also known as pre-filtering as this procedure is done BEFORE generating the rasterized image. It’s
done using some graphics primitive algorithms.
5. Pixel phasing:
It’s a technique to remove aliasing. Here pixel positions are shifted to nearly approximate positions near
object geometry. Some systems allow the size of individual pixels to be adjusted for distributing intensities
which is helpful in pixel phasing.
he primary use of clipping in computer graphics is to remove objects, lines, or
line segments that are outside the viewing pane. The viewing transformation is
insensitive to the position of points relative to the viewing volume − especially
those points behind the viewer − and it is necessary to remove these points
before generating the view.
CLIPPING
Point Clipping
Clipping a point from a given window is very easy. Consider the following figure, where the rectangle indicates
the window. Point clipping tells us whether the given point X,Y is within the given window or not; and decides
whether we will use the minimum and maximum coordinates of the window.
The X-coordinate of the given point is inside the window, if X lies in between Wx1
≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside the window, if Y lies
in between Wy1 ≤ Y ≤ Wy2.
Point Clipping
Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the portion of line which is
outside of window and keep only the portion that is inside the window.
This algorithm uses the clipping window as shown in the following figure. The minimum coordinate for the
clipping region is (XWmin,YWmin) and the maximum coordinate for the clipping region is (XWmax,YWmax).
TOP-LEFT Corner
Line can be partially inside the window We will find intersectionpoint and draw only that portion of line thatis
inside region.
The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.
HOW TO ASSIGN 0 or 1
For any endpoint ( x , y ) of a line, the code can be determined that identifies which region the endpoint lies.
The code's bits are set according to the following conditions:
We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right, and Left
of the region as shown in theabove figure. Here, the TOP and LEFT bit is set to 1 because it is the TOP-
LEFT corner.
Algorithm
Category EF i 1 (visible): EF since the region code for both endpoints is 0000.
let there be 3 lines AB with A (-4, 2) and B (-1, 7), E F with E (-2, 3) and F (1, 2) and IJ with I(-4, 7) and
J(-2, 10)
Step 3 Now find lines that are outside region and needs clipping
Category2 IJ (not visible): IJ since (1001) AND (1000) =1000 (which is not 0000).
Now Apply step 3.2(d) as per (1000) on B(-1,7) we get Bnew with L (-3, 1) and R (2, 6) as min and max
coordinate of region.
y3= ymax =6 and x3=X1+(Ywmax - Y1)/m = -1+( 6-7)/ (5/3) = -1+(3/5)(-1)= (-5-3)/5 =-8/5
Let Ni be the outward normal edge Ei. Now pick any arbitrary point PEi on edge Ei then the dot product Ni.[Pt –
PEi] determines whether the point Pt is “inside the clip edge” or “outside” the clip edge or “on” the clip edge.
Ni.[Pt – PEi] = 0
t=Ni.[Po−PEi] / (−Ni.D)
then
else
If AND ≠ 0000
else
AND=6000
Xm=(x1+x2)/2
Ym=(y1+y2)/2
Step6: If the line is totally visible or totally rejected not found then repeat step 1 to 5.
Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-ordinates of A (-4, 2) and B (-1, 7).
Does this line visible. Find the visible portion of the line using midpoint subdivision?
Solution:
Now considered left-hand side portion. A and B""are now endpoints Find mid of A and B""
A (-4, 2) B ""(-1, 6)
a””= (-3,2)
b””=(-1,6)
LINE GENERATING 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,Y0X0,Y0 and the
second point of line as X1,Y1X1,Y1.
1. Digital Differential Analyzer (DDA) Line Drawing Algorithm
2. Bresenham Line Drawing Algorithm
3. Mid Point Line Drawing Algorithm
DDA Algorithm
Digital Differential Analyzer DDADDA 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
M = dY / dX
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.
if (absolute(dx) > absolute(dy))
Steps = abs(dx);
else
Steps = abs(dy);
5 6 5.5 7 (6, 7)
6 8 (6, 8)
6.5 9 (7, 9)
7 10 (7, 10)
8 12 (8, 12)
At sample position Xk+1,Xk+1, the vertical separations from the mathematical line are labelled
as dupperdupper and dlowerdlower.
=m(Xk+1)+b−Yk=m(Xk+1)+b−Yk
and
dupper=(yk+1)−ydupper=(yk+1)−y
=Yk+1−m(Xk+1)−b=Yk+1−m(Xk+1)−b
You 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.
dlower−dupper=2m(xk+1)−2yk+2b−1dlower−dupper=2m(xk+1)−2yk+2b−1
Let us substitute m with dy/dx where dx and dy are the differences between the end-points.
dx(dlower−dupper)=dx(2dydx(xk+1)−2yk+2b−1)dx(dlower−dupper)=dx(2dydx(xk+1)−
2yk+2b−1)
=2dy.xk−2dx.yk+2dy+2dx(2b−1)=2dy.xk−2dx.yk+2dy+2dx(2b−1)
=2dy.xk−2dx.yk+C=2dy.xk−2dx.yk+C
=2dy.xk−2dx.yk+C=2dy.xk−2dx.yk+C
Now, keeping in mind all the above points and calculations, here is the Bresenham
algorithm for slope m < 1 −
Step 1 − Input the two end-points of line, storing the left end-point in (x0,y0)
Step 2 − Plot the point (x0,y0).
Step 3 − Calculate the constants dx, dy, 2dy, and 2dy–2dx and get the first value
for the decision parameter as −
p0=2dy−dx
Step 4 − At each XkXk 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+2dy
Otherwise,
(xk,yk+1)
pk+1=pk+2dy−2dx
Step 5 − Repeat step 4 dx–1 times.
For m > 1, find out whether you need to increment x while incrementing y each time.
After solving, the equation for decision parameter Pk will be very similar, just the x and y in the equation gets
interchanged.
Solution-
Given-
● Starting coordinates = (X0, Y0) = (9, 18)
● Ending coordinates = (Xn, Yn) = (14, 22)
Step-01:
Calculate ΔX and ΔY from the given input.
● ΔX = Xn – X0 = 14 – 9 = 5
● ΔY =Yn – Y0 = 22 – 18 = 4
Step-02:
Calculate the decision parameter.
Pk = 2ΔY – ΔX
=2x4–5
=3
So, decision parameter Pk = 3
Step-03:
As Pk >= 0, so case-02 is satisfied.
Thus,
● Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
● Xk+1 = Xk + 1 = 9 + 1 = 10
● Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number of iterations equals to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
Pk Pk+1 Xk+1 Yk+1
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Mid-Point Algorithm
Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van
Aken. Assume that you have already put the point P at x,y coordinate and the
slope of the line is 0 ≤ k ≤ 1 as shown in the following illustration.
Now you need to decide whether to put the next point at E or N. This can be chosen by identifying the intersection
point Q closest to the point N or E. If the intersection point Q is closest to the point N then N is considered as the
next point; otherwise E.
To determine that, first calculate the mid-point Mx+1,y+½. If the intersection point Q of the line with the vertical
line connecting E and N is below M, then take E as the next point; otherwise take N as the next point.
In order to check this, we need to consider the implicit equation −
Fx,yx,y = mx + b - y
For positive m at any given X,
● If y is on the line, then Fx,yx,y = 0
● If y is above the line, then Fx,yx,y < 0
● If y is below the line, then Fx,yx,y > 0
ALGORITHM
Step-01:
Calculate ΔX and ΔY from the given input.
These parameters are calculated as-
● ΔX = Xn – X0
● ΔY =Yn – Y0
Step-02:
Calculate the value of initial decision parameter and ΔD.
These parameters are calculated as-
● Dinitial = 2ΔY – ΔX
● ΔD = 2(ΔY – ΔX)
Step-03:
The decision whether to increment X or Y coordinate depends upon the flowing values of D initial.
Follow the below two cases-
Step-04:
Keep repeating Step-03 until the end point is reached.
For each Dnew value, follow the above cases to find the next coordinates.
EXAMPLE BASED ON MID POINT LINE DRAWING ALGORITHM-
Calculate the points between the starting coordinates (20, 10) and ending coordinates (30, 18).
Solution- Given-
● Starting coordinates = (X0, Y0) = (20, 10)
● Ending coordinates = (Xn, Yn) = (30, 18)
Step-01:
Calculate ΔX and ΔY from the given input.
● ΔX = Xn – X0 = 30 – 20 = 10
● ΔY =Yn – Y0 = 18 – 10 = 8
Step-02:
Calculate Dinitial and ΔD as-
● Dinitial = 2ΔY – ΔX = 2 x 8 – 10 = 6
● ΔD = 2(ΔY – ΔX) = 2 x (8 – 10) = -4
Step-03:
As Dinitial >= 0, so case-02 is satisfied.
Thus,
● Xk+1 = Xk + 1 = 20 + 1 = 21
● Yk+1 = Yk + 1 = 10 + 1 = 11
● Dnew = Dinitial + ΔD = 6 + (-4) = 2
Step 4
Similarly, Step-03 is executed until the end point is reached.
20 10
6 2 21 11
2 -2 22 12
-2 14 23 12
14 10 24 13
10 6 25 14
6 2 26 15
2 -2 27 16
-2 14 28 16
14 10 29 17
10 30 18
Drawing a circle on the screen is a little complex than drawing a line. There are
two popular algorithms for generating a circle − Bresenham’s Algorithm and
Midpoint Circle Algorithm. These algorithms are based on the idea of
determining the subsequent points required to draw the circle
e.
Bresenham’s Algorithm
We cannot display a continuous arc on the raster display. Instead, we have to choose the nearest pixel position to
complete the arc.
From the following illustration, you can see that we have put the pixel at X, Y
location and now need to decide where to put the next pixel − at N( X+1, Y) or at S(
X+1, Y-1)
This can be decided by the decision parameter d.
Algorithm
Step 1 − Get the coordinates of the center of the circle and radius, and store
them in x, y, and R
respectively. Set X=0 and Y=R.
Step 8 − Call Draw Circle X, Y, Xc, Yc. Plot eight points by using concepts of eight-way symmetry.
The center is at (Xc, Yc). Current active pixel is (X, Y).
putpixel (X+Xc, Y+Yc)
putpixel (X+Xc, -Y+Yc)
putpixel (-X+Xc, Y+Yc)
putpixel (-X+Xc, -Y+Yc)
putpixel (Y+Xc, X+Yc)
putpixel (Y+Xc, -X+Yc)
putpixel (-Y+Xc, X+Yc)
putpixel (-Y+Xc,- X+Yc)
Step-04:
Now find next x , y values
As Pinitial < 0, so case-01 is satisfied.
Thus,
● Xk+1 = Xk + 1 = 0 + 1 = 1
● Yk+1 = Yk = 8
● Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3
( if Pk>0 Pk+1 = Pk + 4 x (Xk+1 -Yk+1 )+ 10)
Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0). Call draw circle (0,0,1,8) where
following putpixels will be executed:
putpixel (1,8) putpixel (1,-8) putpixel (-1,8) putpixel (-1, -8)
putpixel (8,1) putpixel (8, -1) putpixel (-8, 1) putpixel (-8,-1)
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows- ( for 1 octant )
(0, 8)
-13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Here, all the points have been generated with respect to quadrant-1-
Step 5 − Move each calculate pixel position X, Y onto the circular path centered on
(X_{C,}
Y_{C}) and plot the coordinate values.
X = X + XC, Y = Y + YC
Step-02:
Calculate the value of initial decision parameter P 0 as-
P0 = 1.25 – R or 1-R ( if rounded off)
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter P k.
Follow the below two cases-
Step-04:
If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point-
● Xplot = Xc + X0
● Yplot = Yc + Y0
Here, (Xc, Yc) denotes the current value of X and Y coordinates.
Step-05:
Keep repeating Step-03 and Step-04 until Xplot >= Yplot.
Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of circle.
This is depicted by the following figure-
EXAMPLE -MID POINT CIRCLE DRAWING ALGORITHM-
Problem-01:
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to form a circle.
Solution-
Given-
● Centre Coordinates of Circle (X0, Y0) = (0, 0)
● Radius of Circle = 10
Step-01:
Assign the starting point coordinates (X0, Y0) as-
● X0 = 0
● Y0 = R = 10
Step-02:
Calculate the value of initial decision parameter P0 as-
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Step-03:
As Pinitial < 0, so case-01 is satisfied.
Thus,
● Xk+1 = Xk + 1 = 0 + 1 = 1
● Yk+1 = Yk = 10
● Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Step-04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows- ( we may
(0, 10)
-9 -6 (1, 10)
-6 -1 (2, 10)
-1 6 (3, 10)
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm calculates all the points of octant-1 and terminates.
Now, the points for rest of the part are generated by following the signs of other quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant-1-
● D. Hearn & Baker: Computer Graphics with OpenGL, Pearson Education, Third
Edition,2009.
● https://www.geeksforgeeks.org/
● https://www.javatpoint.com
● https://www.gatevidyalay.com
● https://www.tutorialspoint.com/computer_graphics/computer_graphics_basics.htm
● https://studyresearch.in/2019/12/28/cohensutherlandexample/#:~:text=Clip%20a%20line%20A
%20