Computer Graphics Unit-1
Computer Graphics Unit-1
Unit-1
2. Use in Biology: Molecular biologist can display a picture of molecules and gain insight
5. Presentation Graphics: Example of presentation Graphics are bar charts, line graphs,
pie charts and other displays showing relationships between multiple parameters.
Presentation Graphics is commonly used to summarize:
o Financial Reports
o Statistical Reports
o Mathematical Reports
o Scientific Reports
o Economic Data for research reports
o Managerial Reports
6. Computer Art: Computer Graphics are also used in the field of commercial arts. It is
used to generate television and advertising commercial.
7. Entertainment: Computer Graphics are now commonly used in making motion pictures,
music videos and television shows.
10. Printing Technology: Computer Graphics is used for printing technology and textile
design.
Once the electron heats the phosphorus, they light up, and they are projected on a screen.
The color you view on the screen is produced by a blend of red, blue and green light.
Components of CRT:
Main Components of CRT are:
1. Electron Gun: Electron gun consisting of a series of elements, primarily a heating
filament (heater) and a cathode. The electron gun creates a source of electrons which are
focused into a narrow beam directed at the face of the CRT.
2. Control Electrode: It is used to turn the electron beam on and off.
3. Focusing system: It is used to create a clear picture by focusing the electrons into a
narrow beam.
4. Deflection Yoke: It is used to control the direction of the electron beam. It creates an
electric or magnetic field which will bend the electron beam as it passes through the area.
In a conventional CRT, the yoke is linked to a sweep or scan generator. The deflection yoke
which is connected to the sweep generator creates a fluctuating electric or magnetic
potential.
5. Phosphorus-coated screen: The inside front surface of every CRT is coated with
phosphors. Phosphors glow when a high-energy electron beam hits them. Phosphorescence
is the term used to characterize the light given off by a phosphor after it has been exposed
to an electron beam.
Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are called
picture elements or pixels. Beam refreshing is of two types. First is horizontal retracing and
second is vertical retracing. When the beam starts from the top left corner and reaches the
bottom right scale, it will again return to the top left side called at vertical retrace. Then it
will again more horizontally from top to bottom call as horizontal retracing shown in fig:
Point-
A Point in two-dimensional geometry is defined as a location in 2D space that is
uniquely defined by coordinates (x, y) where x, y are the distances of the point from the X-
axis,and Y-axis, respectively
Straight Line-
A straight line may be defined by two endpoints & an equation. In fig the two endpoints are
described by (x1,y1) and (x2,y2). The equation of the line is used to determine the x, y
coordinates of all the points that lie between these two endpoints.
Using the equation of a straight line, y = mx + b where
m= and
b = the y interrupt,
we can find values of y by incrementing x from x =x1, to x = x2. By scan-converting these
calculated x, y values, we represent the line as a sequence of pixels.
The lines must be generated parallel or at 45° to the x and y-axes. Other lines cause a
problem: a line segment through it starts and finishes at addressable points, may happen to
pass through no another addressable points in between.
2. Lines should terminate accurately: Unless lines are plotted accurately, they may
terminate at the wrong place.
3. Lines should have constant density: Line density is proportional to the no. of dots
displayed divided by the length of the line.
1. DDA Algorithm-
DDA Algorithm is the simplest line drawing algorithm. In this, 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 = (X , Y ) 0 0
● Ending coordinates = (X , Y )
n n
The points generation using DDA Algorithm involves the following steps-
Step-01:
Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
● ΔX = Xn – X0
● ΔY =Yn – Y0
● M = ΔY / ΔX
Step-02:
Find the number of steps or points in between the starting and ending coordinates.
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.
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 = Xn – X0 = 8 – 5 = 3
● ΔY =Yn – Y0 = 12 – 6 = 6
● M = ΔY / ΔX = 6 / 3 = 2
Step-02:
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = Δ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)
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-
● 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.
Procedure- Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
The points generation using Bresenham Line Drawing Algorithm involves the following
steps-
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 decision parameter Pk. It is calculated as-
Pk = 2ΔY – ΔX
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point depending on the value of decision parameter Pk.
Follow the below two cases-
Step-04:
Keep repeating Step-03 until the end point is reached or number of iterations equals to
(ΔX-1) times.
Problem-01:
Calculate the points between the starting coordinates (9, 18) and ending coordinates (14,
22).
Solution- Given-
● Starting coordinates = (X , Y ) = (9, 18) 0 0
Step-01:
Calculate ΔX and ΔY from the given input.
● ΔX = X – X = 14 – 9 = 5 n 0
● ΔY =Y – Y = 22 – 18 = 4
n 0
Step-02:
Calculate the decision parameter.
P = 2ΔY – ΔX
k
=2x4–5
=3
So, decision parameter P = 3 k
Step-03:
As P >= 0, so case-02 is satisfied.
k
Thus,
● P = P + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
k+1 k
● X = X + 1 = 9 + 1 = 10
k+1 k
● Y = Y + 1 = 18 + 1 = 19
k+1 k
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)
P k P X k+1 Y k+1 k+1
9 18
3 1 10 19
1 -1 11 20
-1 7 12 20
7 5 13 21
5 3 14 22
Step-02:
Calculate the value of initial decision parameter P0 as- P0 = 1 – R
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 Pk.
Follow the below two cases-
Step-04:
If the given centre point (X , Y ) is not (0, 0), then do the following and plot the point-
0 0
● X =X +X
plot c 0
● Y =Y +Y
plot c 0
Step-05:
Keep repeating Step-03 and Step-04 until X >= Y .
plot plot
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-
Problem-01:
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to form a
circle.
Solution- Given:
Radius of Circle = 10
●
Step-01:
Assign the starting point coordinates (X , Y ) as- 0 0
● X =0 0
● Y = R = 10 0
Step-02:
Calculate the value of initial decision parameter P as- 0
P =1–R
0
P = 1 – 10
0
P = -9
0
Step-03:
As P < 0, so case-01 is satisfied.
initial
Thus,
● X =X +1=0+1=1 k+1 k
● Y = Y = 10 k+1 k
● P = P + 2 x X + 1 = -9 + (2 x 1) + 1 = -6
k+1 k k+1
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 X >= Y as follows- k+1 k+1
(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 Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X and Y
coordinates.
Octant-1 Points Octant-2 Points
(0, 10) (8, 6)
(1, 10) (9, 5)
(2, 10) (9, 4)
(3, 10) (10, 3)
(4, 9) (10, 2)
(5, 9) (10, 1)
(6, 8) (10, 0)
These are all points for Quadrant-1.
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-
Quadrant-1 (X,Y) Quadrant-2 (-X,Y) Quadrant-3 (-X,-Y) Quadrant-4 (X,-Y)
(0, 10) (0, 10) (0, -10) (0, -10)
(1, 10) (-1, 10) (-1, -10) (1, -10)
(2, 10) (-2, 10) (-2, -10) (2, -10)
(3, 10) (-3, 10) (-3, -10) (3, -10)
(4, 9) (-4, 9) (-4, -9) (4, -9)
(5, 9) (-5, 9) (-5, -9) (5, -9)
(6, 8) (-6, 8) (-6, -8) (6, -8)
(8, 6) (-8, 6) (-8, -6) (8, -6)
(9, 5) (-9, 5) (-9, -5) (9, -5)
(9, 4) (-9, 4) (-9, -4) (9, -4)
(10, 3) (-10, 3) (-10, -3) (10, -3)
(10, 2) (-10, 2) (-10, -2) (10, -2)
(10, 1) (-10, 1) (-10, -1) (10, -1)
(10, 0) (-10, 0) (-10, 0) (10, 0)
These are all points of the Circle.
Four connected approaches is more suitable than the eight connected approaches.
1. Four connected approaches: In this approach, left, right, above, below pixels are tested.
2. Eight connected approaches: In this approach, left, right, above, below and four
diagonals are selected.
Boundary can be checked by seeing pixels from left and right first. Then pixels are checked
by seeing pixels from top to bottom. The algorithm takes time and memory because some
recursive calls are needed.
Algorithm:
1. Take the position of the starting point and the boundary color.
2. Decide wether you want to go in 4 directions (N, S, W, E) or 8 directions (N, S, W, E,
NW, NE, SW, SE).
3. Choose a fill color.
4. Travel in those directions.
5. If the pixel you land on is not the fill color or the boundary color , replace it with the
fill color.
6. Repeat 4 and 5 until you’ve been everywhere within the boundaries.
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 3 − Sort the intersection point in the increasing order of X coordinate
i.e. p0,p1,p1,p2 and p2,p3.
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate
pairs.
4-Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We are putting the
pixels above, below, to the right, and to the left side of the current pixels and this process
will continue until we find a boundary with different color.
Algorithm:
Step 1 − Initialize the value of seed point seedx,seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till
the boundary pixels reached.
If getpixel(x, y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below where we tried
to fill the entire region. Here, the image is filled only partially. In such cases, 4-connected
pixels technique cannot be used.
8-Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We are putting pixels
above, below, right and left side of the current pixels as we were doing in 4-connected
technique.
In addition to this, we are also putting pixels in diagonals so that entire area of the current
pixel is covered. This process will continue until we find a boundary with different color.
Algorithm:
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till
the boundary pixels reached
If getpixel(x,y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighbourhood points
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)
Step 6 − Exit
5. If the tile you land on is a target, replace it with the chosen color.
Curve Generation
In computer graphics, we often need to draw different types of objects onto the screen.
Objects are not flat all the time and we need to draw curves many times to draw an object.
A curve is an infinitely large set of points. Each point has two neighbors except endpoints.
Types of Curves
Curves can be broadly classified into three categories − explicit, implicit, and parametric
curves.
Implicit Curves: Implicit curves are defined by an equation of the form f(x,y)=0, where f(x,y)
is a function of the coordinates x and y in a plane. Implicit curves describe all the points
that satisfy a certain relationship between x and y.
A common example is the circle, whose implicit representation is
x2 + y2 - R2 = 0
Explicit Curves: A mathematical function y = f(x) can be plotted as a curve. Such a function is
the explicit representation of the curve. The explicit representation is not general, since it
cannot represent vertical lines and is also single-valued. For each value of x, only a single
value of y is normally computed by the function.
An explicit curve is expressed as y=f(x), where y is directly dependent on x. This means for
any given x-value, you can directly compute the corresponding y-value using the function
f(x).
A parametric curve in two dimensions is described by two functions, x(t) and y(t), where t
is the parameter that typically varies over an interval [t0,t1]:
x=f(t), y=g(t)
Bezier Curves: Bezier curve is discovered by the French engineer Pierre Bézier. These are
parametric curves widely used in computer graphics, animation, and modeling for creating
smooth and scalable shapes. Bézier curves are used in vector graphics (like SVG), font
design, and even animation paths. They are defined by a set of control points, and the
curve's shape is determined by these points. The Bezier curve can be represented
mathematically as –
Where,
B-Spline Curves: These are generalizations of Bézier curves that offer more flexibility and
control over the curve’s shape, particularly for complex shapes. Like Bézier curves, B-splines are
widely used in computer-aided design (CAD), animation, and modeling, but they are more
versatile when it comes to handling large numbers of control points. The B-Spline curve can be
represented mathematically as –
Where,