Upload
others
View
11
Download
0
Embed Size (px)
Citation preview
Mumbai University I.T (Semester V)
1 |www.brainheaters.in
Solution for Computer Graphics
and Virtual Reality
May -2016
Index Q.1)
a) ………………………………………………………………………….2
b) ………………………………………………………………………….2
c) ………………………………………………………………………….3
d) ………………………………………………………………………….3-5
Q.2)
a) ………………………………………………………………………….5-7
b) ………………………………………………………………………….7-9
Q.3)
a) ………………………………………………………………………….10-12
b) ………………………………………………………………………….N.A
Q.4)
a) ………………………………………………………………………….12-16
b) ………………………………………………………………………….16-17
Q.5)
a) ………………………………………………………………………….N.A
b) ………………………………………………………………………….18-19
Q.6)
a) ………………………………………………………………………….19-20
b) ………………………………………………………………………….20-22
c) ………………………………………………………………………….22-24
d) ………………………………………………………………………….24-26
e) …………………………………………………………………………26-27
Mumbai University I.T (Semester V)
2 |www.brainheaters.in
Q1)
(a) Differentiate between Raster scan display and Random scan display
Ans:
(b) Prove that two successive rotation transformation are additive.
Ans:
About a line
Mumbai University I.T (Semester V)
3 |www.brainheaters.in
(c) Show that the transformation matrix for the reflection a line y=x is
equivalent to reflection to x-axis followed by counter clockwise rotation of
900
Ans:
(d) Explain 3D trackers and enumerate some important trackers characteristics.
Ans:
Mumbai University I.T (Semester V)
4 |www.brainheaters.in
Characteristics
Mumbai University I.T (Semester V)
5 |www.brainheaters.in
Q2)
(a) Specify and highlights and drawbacks of Bezier curve .Construct the Bezier
curve of order three with control points P1(0,0) , P2(1,3) P3(4,2) and
P4(2,1) .Generate at least five points on the curve.
Ans:
Mumbai University I.T (Semester V)
6 |www.brainheaters.in
Mumbai University I.T (Semester V)
7 |www.brainheaters.in
(b) Write DDA line drawing Algorithm .Compare DDA with Bresenham’s Line
drawing Algorithm.Calculate the pixel co-ordinates of line AB using DDA
algorithm where A=(0,0) and B =(4,6).
Ans:
Mumbai University I.T (Semester V)
8 |www.brainheaters.in
Mumbai University I.T (Semester V)
9 |www.brainheaters.in
Mumbai University I.T (Semester V)
10 |www.brainheaters.in
Q3)
(a) Let ABCD be the rectangular window with A (20,20) ,B(90,20) C(90,70)
And D( 20,70) .Find the region codes for endpoints and use cohen Sutherland
algorithm to clip the lines P1 P2 with P1 (10,30) and P2(80,90)
Ans:
Mumbai University I.T (Semester V)
11 |www.brainheaters.in
Mumbai University I.T (Semester V)
12 |www.brainheaters.in
(b) With respect to 3D transformation ,describe the steps to be carried out when
an object is to be rotated about an arbitrary axis. Specify all the required
matrices .State your assumptions clearly.
Ans: N.A
Q4)
(a) Explain the flood fill algorithm for 4 connected and 8 connected .What are
its advantages over boundary fill algorithm.
Ans:
Flood Fill Algorithm
Sometimes we come across an object where we want to fill the area and its boundary
with different colors. We can paint such objects with a specified interior color instead
of searching for particular boundary color as in boundary filling algorithm.
Instead of relying on the boundary of the object, it relies on the fill color. In other
words, it replaces the interior color of the object with the fill color. When no more
pixels of the original interior color exist, the algorithm is completed.
Mumbai University I.T (Semester V)
13 |www.brainheaters.in
Once again, this algorithm relies on the Four-connect or Eight-connect method of
filling in the pixels. But instead of looking for the boundary color, it is looking for all
adjacent pixels that are a part of the interior.
4-Connected & 8-ConnectedPolygon
In this technique 4-connected pixels are used as shown in the figure1. 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
Mumbai University I.T (Semester V)
14 |www.brainheaters.in
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 in figure 3
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 figure2. 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
Mumbai University I.T (Semester V)
15 |www.brainheaters.in
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
The 4-connected pixel technique failed to fill the area as marked in the figure 3 which
won’t happen with the 8-connected technique.
Comparison
Mumbai University I.T (Semester V)
16 |www.brainheaters.in
(b) Explain an algorithm which uses parametric equation of line clipping .Using
same algorithm find the line segment A(10,10) and B(70,40) after it is
clipped against the window of two vertices (20,10) and (40,50).
Ans: The solution to the sum of this question is not avail available. Answer to
the theory part is given below
Liang-Barsky Line Clipping
The ideas for clipping line of Liang-Barsky and Cyrus-Beck are the same. The only
difference is Liang-Barsky algorithm has been optimized for an upright rectangular
clip window. So we will study only the idea of Liang-Barsky.
Liang and Barsky have created an algorithm that uses floating-point arithmetic but
finds the appropriate end points with at most four computations. This algorithm uses
the parametric equations for a line and solves four inequalities to find the range of the
parameter for which the line is in the viewport.
Mumbai University I.T (Semester V)
17 |www.brainheaters.in
Let be the line which we want to study. The parametric
equation of the line segment from gives x-values and y-values for every point in
terms of a parameter tthat ranges from 0 to 1. The equations are
and
We can see that when t = 0, the point computed is P(x1,y1); and when t = 1, the point
computed is Q(x2,y2).
Algorithm
1. Set and
2. Calculate the values of tL, tR, tT, and tB (tvalues).
if or ignore it and go to the next edge
otherwise classify the tvalue as entering or exiting value (using inner
product to classify)
if t is entering value set ; if t is exiting value set
3. If then draw a line from (x1 + dx*tmin, y1 + dy*tmin) to (x1 +
dx*tmax, y1 + dy*tmax)
4. If the line crosses over the window, you will see (x1 + dx*tmin, y1 + dy*tmin)
and (x1 + dx*tmax, y1 + dy*tmax) are intersection between line and edge.
Mumbai University I.T (Semester V)
18 |www.brainheaters.in
Q5)
(a) Consider a triangle ABC whose coordinates are A(10,20) B(30,40) and
8C(50,20) .Perform the following transformation (specify the matrices that
are used)
(i) Translate the given triangle by 3 units in X direction and -2 unit in Y
direction .
(ii) Rotate the given triangle by 30
(iii) Reflect the given triangle about X=Y.
(iv) Scale the given triangle uniformly by 2 units.
Ans: N.A
(b) What is significance of modelling in virtual reality? Explain any modelling
technique used in virtual reality).
Ans:
Real-Life Situations
Virtual reality modeling is used to create interactive scenarios which reflect real-life
situations. Virtual reality e-learning can be used to simulate the way equipment
responds; emulate the way machinery works or to replicate soft skills such as human
actions and behaviour. Anything is possible; just let your imagination go wild!
Making Learning Fun and Interesting
As a child you watched, listened and played. You were intrigued by colours, shapes
and sounds and the only way you found out how something worked was by playing
and using it. Virtual reality simulations use these basic principles of learning to
produce fun, compelling and memorable end results. We engage the user with
breathtaking graphics, informative audio and interactive scenarios using our 3D
virtual environments to give a sense of really being there.
Save on Cost
Do you have limited training resources, equipment that is scarce or expensive, too
many people to train at one time? If some of these limitations apply to you then using
virtual reality could be a perfect solution for your needs.
Mumbai University I.T (Semester V)
19 |www.brainheaters.in
By modelling your equipment, possibly down to the last detail you could distribute a
training programme to all your employees or learners that will allow them to interact
with it, follow best practice procedures or carry out fault finding scenarios, all
without having to access (and possibly damage) the real item.
Complex Situations Made Easy
Complicated pieces of equipment, processes or systems can be recreated using a
number of techniques. This form of e-learning allows users to learn about
mechanisms and processes that would be physically or logistically difficult to do so
in other conditions.
A Safe Environment
There are some occasions when training your staff is expensive and it can sometimes
be hazardous, with real risk of personal injury or damage to expensive equipment.
One can develop highly interactive, virtual reality environments to help with these
issues. By creating an environment which simulates a potentially harmful real-life
situation or replicating a piece of dangerous equipment, Sinteractive scenarios
remove these concerns and help the user gain a knowledge and understanding of the
subject matter without being put into a costly or harmful environment.
Q6)
(a) Homogeneous Coordinates
Ans:
In general, when you want to perform a complex transformation, you usually make it
by combining a number of basic transformations. The above equation for q, however,
is awkward to read because scaling is done by matrix multiplication and translation is
done by vector addition. In order to represent all transformations in the same form,
computer scientists have devised what are called homogeneous coordinates. Do not
try to apply any exotic interpretation to them. They are simply a mathematical trick to
make the representation be more consistent and easier to use.
Homogeneous coordinates (HC) add an extra virtual dimension. Thus 2D HC are
actually 3D and 3D HC are 4D. Consider a 2D point p = (x,y). In HC, we represent p
as p = (x,y,1). An extra coordinate is added whose value is always 1. This may seem
odd but it allows us to now represent translations as matrix multiplication instead of
Mumbai University I.T (Semester V)
20 |www.brainheaters.in
as vector addition. A translation (dx, dy) which would normally be performed as q =
(x,y) + (dx, dy) now is written as
q = T p = =
Now, we can write the scaling about a fixed point as simply a matrix multiplication:
q = (-T) S T p = A p,
where A = (-T) S T
The matrix A can be calculated once and then applied to all the points in the object.
This is much more efficient than our previous representation. It is also easier to
identify the transformations and their order when everything is in the form of matrix
multiplication.
The matrix for scaling in HC is
S =
and the matrix for rotation is
R =
(b) Text Clipping
Ans:
Various techniques are used to provide text clipping in a computer graphics. It
depends on the methods used to generate characters and the requirements of a
particular application. There are three methods for text clipping which are listed
below −
All or none string clipping
All or none character clipping
Mumbai University I.T (Semester V)
21 |www.brainheaters.in
Text clipping
The following figure shows all or none string clipping −
In all or none string clipping method, either we keep the entire string or we reject
entire string based on the clipping window. As shown in the above figure, STRING2
is entirely inside the clipping window so we keep it and STRING1 being only
partially inside the window, we reject.
The following figure shows all or none character clipping −
This clipping method is based on characters rather than entire string. In this method if
the string is entirely inside the clipping window, then we keep it. If it is partially
outside the window, then −
You reject only the portion of the string being outside
If the character is on the boundary of the clipping window, then we discard that
entire character and keep the rest string.
The following figure shows text clipping −
Mumbai University I.T (Semester V)
22 |www.brainheaters.in
This clipping method is based on characters rather than the entire string. In this
method if the string is entirely inside the clipping window, then we keep it. If it is
partially outside the window, then
You reject only the portion of string being outside.
If the character is on the boundary of the clipping window, then we discard
only that portion of character that is outside of the clipping window.
(c) Fractals
Ans:
Fractals are very complex pictures generated by a computer from a single formula.
They are created using iterations. This means one formula is repeated with slightly
different values over and over again, taking into account the results from the previous
iteration.
Fractals are used in many areas such as −
Astronomy − For analyzing galaxies, rings of Saturn, etc.
Biology/Chemistry − For depicting bacteria cultures, Chemical reactions,
human anatomy, molecules, plants,
Others − For depicting clouds, coastline and borderlines, data compression,
diffusion, economy, fractal art, fractal music, landscapes, special effect, etc.
Generation of Fractals
Fractals can be generated by repeating the same shape over and over again as shown
in the following figure. In figure (a) shows an equilateral triangle. In figure (b), we
Mumbai University I.T (Semester V)
23 |www.brainheaters.in
can see that the triangle is repeated to create a star-like shape. In figure (c), we can
see that the star shape in figure (b) is repeated again and again to create a new shape.
We can do unlimited number of iteration to create a desired shape. In programming
terms, recursion is used to create such shapes.
Geometric Fractals
Geometric fractals deal with shapes found in nature that have non-integer or fractal
dimensions. To geometrically construct a deterministic (nonrandom) self-similar
fractal, we start with a given geometric shape, called the initiator. Subparts of the
initiator are then replaced with a pattern, called the generator.
As an example, if we use the initiator and generator shown in the above figure, we
can construct good pattern by repeating it. Each straight-line segment in the initiator
is replaced with four equal-length line segments at each step. The scaling factor is
1/3, so the fractal dimension is D = ln 4/ln 3 ≈ 1.2619.
Also, the length of each line segment in the initiator increases by a factor of 4/3 at
each step, so that the length of the fractal curve tends to infinity as more detail is
added to the curve as shown in the following figure −
Mumbai University I.T (Semester V)
24 |www.brainheaters.in
(d) B-Spline Curves
Ans:
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,
k (t) given by
C(t)=∑ni=0PiNi,k(t),
n≥k−1, tϵ[tk−1,tn+1]
Mumbai University I.T (Semester V)
25 |www.brainheaters.in
Where,
{pi
: 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)
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+K
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.
The degree of B-spline polynomial is independent on the number of vertices of
defining polygon.
B-spline allows the local control over the curve surface because each vertex
affects the shape of a curve only over a range of parameter values where its
associated basis function is nonzero.
The curve exhibits the variation diminishing property.
The curve generally follows the shape of defining polygon.
Any affine transformation can be applied to the curve by applying it to the
vertices of defining polygon.
The curve line within the convex hull of its defining polygon.
Mumbai University I.T (Semester V)
26 |www.brainheaters.in
(e) Morphing and wraping
Ans:
Morphing
Morphing is a familiar technology to produce special effects in image or videos.
Morphing is common in entertainment industry. Morphing is widely used in movies,
animation games etc. In addition to the usage of entertainment industry, morphing
can be used in computer based trainings, electronic book illustrations, presentations,
education purposes etc. morphing software is widely available in internet.
Animation industry looking for advanced technology to produce special effects on
their movies. Increasing customers of animation industry does not satisfy with the
movies with simple animation. Here comes the significance of morphing.
The Word "Morphing" comes from the word "metamorphosis" which means change
shape, appearance or form. Morphing is done by coupling image warping with colour
interpolation. Morphing is the process in which the source image is gradually
Mumbai University I.T (Semester V)
27 |www.brainheaters.in
distorted and vanished while producing the target image. So earlier images in the
sequence are similar to source image and last images are similar to target image.
Middle image of the sequence is the average of the source image and the target
image.
Morphing techniques may be classified into two based on the ways to specify their
features. They are mesh based methods and feature based methods. In mesh based
methods, features of the image specified by a non uniform mesh. Feature based
methods, features of the image specifies as line segment or a set of points. Feature
based methods are popular.
Warping:
A warp is a 2-D geometric transformation and generates a distorted image when it is applied to an image. Warping an image means : apply a given deformation to it. Two ways to warp an image:- Some pixels in the destination image may not be mapped. Each pixel in source image is mapped to an appropriate pixel in destination image.
This method goes through each pixel in the destination image and samples an appropriate source image pixel. All destination image pixels are mapped to some source image pixel. This mapping is used in the Beier/Neely line morphing method.