Unit 1 Computer Graphics Notes
Unit 1 Computer Graphics Notes
Imagine a car manufacturing company that wants to showcase its vehicle sales
over the past decade. Storing and presenting this huge amount of data can be
both time-consuming and memory intensive. Furthermore, it can be difficult for
the average person to understand. In such cases, using graphics can be a more
effective solution. By using charts and graphs to visually signify the data, it
becomes much easier to understand and analyze the data.
2
The term computer graphics (CG) describes the use of computers to create
and manipulate images.
Graphics can be two- or three-dimensional.
Computer Graphics is the creation and manipulation of images or pictures
with the help of computers.
The major product of computer graphics is the picture. With the help of CG,
pictures can be represented in 2D, and 3D space.
Many applications show various parts of the displayed picture changing in
size and orientation. Such transformations, i.e., pictures can be made to
grow, shrink, rotate, etc., can be achieved through CG.
The display on them is often too big to be shown in its entirety. Thus, with
the help of CG, a technique called clipping can be used to select just those
parts of the picture that lie on the screen and to discard the rest.
CG is in daily use in the fields of science, engineering, medicine,
entertainment, advertising, graphic arts, fine arts, business, education, etc.
The electronic industry is more dependent on the technologies provided by
CG,
such as:
o Engineers can draw their circuit in a much shorter time.
o Architects can have alternative solutions to design problems.
o Molecular biologists can display pictures of molecules and study their
structure.
o Town planners and transportation engineers use computer-
generated maps that display data useful to them in their planning
work.
Figure 1
1. Frame Buffer
o The images to be displayed are stored in a frame buffer in the form
of a matrix of intensity values.
o The frame buffer contains the image stored in binary form as a
matrix of 0’s and 1’s, representing the pixel. 0 indicates darkness, and
1 indicates the image.
o The Frame Buffer holds the set of intensity values for all the screen
points.
o The intensity values stored in a Frame Buffer are retrieved and
painted on a screen one row at a time. This row is called a scan line.
2. Display Controller
o The Display Controller passes the contents of the frame buffer to the
T.V. Monitor.
o The Display Controller reads successive bytes of data from the frame
buffer and then converts 0’s and 1’s into the corresponding video
signal.
o These signals are fed to the T.V. Monitor.
3. T.V. Monitor
o The T.V. Monitor then produces a black and white pattern on the
screen.
5
o The frame buffer contents are modified to represent the new pattern
of pixels or if some changes are to be made to the displayed picture.
GRAPHICS AREAS
2. Rendering is a term inherited from art and deals with the creation of
shaded images from 3D computer models.
1. User Interaction deals with the interface between input devices such as
mice and tablets, the application, feedback to the user in imagery, and
other sensory feedback.
2. Virtual Reality attempts to immerse the user into a 3D virtual world. This
typically requires at least stereo graphics and a response to head motion.
For true virtual reality, sound and force feedback should be provided as
well.
6
Almost any field can make some use of computer graphics, but the major
consumers of computer graphics technology include the following
industries:
3. Visual Effects use almost all types of computer graphics technology. Almost
every modern film uses digital compositing to superimpose backgrounds
with separately filmed foregrounds. Many films also use 3D modeling and
animation to create synthetic environments, objects, and even characters
that most viewers will never suspect are not real.
7
4. Animated Films use many of the same techniques that are used for visual
effects, but without necessarily aiming for images that look real.
DISPLAY TECHNOLOGIES
The most common graphics output device is the video monitor, which is
based on the standard cathode ray tube (CRT) design. Figure 4 illustrates
the basic operation of a CRT.
In raster scan displays, the electron beam moves across the screen, one row at a
time from top to bottom. As it moves, it turns on and off to create a pattern of
illuminated pixels. This process is repeated quickly enough to create the illusion of
a stable image.
Figure 5: Raster Scan Display
The image on the screen is refreshed many times per second, which is why these
displays are also called refresh CRTs.
Horizontal and Vertical Retrace
During the raster scanning process, once the electron beam reaches the end of a
row, it must return to the start of the next row. This movement is known as the
horizontal retrace. Similarly, after completing the bottom row, the beam returns
to the top row, which is called the vertical retrace.
Figure 6: Horizontal and Vertical Retrace
10
What is a Plotter?
It is basically a category of printers. They receive the commands from the
computers and then create drawings on paper using pens. We use plotters
for producing various hard copies of designs, large graphs, etc., on paper-
such as engineering drawings, business charts, construction maps,
architectural plans, etc.
A plotter is either a standalone device that has its own internal processor or
a peripheral computer that we add to a computer system. It performs the
production of data in the form of a hardcopy at a comparatively slower rate
than a printer. We mainly use these in specialized fields, such as
engineering, architecture, and drawing.
What is a printer?
It is basically a hardware device (output) that lets a user acquire graphics
and text output from the computer for generating a hard copy. Basically, a
printer processes the available soft copy for producing the hard copy for it.
These printers are of various types on the basis of the quality of hard copy
produced, size, cost, complex construction, and speed. As compared to a
plotter, a printer is capable of producing hardcopy at a much faster speed.
It basically prints one line at a time and is used for producing text and
graphics on physical mediums like paper.
17
1. Graphics Monitors
Graphics monitors are designed to display high-quality images and are essential
for any graphics system. The two main types of monitors used in graphics are:
These are traditional monitors that use electron beams to illuminate phosphor
dots on the screen.
Advantages: High contrast ratios, wide viewing angles, and fast response times.
Disadvantages: Bulky, heavy, and consume more power.
Modern monitors that use liquid crystals and a backlight to produce images.
Advantages: Slim profile, lightweight, and energy efficient.
Disadvantages: Limited viewing angles and contrast ratios compared to CRTs.
Workstations
Input Devices
Input devices are used to interact with the graphics system, allowing users to
create, modify, and manipulate images. Common input devices include:
Keyboards
Used for entering text and executing commands.
Standard layout with additional function keys for specific tasks.
Mouse
A pointing device that detects two-dimensional motion relative to a surface.
Essential for navigating graphical user interfaces.
Trackball and Spaceball
Trackball: A stationary device with a ball that can be rotated to move the cursor.
Data Glove: A wearable device that captures hand and finger movements.
Used in virtual reality and animation.
Touch Screens: Displays that detect touch input, allowing direct interaction with
the screen.
Widely used in tablets, smartphones, and interactive kiosks.
Light Pen: A pointing device that can detect the position on the screen when
touched.
19
Voice Systems: Allow users to interact with the computer using voice commands.
Used in accessibility applications and hands-free environments.
Image Scanners: Devices that convert physical images into digital form.
Used for digitizing photographs, documents, and artwork.
Output primitives are the basic elements used to create more complex graphical
images. The primary output primitives in computer graphics are points, lines, and
polygons.
Points
Points are the simplest graphical elements, representing a single location in
a coordinate space.
Defined by a pair (x, y) in 2D or a triplet (x, y, z) in 3D.
Used as the fundamental building blocks for more complex shapes.
Lines
Lines are defined by two endpoints and are used to connect points.
In 2D, a line segment is defined by its endpoints (x1, y1) and (x2, y2).
In 3D, it’s defined by (x1, y1, z1) and (x2, y2, z2).
20
1. Input:
o Two endpoints of the line: (x1,y1) and (x2,y2)
2. Calculate Differences:
Δx=x2−x1)
Δy=y2−y1
xincrement=Δx/Stepsx
yincrement=Δy/Stepsy
21
Example:
1. Calculate Differences:
Δx=10−2=8
Δy=8−3=5
2. Determine Steps:
Steps=max(∣8∣,∣5∣)=8
3. Calculate Increments:
X increment= 8/8=1
Y increment= 5/8=0.625
Advantages:
Simple to implement.
Works well for lines with small slopes.
Disadvantages:
Key Concept
Given two endpoints of a line (x0,y0) and (x1,y1), follow these steps:
23
Initialize:
The algorithm plots the points in the order: (3,2) (4,2), (5,3), (6,3), (7,3), (8,4), and
(9,4)
1. Initialization:
o Start with the two endpoints of the line, (x0, y0) and (x1,y1).
o Calculate the differences: Δx=x1−x0
o Δy=y1−y0
o Determine the initial decision parameter: p0=2Δy−Δx
o The initial point (x0, y0) is plotted.
2. Iteration:
o For each x from x0 to x1
If pi<0:
Plot (xi+1, yi)
Update the decision parameter: pi+1=pi+2Δy
Else:
Plot (xi+1, yi+1) where yi+1=yi+1
Update the decision parameter: pi+1=pi+2Δy−2Δx
3. Termination:
o The algorithm continues until all points on the line are plotted.
25
Example:
Let's say we want to draw a line from (2,3) to (7,5) using the Midpoint Line
Algorithm.
1. Initialization:
o x0=2, y0=3
o x1=7, y1=5
o Δx=7−2=5
o Δy=5−3=2
o Initial decision parameter p0=2×Δy−Δx=2×2−5=−1
2. Iteration:
o For x=2:
p0=−1 (less than 0), plot (3,3).
Update p1=p0+2×Δy=−1+4=3
o For x=3:
p1=3 (greater than 0), plot (4,4).
Update p2=p1+2×Δy−2×Δx=3+4−10=−3
o For x=4:
p2=−3 (less than 0), plot (5,4).
Update p3=p2+2×Δy=−3+4=1
o For x=5:
p3=1 (greater than 0), plot (6,5).
Update p4=p3+2×Δy−2×Δx=1+4−10=−5
o For x=6x = 6x=6:
p4=−5 (less than 0), plot (7,5).
3. Result:
o The points plotted are (2,3), (3,3), (4,4), (5,4), (6,5), (7,5).
Equation of circle.
X2 + y2 = r2
OR
27
(x−h)2 + (y−k)2=r2
h and k are the coordinates of the center of the circle.
r is the radius of the circle.
Given the center of a circle (xc, yc) and a radius r, the goal is to plot the circle
centered at (xc, yc) with radius r. The algorithm starts at the top of the circle and
moves counterclockwise, using the symmetry of the circle to reflect the points
into all eight octants.
Steps of the Algorithm.
1. Initialization:
o Start at the topmost point on the circle: (x0, y0) =(0, r)
o Compute the initial decision parameter: p0=1−r
o The circle is symmetric, so for each point (x, y) computed in the first
octant, plot the corresponding points in the other seven octants.
2. Iteration:
o For each pixel (xk, yk) starting from (0, r),
If pk<0, the next pixel is (xk+1, yk) and the decision parameter
is updated as: pk+1=pk+2xk+3
If pk≥0, the next pixel is (xk+1, yk−1) and the decision
parameter is updated as: pk+1=pk+2xk−2yk+5
o Continue the process until xk≥yk .
Example
Let's draw a circle centered at (0,0) with radius r=5
1. Calculate Initial Values:
o Initial point: (x0, y0) = (0,5)
o Initial decision parameter: p0=1−5=-4
2. Plotting Points:
o Start at (0,5).
o p0=−4<0, so plot (1,5) and compute the next decision parameter:
p1=p0+2(0) +3=−4+3=−1
o p1=−1<0, so plot (2,5) and compute: p2=p1+2(1) +3=−1+5=4
o p2=4>0, so plot (3,4) and compute: p3=p2+2(2) −2(5) +5=4+4−10+5=3
o Continue this process until xk≥yk
The algorithm will compute points like (0,5), (1,5), (2,5), (3,4) etc., and reflect
these points across the other seven octants to complete the circle.
Plotting the Full Circle
28
Given the symmetry, for each computed point (x, y) in the first octant, the
corresponding points in all octants are:
(x, y)
(y, x)
(−x, y)
(−y, x)
(x, −y)
(y, −x)
(−x, −y)
(−y, −x)
This approach ensures that the circle is plotted correctly by only calculating the
necessary points in the first octant and then reflecting them to the rest of the
circle.
Introduction
Ellipse Equation
x2 y2
-- + -- = 1
a2 b2
Where:
Key Concepts
1. Symmetry: The ellipse is symmetric about both its axes, which means only
one-quarter of the ellipse needs to be calculated. The rest can be mirrored
from the calculated points.
2. Decision Parameter: The decision parameter helps determine the next pixel
position based on the current location, choosing between moving
horizontally, vertically, or diagonally.
Algorithm Steps
1. Region 1: Where the slope of the curve is greater than or equal to -1.
2. Region 2: Where the slope of the curve is less than -1.
Initialization:
Loop:
o Move along the ellipse by incrementing the xxx-coordinate and
determining whether to move the y-coordinate.
o If p1<0, move horizontally to the right.
o If p1≥0, move diagonally (right and down).
Initialization:
o Start from the last point in region 1.
2 2 2
o Initialize the decision parameter p2 as: p2= b2(x+1/2) + a (y−1) -
a2b2
Loop:
o Move along the ellipse by decrementing the y-coordinate and
determining whether to move the xxx-coordinate.
o If p2>0, move vertically down.
o If p2≤0, move diagonally (down and right).
30
Example
1. Region 1 Calculation:
=9−75+6.25=−59.75
o Since p1<0, move horizontally to (1,3).
o Recalculate p1 and determine the next move until the slope changes to
less than -1.
2. Region 2 Calculation:
o Start from the last point in region 1.
o Initialize p2 and follow the decision-making process like region 1,
but now focusing on decrementing y.
3. Plotting Points:
o Plot the calculated points on the screen.
o Mirror these points in all four quadrants to complete the ellipse.
When working with filled area primitives like polygons, circles, or other shapes in
computer graphics, specific algorithms are employed to determine which pixels
inside a defined boundary should be colored. The most common algorithms for
filling these areas are:
Introduction: The Scan Line Polygon Fill Algorithm is used to fill the area of a
polygon by processing each horizontal line (or scan line) of the polygon. It is an
efficient method for filling polygons in computer graphics, especially when dealing
with complex shapes.
This algorithm works by intersecting scanline with polygon edges and fills the
polygon between pairs of intersections. The following steps depict how this
algorithm works.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax.
Name each intersection point of the polygon. As per the figure shown above, they
are named as p0, p1, p2, p3.
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the
alternate pairs.
Key Points:
Steps to Explain:
1. Choosing a Seed Point:
o Select a pixel inside the boundary where you want to start filling. This
is called the seed point.
2. Check Boundary Condition:
o If the current pixel is not the boundary color and has not been filled
yet, fill it with the desired color.
3. Recursive Filling:
o Move to the neighboring pixels:
In 4-connected filling, check the pixels directly above, below,
left, and right.
In 8-connected filling, also check the diagonally adjacent pixels.
o Recursively apply the fill operation to each neighbor.
4. Termination:
o The algorithm stops when it reaches the boundary or when there are
no more neighboring pixels to fill.
Four connected
34
Algorithm
Key Points:
Simple to implement but can be inefficient for large areas.
Careful with recursion to avoid stack overflow.
Used in applications like paint programs for filling bounded regions.
Introduction: The Flood Fill Algorithm is used to replace a specific color with a
new color across a region. It is similar to the Boundary Fill Algorithm but does not
rely on a boundary. Instead, it fills all pixels connected to the seed point that have
the same initial color.
35
Steps to Explain:
4. Termination:
o The algorithm continues until all connected pixels of the target color
are filled.
Key Points:
Conclusion: These three algorithms are essential tools in computer graphics for
filling areas. Each has its specific use case:
THANK YOU