Q. What is computer Graphics? Explain the application of computer GRAPHICS.
Computer graphics deals with creation, manipulation and storage of different type of
images and objects. Some of the applications of computer graphics are: Computer Art:
Using computer graphics we can create fine and commercial art which include animation
packages, paint packages.
Application of Computer Graphics: -
1. Computer Art: - Using computer graphics we can create fine and commercial art which
include animation packages, paint packages. These packages provide facilities for
designing object shapes and specifying object motion. Cartoon drawing, paintings, logo
design can also be done.
2. Computer Aided Drawing: - Designing of buildings, automobile, aircraft is done with
the help of computer aided drawing, this helps in providing minute details to the
drawing and producing more accurate and sharp drawings with better specifications.
3. Presentation Graphics: - For the preparation of reports or summarising the financial,
statistical, mathematical, scientific, economic data for research reports, managerial
reports, moreover creation of bar graphs, pie charts, time chart, can be done using the
tools present in computer graphics.
4. Entertainment: - Computer graphics finds a major part of its utility in the movie
industry and game industry. Used for creating motion pictures , music video, television
shows, cartoon animation films. In the game industry where focus and interactivity are
the key players, computer graphics helps in providing such features in the efficient
way.
5. Education: -Computer generated models are extremely useful for teaching huge
number of concepts and fundamentals in an easy to understand and learn manner.
Using computer graphics many educational models can be created through which more
interest can be generated among the students regarding the subject.
6. Training: - Specialised system for training like simulators can be used for training the
candidates in a way that can be grasped in a short span of time with better
understanding. Creation of training modules using computer graphics is simple and
very useful.
7. Visualisation: - Today the need of visualise things have increased drastically, the need
of visualisation can be seen in many advance technologies , data visualisation helps in
finding insights of the data , to check and study the behaviour of processes around us
we need appropriate visualisation which can be achieved through proper usage of
computer graphics
8. Image Processing: - Various kinds of photographs or images require editing in order to
be used in different places. Processing of existing images into refined ones for better
interpretation is one of the many applications of computer graphics.
9. Machine Drawing: - Computer graphics is very frequently used for designing, modifying
and creation of various parts of machine and the whole machine itself, the main reason
behind using computer graphics for this purpose is the precision and clarity we get
from such drawing is ultimate and extremely desired for the safe manufacturing of
machine using these drawings.
10. Graphical User Interface: - The use of pictures, images, icons, pop-up menus,
graphical objects help in creating a user-friendly environment where working is easy
and pleasant.
Q. Explain the working of Raster and Random scan display with diagram.
Random Scan Display: - In Random Scan Display, the electron beam direct straightway to
the particular points of the screen where the image is producing. Random Scan Display
generates the image by drawing a set of random straight lines. It is much in the same way
one might move a pencil over a piece of paper to draw an image. The drawing strikes from
one point to another, one line at a time. That’s why this technique also says Vector Scan
Display.
No bit planes are containing mapped pixel values in the vector systems. Instead of
the Display Buffer memory stores a set of line-drawing commands along with endpoint
coordinates in a display list or display program created by a graphics package. The display
processing unit (DPU) executes each command during every refresh cycle and feeds the
vector generator with digital x, y, Δx, Δy values.
Raster Scan Display: - Raster Scan Display basically employs a Cathode Ray Tube (CRT)
or an LCD panel for display. The CRT works just like the picture tube of a television set.
Raster Scan Display viewing surface is coated with a layer of arrayed phosphor dots. At the
back of the CRT is a set of electron guns (cathodes) that produce a controlled stream of
electrons that says electron beam. The phosphor material emits light when struck by these
high-energy electrons. The Architecture of Raster and Random Scan Display Devices
Diagram is given below:
The frequency and intensity of the emitting light depend on the type of phosphor material
uses and the energy of the electrons. To produce a picture on the screen, these directed
electron beams start at the top of the screen. It scans rapidly from left to right along the
row of phosphor dots. They return to the leftmost position one line down. It scans again
and repeats this to cover the entire screen. The return of the beam direction to the leftmost
position is one line down that says Horizontal Retrace.
Q. Write and explain Bresenham’s & Midpoint circle generating algorithm.
In Bresenham's algorithm at any point (x, y) we have two option either to choose the next
pixel in the east i.e. (x+1, y) or in the south east i.e. (x+1, y-1). 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. Let us discuss the algorithms in detail −
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
Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y,
and R respectively. Set P=0 and Q=R.
Step 2 − Set decision parameter D = 3 – 2R.
Step 3 − Repeat through step-8 while P ≤ Q.
Step 4 − Call Draw Circle (X, Y, P, Q).
Step 5 − Increment the value of P.
Step 6 − If D < 0 then D = D + 4P + 6.
Step 7 − Else Set R = R - 1, D = D + 4(P-Q) + 10.
Step 8 − Call Draw Circle (X, Y, P, Q).
Midpoint algorithm: - The midpoint circle drawing algorithm helps us to calculate the
complete perimeter points of a circle for the first octant. We can quickly find and calculate
the points of other octants with the help of the first octant points. The remaining points
are the mirror reflection of the first octant points.
Step 1 − Input radius r and circle center $(x_{c,} y_{c})$ and obtain the first point on the
circumference of the circle centered on the origin as.
Step 2 − Calculate the initial value of decision parameter as
$P_{0}$ = 5/4 – r (See the following description for simplification of this equation.)
Step 3 − At each $X_{K}$ position starting at K=0, perform the following test −
Step 4 − Determine the symmetry points in other seven octants.
Step 5 − Move each calculate pixel position (X, Y) onto the circular path centered on $(X_{C,}
Y_{C})$ and plot the coordinate values.
Step 6 − Repeat step-3 through 5 until X >= Y.
Q: -Flood Fill Algorithm:
In this method, a point or seed which is inside region is selected. This point is called a
seed point. Then four connected approaches or eight connected approaches is used to fill
with specified color.
The flood fill algorithm has many characters similar to boundary fill. But this method is
more suitable for filling multiple colors boundary. When boundary is of many colors and
interior is to be filled with one color we use this algorithm.
Algorithm: -
Procedure floodfill (x, y,fill_ color, old_color: integer)
If (getpixel (x, y)=old_color)
{
setpixel (x, y, fill_color);
fill (x+1, y, fill_color, old_color);
fill (x-1, y, fill_color, old_color);
fill (x, y+1, fill_color, old_color);
fill (x, y-1, fill_color, old_color);
}
}
Q. RGB MODEL
The RGB color model is one of the most widely used color representation method in
computer graphics. It uses a color coordinate system with three primary colors:
R(red), G(green), B(blue)
Each primary color can take an intensity value ranging from 0(lowest) to 1(highest). Mixing
these three primary colors at different intensity levels produces a variety of colors. The
collection of all the colors obtained by such a linear combination of red, green and blue
forms the cube shaped RGB color space.
Q. Interactive and Passive Graphics: -
Interactive and Passive Graphics
(a) Interactive Computer Graphics:
In interactive Computer Graphics user have some controls over the picture, i.e., the user
can make any change in the produced image. One example of it is the ping-pong game.
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.
(b) Non-Interactive or Passive Computer Graphics:
In non-interactive computer graphics, the picture is produced on the monitor, and the
user does not have any controlled over the image, i.e., the user cannot make any change in
the rendered image. One example of its Titles shown on T.V.
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.
Q: -BOUNDRY FILL ALGORITHM: -
Introduction: Boundary Fill Algorithm starts at a pixel inside the polygon to be filled and
paints the interior proceeding outwards towards the boundary. This algorithm works only
if the color with which the region has to be filled and the color of the boundary of the
region are different. If the boundary is of one single color, this approach proceeds
outwards pixel by pixel until it hits the boundary of the region.
Algorithm: -
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);
}
}
Q: - LINE Drawing Algorithm Bresenhem’s.
This algorithm is used for scan converting a line. It was developed by Bresenham. It is an
efficient method because it involves only integer addition, subtractions, and multiplication
operations. These operations can be performed very rapidly so lines can be generated
quickly.
Bresenham's Line Algorithm:
Step1: Start Algorithm
Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy
Step3: Enter value of x1,y1,x2,y2
Where x1,y1are coordinates of starting point
And x2,y2 are coordinates of Ending point
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1
Calculate i1=2*dy
Calculate i2=2*(dy-dx)
Calculate d=i1-dx
Step5: Consider (x, y) as starting point and x endas
maximum possible value of x.
If dx < 0
Then x = x2
y = y2
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2
Step6: Generate point at (x,y)coordinates.
Step7: Check if whole line is generated.
If x > = xend
Stop.
Step8: Calculate co-ordinates of the next pixel
If d < 0
Then d = d + i1
If d ≥ 0
Then d = d + i2
Increment y = y + 1
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
Step11: Go to step 7
Step12: End of Algorithm
Q: - LINE Drawing program DDA in Graphics.
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main()
{
intgd = DETECT ,gm, i;
float x, y,dx,dy,steps;
int x0, x1, y0, y1;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor(WHITE);
x0 = 100 , y0 = 200, x1 = 500, y1 = 300;
dx = (float)(x1 - x0);
dy = (float)(y1 - y0);
if(dx>=dy)
{
steps = dx;
}
else
{
steps = dy;
}
dx = dx/steps;
dy = dy/steps;
x = x0;
y = y0;
i = 1;
while(i<= steps)
{
putpixel(x, y, RED);
x += dx;
y += dy;
i=i+1;
}
getch();
closegraph();
}
Q: - 2D Transformation & Homogenous Coordinates: -
Transformation means changing some graphics into something else by applying rules. We
can have various types of transformations such as translation, scaling up or down,
rotation, shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.
Transformations play an important role in computer graphics to reposition the graphics on
the screen and change their size or orientation.
Homogenous Coordinates: -
To perform a sequence of transformation such as translation followed by rotation and
scaling, we need to follow a sequential process −
Translate the coordinates,
Rotate the translated coordinates, and then
Scale the rotated coordinates to complete the composite transformation.
To shorten this process, 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. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point PX, Y can be
converted to homogenous coordinates by P’ (Xh, Yh, h).
Q: -Algorithm of Cohen Sutherland Line Clipping:
Step1: Calculate positions of both endpoints of the line
Step2: Perform OR operation on both of these end-points
Step3: If the OR operation gives 0000
Then
line is considered to be visible
else
Perform AND operation on both endpoints
If and ≠ 0000
then the line is invisible
else
And=0000
Line is considered the clipped case.
Step4: If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)
(a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window
(b) If bit 2 is "1" line intersect with right boundary
y3=y1+m(X-X1)
where X = Xwmax
where X more is maximum value of X co-ordinate of the window
(c) If bit 3 is "1" line intersects with bottom boundary
X3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window
(d) If bit 4 is "1" line intersects with the top boundary
X3=X1+(y-y1)/m
where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window
Q: - Polygon clipping Sutherland-Hodgeman Polygon clipping Algorithm: -
Q: -3-D Transformation:
In very general terms a 3D model is a mathematical representation of a physical entity
that occupies space. In more practical terms, a 3D model is made of a description of its
shape and a description of its color appearance.3-D Transformation is the process of
manipulating the view of a three-D object with respect to its original position by modifying
its physical attributes through various methods of transformation like Translation,
Scaling, Rotation, Shear, etc.
Properties of 3-D Transformation:
Lines are preserved,
Parallelism is preserved,
Proportional distances are preserved.
One main categorization of a 3D object’s representation can be done by considering
whether the surface or the volume of the object is represented:
Boundary-based: the surface of the 3D object is represented. This representation is also
called b-rep. Polygon meshes, implicit surfaces, and parametric surfaces
Q: -BSP Tree Method: -
The procedure to build a BSP Tree in the object space is given as follows:
1. Select a polygon (Arbitrary) as the root of the tree.
2. Partition the object space into two half-spaces (inside & outside of the partition plane
determined by the normal to the plane), some object polygons lie in the rear half while
others in the front half of the partition plane.
3. If a polygon is intersected by the partition plane, split it into two polygons so that it
belongs to different half-spaces.
4. Select one polygon in the root’s front as the left node or child and another in the root’s
back as the right node or child.
5. Recursively subdivide spaces considering the plane of the children as partition planes
until a subspace contains a single polygon.
Q: -Bezier Curves
Bezier curve is discovered by the French engineer Pierre Bézier. These curves can be
generated under the control of other points. Approximate tangents by using control points
are used to generate curve. The Bezier curve can be represented mathematically as −
∑k=0nPiBni(t)∑k=0nPiBin(t)
Where pipi is the set of points and Bni(t)Bin(t) represents the Bernstein polynomials
which are given by −
Bni(t)=(ni)(1−t)n−itiBin(t)=(ni)(1−t)n−iti
Where n is the polynomial degree, i is the index, and t is the variable.
The simplest Bézier curve is the straight line from the point P0P0 to P1P1. A quadratic
Bezier curve is determined by three control points. A cubic Bezier curve is determined by
four control points.
Properties of Bezier Curves
Bezier curves have the following properties −
They generally follow the shape of the control polygon, which consists of the segments
joining the control points.
They always pass through the first and last control points.
They are contained in the convex hull of their defining control points.
The degree of the polynomial defining the curve segment is one less that the number of
defining polygon point. Therefore, for 4 control points, the degree of the polynomial is 3,
i.e. cubic polynomial.
Q: -Interpolative shading model: -
Interpolative Shading The idea of interpolative shading is to avoid computing the full
lighting equation at each pixel by interpolating quantities at the vertices of the faces.
Given vertices p¯1, p¯2, and p¯3, we need to compute the normal for each vertex,
compute the radiances for each vertex, project onto the window in device coordinates, and
fill the polygon using scan conversion.
There are two methods used for interpolative shading:
Grouard Shading The radiance values are computed at the vertices and then linearly
interpolated within each triangle.
Phung shading the normal values at each vertex are linearly interpolated within each
triangle, and the radiance is computed at each pixel.
Q: -B-Spline Curves
The Bezier-curve produced by the Bernstein basis function has limited flexibility.
First, the number of specified polygon vertices fixes the order of the resulting polynomial
which defines the curve.
The second limiting characteristic is that the value of the blending function is nonzero for
all parameter values over the entire curve.
The B-spline basis contains the Bernstein basis as the special case. The B-spline basis is
non-global.
A B-spline curve is defined as a linear combination of control points Pi and B-spline basis
function Ni,Ni, k tt given by
C(t)=∑ni=0PiNi,k(t),C(t)=∑i=0nPiNi,k(t), n≥k−1,n≥k−1, tϵ[tk−1,tn+1]
Where,
{pipi: i=0, 1, 2….n} are the control points
k is the order of the polynomial segments of the B-spline curve. Order k means that the
curve is made up of piecewise polynomial segments of degree k - 1,
the Ni,k(t)Ni,k(t) are the “normalized B-spline blending functions”. They are described by
the order k and by a non-decreasing sequence of real numbers normally called the “knot
sequence”.
ti:i=0,...n+Kti:i=0,...n+K
The Ni, k functions are described as follows −
Ni,1(t)={1,0,ifuϵ[ti,ti+1)OtherwiseNi,1(t)={1,ifuϵ[ti,ti+1)0,Otherwise
and if k > 1,
Ni,k(t)=t−titi+k−1Ni,k−1(t)+ti+k−tti+k−ti+1Ni+1,k−1(t)
and
tϵ[tk−1,tn+1)tϵ[tk−1,tn+1)
Properties of B-spline Curve
B-spline curves have the following properties −
The sum of the B-spline basis functions for any parameter value is 1.
Each basis function is positive or zero for all parameter values.
Each basis function has precisely one maximum value, except for k=1.
The maximum order of the curve is equal to the number of vertices of defining
polygon.
Q: -Z-Buffer Algorithm: -
It is also called a Depth Buffer Algorithm. Depth buffer algorithm is simplest image space
algorithm. For each pixel on the display screen, we keep a record of the depth of an object
within the pixel that lies closest to the observer. In addition to depth, we also record the
intensity that should be displayed to show the object. Depth buffer is an extension of the
frame buffer. Depth buffer algorithm requires 2 arrays, intensity and depth each of which
is indexed by pixel coordinates (x, y).
Algorithm: -
For all pixels on the screen, set depth [x, y] to 1.0 and intensity [x, y] to a background
value.
For each polygon in the scene, find all pixels (x, y) that lie within the boundaries of a
polygon when projected onto the screen. For each of these pixels:
(1) Calculate the depth z of the polygon at (x, y)
(2) If z < depth [x, y], this polygon is closer to the observer than others already recorded
for this pixel. In this case, set depth [x, y] to z and intensity [x, y] to a value corresponding
to polygon's shading. If instead z > depth [x, y], the polygon already recorded at (x, y) lies
closer to the observer than does this new polygon, and no action is taken.
3. After all, polygons have been processed; the intensity array will contain the solution.
4. The depth buffer algorithm illustrates several features common to all hidden surface
algorithms.
5. First, it requires a representation of all opaque surface in scene polygon in this case.
6. These polygons may be faces of polyhedral recorded in the model of scene or may
simply represent thin opaque 'sheets' in the scene.
7. The IInd important feature of the algorithm is its use of a screen coordinate system.
Before step 1, all polygons in the scene are transformed into a screen coordinate system
using matrix multiplication.
Q: -Midpoint Ellipse generation algorithm
Mid-Point Ellipse Algorithm:
Take input radius along x axis and y axis and obtain center of ellipse.
Initially, we assume ellipse to be centered at origin and the first point as : (x, y0)= (0, ry).
Obtain the initial decision parameter for region 1 as: p10=ry2+1/4rx2-rx2ry
For every xk position in region 1 :
If p1k<0 then the next point along the is (xk+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (xk+1, yk-1 )
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
Obtain the initial value in region 2 using the last point (x0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
At each yk in region 2 starting at k =0 perform the following task.
If p2k>0 the next point is (xk, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
Else, the next point is (xk+1, yk -1) and p2k+1=p2k+2ry2xk+1 -2rx2yk+1+rx2
Now obtain the symmetric points in the three quadrants and plot the coordinate value as:
x=x+xc, y=y+yc
Repeat the steps for region 1 until 2ry2x>=2rx2y