Computer Graphics Theory
Computer Graphics Theory
2 Marks Questions:
1. Define Pixel and Resolution.
Answer: Pixel: Pixel or Pel is defined as "the smallest addressable screen element". OR
A pixel may be defined as the smallest size object or color spot that can be displayed and
addressed on a monitor.
Resolution: This is referring to the size of the pixel. The number of horizontal and vertical
pixels on a display screen is called Resolution. The smaller the pixel, the higher the
resolution.
2. List any four areas of applications of Computer Graphics.
Answer:
It is a computer display mode that uses pixels to create an image. The screen is internally
represented as a grid of pixels in graphics mode. The smallest addressable entity on the screen
is the pixel.
Pixels are used to represent everything, including characters. More smooth shapes and
typefaces are supported in Graphics mode. In text mode, graphical objects such as a circle, line,
triangle, and so on cannot be displayed.
5. List different Display devices.
Answer: There are some display devices given below:
1. Cathode-Ray Tube(CRT)
2. Color CRT Monitor
3. Liquid crystal display(LCD)
4. Light Emitting Diode(LED)
5. Direct View Storage Tubes(DVST)
6. Plasma Display
7. 3D Display
6. Define aspect ratio. Give one example of an Aspect ratio.
Answer: Aspect ratio: It is the ratio of the number of vertical points to the number of
horizontal points necessary to produce equal length lines in both directions on the screen.
Or
In computer graphics, the relative horizontal and vertical sizes. For example, if a graphic
has an aspect ratio of 2:1, it means that the width is twice as large as the height. Or Aspect
ratio is the ratio between width of an image and the height of an image.
Example: The term is also used to describe the dimensions of a display resolution. For
example, a resolution of 800x600, 1027x768, 1600x1200 has an aspect ratio of 4:3.
Resolution 1280x1024 has an aspect ratio 5:4. Resolution 2160x1440, 2560x1700 has an
aspect ratio 3:2.
Advantages:
• Virtual reality creates a realistic world
• Through Virtual Reality user can experiment with an artificial environment.
• Virtual Reality make the education more easily and comfort.
• It enables user to explore places.
• Virtual Reality has made watching more enjoyable than reading.
Virtual reality widely used in video games, engineering, entertainment, education, design,
films, media, medicine and many more.
Augmented reality merges the physical world with computer-generated virtual elements.
It is accessed using common equipment such as mobile phones.
• There are nearly uncountable possibilities with the Augmented Reality. With the
smartphone's camera, AR adds the digital elements to a live view.
• It uses the smartphone's camera to present the real world's view in front of us and
then put a layer of information that includes the text or images on the top of that
view.
• Some of the examples of Augmented Reality are the Pokemon Go game, Snapchat
lenses.
From the Fig., we can see that from the point (x, y), the number of interactions point on the left
side is 5 and on the right side is 3. So, on both sides of the point, the number of interactions are
odd. Hence, the point is considered within the object.
4 Marks
5. Consider the line from (0,0) to (4,6). Use DDA algorithm to rasterize this line.
Answer:
Step 1: x1 = 0; y1 = 0, x2 = 4 and y2 = 6
𝑦 −𝑦 6−0 6
Step 2 : Slope 𝑚 = 𝑥2−𝑥1 = 4−0 = 4 which is more than 1.
2 1
1
𝑦1 = 𝑦1 + 1, 𝑥1 = 𝑥1 +
𝑚
1 0 0 (0,0)
3 0.67+4/6=1.34 2 (1,2)
4 1.34+4/6=2.01 3 (2,3)
5 2.01+4/6=2.68 4 (3,4)
6 2.68+4/6=3.35 5 (3,5)
7 3.35+4/6=4.02 6 (4,6)
The algorithm will stop here because x and y values are reached to end point (4,6).
Let us consider a line joining point A (x1, y1) and B (x2, y2)
𝑦 −𝑦
The slope of this equation is given as 𝑚 = 𝑥2 −𝑥1
2 1
#include <graphics.h>
void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
int x = 250, y = 200, radius = 50;
circle(x, y, radius);
boundaryFill4(x, y, 6, 15);
delay(10000);
getch();
closegraph();
return 0;
}
Algorithm DDA
1. Read the line end points (𝑥1, y1) and (𝑥2, y2) such that they are not equal. [If
equal then plot that point and exit]
2. Δ𝑥 = |𝑥2 − 𝑥1| and Δ𝑦 = |𝑦2 − 𝑦1|
3. If (Δ𝑥 ≥ Δ𝑦) 𝑡ℎ𝑒𝑛
Length=Δ𝑥
Else
Length=Δ𝑦
End if
4. Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡ℎ
Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡ℎ
[This makes either Δ𝑥 or Δ𝑦 equal to 1 because length is either 𝑥2 − 𝑥1 or 𝑦2−
𝑦1. Therefore, the incremental value for either x or y is one.]
5. 𝑥 = 𝑥1 + 0.5 sign (Δ𝑥)
𝑌 = 𝑦1 + 0.5 sign (Δ𝑦)
[Here, sign function makes the algorithm work in all quadrants. It
returns -1, 0, 1 depending on whether its argument is <0, =0, >0, respectively.]
6 . i=1
[begins the loop, in this points are plotted]
While ( i ≤ length)
Begin
Plot (integer (x), integer (y))
𝑥 = 𝑥 + Δ𝑥
𝑦 = 𝑦 + Δ𝑦
𝑖=𝑖+1
End.
Stop
Note :
1- Sign function returns : -1 if its argument is < 0
: 0 if its arguments is = 0
: +1 if its arguments is > 0
Using the Sign function makes the algorithm work in all quadrants.
Example 2.1: consider the line from (0,0) to (6,6). Use the simple DDA algorithm
to rasterize this line
Solution:
i plot x y
0.5 0.5
1 (0,0)
1.5 1.5
2 (1,1)
2.5 2.5
3 (2,2)
3.5 3.5
4 (3,3)
4.5 4.5
5 (4,4)
5.5 5.5
6 (5,5)
6.5 6.5
Example 2.2: consider the line from (23,33) to (29,40) Use the simple DDA
algorithm to rasterize this line
Solution:
x1=23 ,
y1=33 ,
x2=29 ,
y2=40
Δ𝑥 = 𝑥2 − 𝑥1 =6
Length = 𝑦2− 𝑦1=7
Δ𝑥 = (𝑥2 − 𝑥1)/𝑙𝑒𝑛𝑔𝑡ℎ
= 6/7 = 0.85 and
Δ𝑦 = (𝑦2 − 𝑦1)/𝑙𝑒𝑛𝑔𝑡ℎ
=7/7 = 1
Initial value for
𝑥 = 23 + 0.5 (0.8) =23
𝑌 = 33 + 0.5 (1) = 33.5
i x y Plot(x,y)
1. 23.5 33.5 (23,33)
2. 24.3 34.5 (24,34)
3. 25.1 35.5 (25,35)
4. 25.9 36.5 (25, 36)
5. 26.7 37.5 (26, 37)
6. 27.5 38.5 (27, 38)
7. 28.3 39.5 (28, 39)
Example 2.3: consider the line from (0,0) to (4,6). Use the simple DDA
Solution:
x1=0 , y1=0 ,
x2=4, y2=6
Length = y2− y1 =6
Δ𝑥 = (x2 − x1)/ length = 4/6 and
Δy = (y2 − y1)/ length =6/6 = 1
1. Read the line end points (x1, y1) and (x2 , y2) such that they are not equal.
[If equal, then plot that point and exit]
2. ∆𝑥 =∣ 𝑥2 − 𝑥1 ∣ And ∆𝑦 =∣ 𝑦2 − 𝑦1 ∣
3. [Initialize starting point]
x=x1
y=y1
4. 𝑒 = 2 ∗ ∆𝑦 − ∆𝑥
[Initialize value of decision variable or error to compensate for non zero
intercepts]
5. i=1
[Initialize counter]
6. Plot (x,y)
7. While (e ≥ 0)
{
y=y+1
e = e − 2 ∗ Δx
}
x=x+1
e = e + 2 ∗ Δy
8. i=i+1
9. If (i≤Δx) then go to step 6
10. Stop
Example2.2:- Consider the line from (5, 5) to (13, 9), use the Bresenham's
algorithm to rasterize the line.
Solution: Evaluating steps 1 through 4 in the Bresenham's algorithm we have,
𝚫x = ∣13-5∣=8
𝚫y = l9-5∣=4
x=5 , y=5.
𝑒 = 2 ∗ ∆𝑦 − ∆𝑥 = 2*4-8 =0
Tabulating the results of each iteration in the step 5 through 10
i plot x y e
5 5 0
1 (5,5) 6 6 -16
-8
2 (6,6) 7 6 0
3 (7,6) 8 7 -16
-8
4 (8,7) 9 7 0
5 (9,7) 10 8 -16
-8
6 (10,8) 11 8 0
7 (11,8) 12 9 -16
-8
8 (12,9) 13 9 0
9 (13,9) 14 10 -16
-8
1. Read the line end points (x1, y1) and (x2, y2) such that they are not equal.
[If equal then plot that point and exit]
2. ∆𝑥 =∣ 𝑥2 − 𝑥1 ∣ and ∆𝑦 =∣ 𝑦2 − 𝑦1 ∣
3. [Initialize starting point]
x=x1
y=y1
4. 𝑆1 = 𝑆𝑖𝑔𝑛(𝑥2 − 𝑥1 )
𝑆2 = 𝑆𝑖𝑔𝑛(𝑦2 − 𝑦1 )
5. If ∆y > ∆x then
Begin
T=∆x : ∆x =∆y : ∆y =T : Interchange=1
End
Else
Interchange =0
End If
6. e = 2 ∗ ∆y − ∆x
[Initialize value of decision variable or error to compensate for non zero
intercepts]
7. i=1
[initialize counter ]
8. Plot (x,y)
9. While (𝐞 ≥ 𝟎)
Begin
If (Interchange=1) Then x=x + s1
Else y= y + s2
End If
e = e − 2 ∗ Δx
End while
I Plot E x y
0 0 0
1 (0,0)
-16 0 -1
-8 -1 -1
2 (-1,-1)
0 -2 -1
3 (-2,-1)
-16 -2 -2
-8 -3 -2
4 (-3,-2)
0 -4 -2
5 (-4,-2)
-16 -4 -3
-8 -5
6 (-5,-3)
0 -6 -3
7 (-6,-3)
-16 -6 -4
-8 -7 -4
8 (-7,-4)
0 -8 -4
Eight-Way Symmetry
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 . If the point
is (x,y)is on the circle , then we can trivially compute seven other points on
the circle , as shown in figure above. Therfore, we need to compute only 45
segment to detrmine the circle completely .
get point's symmetric complement about these lines by permuting the indices
:
{(x,-y), (-x,y), (-x,-y), (y,x), (y,-x), (-y,x),(-y,-x)}
Let us assume point P in Fig. 2.7 as a last scan converted pixel. Now we have two options
either to choose pixel A or pixel B. The closer pixel amongst these two can be determined as
follows:
The distances of pixels A and B from the origin are given as
𝐷𝐴 = √𝑋𝑖+1 2 + (𝑌𝑖 )2
Now, the distances of pixels A and B from the true circle are given as
𝛿𝐴 = 𝐷𝐴 − 𝑟 𝑎𝑛𝑑 𝛿𝐵 = 𝐷𝐵 − 𝑟
However, to avoid square root term in derivation of decision variable, i.e. to simplify the
computation and to make algorithm more efficient the 𝛿𝐴 𝑎𝑛𝑑 𝛿𝐵 defined as
𝛿𝐴 = 𝐷𝐴 2 − 𝑟 2 𝑎𝑛𝑑
𝛿𝐵 = 𝐷𝐵 2 − 𝑟 2
From Fig.2.7, we can observe that 𝛿𝐴 is always positive and 𝛿𝐵 always negative.
Therefore, we can define decision variable 𝑑𝑖 as
𝑑𝑖 = 𝛿𝐴 + 𝛿𝐵
and we can say that if 𝑑𝑖 < 0 , i.e. 𝛿𝐴 < 𝛿𝐵 then only x is incremented; otherwise x is
incremented in positive direction and y is incremented in negative direction. In other words
we can write,
Answer:
Answer:
- We have to use 3×3 transformation matrix instead of 2×2 transformation matrix.
- To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W.
- In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system.
- Homogeneous coordinates are used extensively in computer vision and graphics
because they allow common operations such as translation, rotation, scaling and
perspective projection to be implemented as matrix operations.
Answer:
• Reflection about X axis
• Reflection about Y axis
• Reflection about X=Y axis
• Reflection about X = -Y axis
• Reflection about origin
• Reflection about any line y = mx +c
• Reflection about a line parallel to X-axis
• Reflection about a line parallel to Y axis
4. Explain X-shear with Yref Line.
Answer:
Answer:
What is Parallel Projection? Explain with Example.
Answer:
- Parallel Projection use to display picture in its true shape and size. When projectors are
perpendicular to view plane then is called orthographic projection.
- The parallel projection is formed by extending parallel lines from each vertex on the
object until they intersect the plane of the screen.
- The point of intersection is the projection of vertex.
- Parallel projections are used by architects and engineers for creating working drawing
of the object, for complete representations require two or more views of an object using
different planes.
1. Isometric Projection: All projectors make equal angles generally angle is of
30°.
2. Dimetric: In these two projectors have equal angles. With respect to two
principle axis.
3. Trimetric: The direction of projection makes unequal angle with their principle
axis.
4. Cavalier: All lines perpendicular to the projection plane are projected with no
change in length.
5. Cabinet: All lines perpendicular to the projection plane are projected to one
half of their length. These give a realistic appearance of object.
Answer:
7. Prove that two Scaling Transformations Commute. i.e. S1*S2=S2*S1
Answer:
Answer:
1) Any 2D point in the homogeneous coordinate system is represented by a triplet (x, y,
b) where x, y and h are not all zero. (0, 0, 0) does not represent any point. Origin is
represented as (0,0,1)
2) In homogeneous coordinate systems, two points are identical, if one point is derived by
multiplying some constant to the second point.
3) If h is not zero, then point (xh, yh, h) in a homogenous coordinate system is represented
as (xh /h, yh/ h) in the Euclidean/Cartesian coordinate system.
4) If h is 0, point represented is at infinity.
CHAPTER 4
Windowing & Clipping
Answer:
Viewport: The viewport is the rectangular region on the display screen where the
contents of the window are actually displayed, mapped from the window
coordinates to screen coordinates, usually through a transformation process.
Answer:
Answer:
o Outcodes, also known as "outcode bits" or "clip codes," are a set of binary
values used in computer graphics to perform efficient line and polygon clipping
against a rectangular window or viewport.
o Each outcode corresponds to a specific region of the screen or window, and they
help determine if a line or polygon lies completely outside, partially inside, or
completely inside the defined clipping region.
o In the context of the Cohen-Sutherland line clipping algorithm, a common use
of outcodes, there are four outcode bits:
Top: This bit is set (1) if a point is above the clipping region's top boundary.
Bottom: This bit is set (1) if a point is below the clipping region's bottom
boundary.
Left: This bit is set (1) if a point is to the left of the clipping region's left
boundary.
Right: This bit is set (1) if a point is to the right of the clipping region's right
boundary
CHAPTER 5
Introduction to Curves
2 Marks Questions
1) List any four types of Curves.
Answer:
a) Bezier Curve
b) B-Spline Curve
c) Hilbert’s curve
d) Koch Curve
2) State the concept of Interpolation.
Answer:
- Depending upon the blending functions and boundary conditions, a curve generated
from a given set of control points may or may not interpolate the control points.
- If the curve passes through the control points. It is called interpolation. Interpolation
curves are used in animation and specifying camera motion. It is also used in digitizing
the coordinates.
3) Define spline curves.
Answer:
Answer:
- It was introduced by the German mathematician David Hilbert.
- This curve is also known as the Hilbert space- filling curve.
- The basic entity of this curve is U-shape as shown below.
Answer:
- Bezier curve is discovered by the French engineer Pierre Bezier.
- These curves can be generated under the control of other points.
- Approximate tangents by using control points are used to generate curve .
- To generate a cubic Bézier curve, you need four control points: P0, P1, P2, and P3.
- P0 and P3 are the start and end points of the curve, while P1 and P2 are the control points
that influence the shape of the curve.
- Here's the procedure to generate a cubic Bézier curve:
a) Define the control points: