22318-2019-Winter-model-answer-paper[Msbte study resources]_organized
22318-2019-Winter-model-answer-paper[Msbte study resources]_organized
22318-2019-Winter-model-answer-paper[Msbte study resources]_organized
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
WINTER – 19 EXAMINATION
Subject Name: Computer Graphics Model Answer Subject Code: 22318
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in
the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner
may try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components
indicated in the figure. The figures drawn by candidate and model answer may vary.
The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed
constant values may vary and there may be some difference in the candidate’s
answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of
relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based
on equivalent concept.
OR
Page 3 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Step 4 : Fill all those pair of coordinates that are inside polygons and
ignore the alternate pairs.
c Write 2D and 3D scaling matrix. 4M
Ans 2D Scaling 2D matrix: 2
Scaling means to change the size of object. This change can either be M,
positive or negative. 3D matrix: 2 M
To change the size of an object, scaling transformation is used. In the
scaling process, you either expand or compress the dimensions of the
object.
Scaling can be achieved by multiplying the original co-ordinates of
the object with the scaling factor to get the desired result.
Let us assume that the original co-ordinates are (X, Y), the scaling
factors are (SX, SY), and the produced co-ordinates are (X', Y'). This
can be mathematically represented as shown below:
o X' = X SX and Y' = Y SY
The scaling factor SX, SY scales the object in X and Y direction
respectively. The above equations can also be represented in matrix
form as below:
X' X Sx 0
=
Y' Y 0 Sy
OR
P'
=P S
Where, S is the scaling matrix.
The scaling process is shown in the Fig
Page 7 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 4 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
It specifies three co-ordinates with their own scaling factors. If scale factors,
Sx = Sy = Sz = S > 1 then the scaling is called as magnification.
Sx = Sy = Sz = S < 1 then the scaling is called as reduction.
Therefore, point after scaling with respect to origin can be calculated as,
P=P . S
d Explain midpoint subdivision line clipping algorithm. 4M
Ans Step 1: Scan two end points for the line P1(x1, y1) and P2(x2, y2). Algorithm: 4 M
Step 2: Scan corners for the window as (Wx1, Wy1) and (Wx2, Wy2).
Step 3: Assign the region codes for endpoints P1 and P2 by initializing code
with
0000.
Bit 1 - if (x < Wx1)
Bit 2 - if (x > Wx2)
Bit 3 - if (y < Wy1)
Bit 4 - if (y > Wy2)
Step 4: Check for visibility of line P1, P2.
If region codes for both end points are zero then the line is visible,
draw it and jump to step 6.
If region codes for end points are not zero and the logical Anding
operation of them is also not zero then the line is invisible, reject it
and jump to step 6.
If region codes for end points does not satisfies the condition in 4 (i)
and 4 (ii) then line is partly visible.
Step5: Find midpoint of line and divide it into two equal line segments and
repeat
steps 3 through 5 for both subdivided line segments until you get completely
visible and completely invisible line segments.
Step 6: Exit.
e Explain interpolation techniques in curve generation. 4M
Ans Specify a spline curve by giving a set of coordinate positions, called control Diagram: 2 M,
points, which indicates the general shape of the curve These, control points Explanation: 2
are then fitted with piecewise continuous parametric polynomial functions in M
one of two ways. When polynomial sections are fitted so that the curve passes
through each control point, the resulting curve is said to interpolate the set of
control points. On the other hand, when the polynomials are fitted to the
general control -point path without necessarily passing through any control
point, the resulting curve is said to approximate the set of control points
interpolation curves are commonly used to digitize drawings or to specify
animation paths. Approximation curves are primarily used as design tools to
Page 6 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Picture definition is stored in a memory area called the refresh buffer
or frame buffer. This memory area holds the set of intensity values
for all the screen points. The stored intensity values are then retrieved
from frame buffer and painted on the screenone row at a time. Each
screen point is referred as Pixel orpel. Each pixel on the screen can be
specified by it row and column number.
Intensity range for pixel position depends on capability of the raster
system. In black and white system, the point on screen is either on or
off. Only one bit is needed to control the intensity of the screen. In
case of color systems, 2 bits are requiredOne to represent ON (1),
another one is OFF (0).
Refreshing on raster scan is carried out at the rate of 60 to 80 frames
per seconds.
The video or display controller has direct access to memory locations
in the frame buffer. It is responsible for retrieving data from the frame
buffer and passing it to the display device. It reads bytes of data from
frame buffer and converts 0’s and 1’s in one line into its
corresponding video signals and this is called a scan line. If the
intensity is one (1) then controller sends a signal to display a dot in
the corresponding position on the screen. If the intensity is zero (0)
then no dot is displayed.
b Write procedure to fill polygon with flood fill. 4M
Ans flood_fill(x,y,old_color,new_color) Correct
procedure: 4 M
{
if(getpixel(x,y) = old_color)
{
putpixel(x,y,new_color);
flood_fill(x+1,y,old_color, new_color);
flood_fill(x-1,y,old_color, new_color);
flood_fill(x,y+1,old_color, new_color);
flood_fill(x,y-1,old_color, new_color);
flood_fill(x+1,y+1,old_color, new_color);
flood_fill(x-1,y-1,old_color, new_color);
flood_fill(x+1,y-1,old_color, new_color);
flood_fill(x-1,y+1,old_color, new_color);
Page 9 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
The pair (tx, ty) is called the translation vector or shift vector. The above
equations can also be represented using the column vectors.
Rotation
Rotation as the name suggests is to rotate a point about an axis.
The axis can be any of the co-ordinates or simply any other
specified line also.
In rotation, we rotate the object at particular angle θ (theta) from
its origin. From the following figure, we can see that the point
P(X, Y) is located at angle φ from the horizontal X coordinate
with distance r from the origin.
Let us, suppose you want to rotate it at the angle θ. After rotating
it to a new location, you will get a new point P' (X', Y').
Same way we can represent the point P' (X', Y') as:
x′ = r cos (ф + θ) = r cos ф cos θ − r sin ф sin θ (3)
y′ = r sin (ф + θ) = r cos ф sin θ + r sin ф cos θ (4)
Substituting equation (1) and (2) in (3) and (4) respectively, we will get
x′ = x cos θ − y sin θ
y′ = x sin θ + y cos θ
Representing the above equation in matrix form,
Page 11 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
If we provide values less than 1 to the scaling factor S, then we can reduce
the size of the object. If we provide values greater than 1, then we can increase
the size of the object.
d Explain Koch curve with diagram. 4M
Ans Koch Curve: - In Koch curve, begin at a line segment. Divide it into third Explanation: 2
and replace the center by the two adjacent sides of an equilateral triangle as M,
shown below. This will give the curve which starts and ends at same place as Diagram: 2 M
the original segment but is built of 4 equal length segments, with each 1/3rd
of the original length. So the new curve has 4/3 the length of original
segments. Repeat same process for each of the 4 segment which will give
curve more wiggles and its length become 16/9 times the original. Suppose
repeating the replacements indefinitely, since each repetition increases the
length by a factor of 4/3, the length of the curve will be infinite but it is folded
in lots of tiny
Page 13 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
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.
There are two methods by which we can identify whether particular point is
inside an object or outside namely, Odd-Even Rule, and Non-zero winding
number rule.
1. Odd-Even Rule:
In this technique, we count the edge crossing along the line from any point
(x, y) to infinity. If the number of interactions is odd then the point (x, y) is
an interior point. If the number of interactions is even then point (x, y) is an
exterior point.
Here is the example to give you the clear idea,
Page 15 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Scaling:
Scaling means to change the size of object. This change can either be positive
or negative.
To change the size of an object, scaling transformation is used. In the scaling
process, you either expand or compress the dimensions of the object.
Scaling can be achieved by multiplying the original co-ordinates of the object
with the scaling factor to get the desired result.
Let us assume that the original co-ordinates are (X, Y), the scaling factors are
(SX, SY), and the produced co-ordinates are (X', Y'). This can be
mathematically represented as shown below:
Page 12 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
}
}
1)Translation
2)Scaling
3)Rotation
1)Translation:
A translation is applied to an object by repositioning it along a
straight-line path from one coordinate location to another.
Translation refers to the shifting (moving) of a point to some other
place, whose distance with regard to the present point is known.
Translation can be defined as “the process of repositioning an
object along a straight line path from one co-ordinate location to
new co-ordinate location.”
A translation moves an object to a different position on the screen.
You can translate a point in 2D by adding translation coordinate
(tx, ty) to the original coordinate (X, Y) to get the new coordinate
(X', Y')
Page 10 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
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 the total
number of interaction point is 8, which is odd. Hence, the point is
considered within the object.
Page 16 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
3) Text 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.
Page 14 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
In another alternative method, give directions to all the edges of the polygon.
Draw a scan line from the point to be test towards the left most of X direction.
Given the value 1 to all the edges which are going to upward direction and
all other – 1 as direction values.
Check the edge direction values from which the scan line is passing and sum
up them.
If the total sum of this direction value is non-zero, then this point to be tested
is an interior point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the scan line
is passing then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is
said to be an interior point.
b Explain composite transformation over arbitrary point. 4M
Ans To do rotation of an object about any selected arbitrary point P1(x1 ,y1), Explanation: 2
following sequence of operations shall be performed. M,
1. Translate: Matrix: 1 M,
Translate an object so that arbitrary point P1 is moved to coordinate Diagram: 1M
origin.
2. Rotate:
Rotate object about origin.
3. Translate:
Translate object so that arbitrary point P1 is moved back to the its
original position.
Rotate about point P1(x1,y1).
1) Translate P1 to origin.
2) Rotate
3) Translate back to P1.
Equation for this composite transformation matrix form is as follows:
Page 17 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
First Line
2M,Second
Line 2M
Page 19 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 21 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 23 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 20 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Here (x1,y1) are coordinates of point P1 and hence are translation factors tx
and ty; we want to move P1 to origin , x1 and y1 are x and y distances to
P1and hence it is translation factor.
Page 18 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
OR
Page 22 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
√3 1
1 0 1 2 0
2
A’B’C’]=[ABC]. R30° =[0 1 1] 1 √3 =
−2 0
1 1 1 2
[0 0 1]
0.866025 −0.5 0
[ 0.5 0.866025 0]
1.36603 0.366025 1
ii. Translating one unit x and y direction and then rotate 45°
about origin.
Points A, B and C, 𝜃= 45° and about points are (1,1)
tx = 1;
ty = 1;
for rotation about arbitrary point we followed sequence of operation
as
Translation -> Rotation about origin -> Retranslation
1 1
− 0
𝑥′ 1 0 1 √2 √2 1 0 −1 1 0 1
[𝑦 ′ ] = [0 1 1 ] 1 1 [0 1 −1] [0 1 1]
𝑧′ 0 0 1 √2 √2 0 0 0 1 1 1 1
[0 0 1]
1 1
− 1
𝑥′ √2 √2 1 0 −1 1 0 1
[𝑦 ′ ] = 1 1 [0 1 −1] [0 1 1]
1 0 0 1 1 1 1
𝑧′ √2 √2
[0 0 1]
1 1
− 1
𝑥′ √2 √2 1 0 1
[𝑦 ′ ] = 1 1 2 [0 1 1 ]
− − +1 1 1 1
𝑧′ √2 √2 √2
[ 0 0 1 ]
1 1
− +1 +1 1
𝑥′ √2 √2
[𝑦 ′ ] = 1 1 4
′ − − +3
𝑧 √2 √2 √2
[ 1 1 1 ]
Page 25 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 27 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
3) Starbust method:
In this method a fix pattern of line segments are used to generate characters.
Out of these 24 line segments, segments required to display for particular
character are highlighted. This method of character generation is called
starbust method because of its characteristic appearance
The starbust patterns for characters A and M. the patterns for particular
characters are stored in the form of 24 bit code, each bit representing one
line segment. The bit is set to one to highlight the line segment; otherwise
it is set to zero. For example, 24-bit code for Character A is 0011 0000
0011 1100 1110 0001 and for
character M is 0000 0011 0000 1100 1111 0011.
This method of character generation has some disadvantages. They are
1. The 24-bits are required to represent a character. Hence more memory
is required.
2. Requires code conversion software to display character from its 24-
bitcode.
3. Character quality is poor. It is worst for curve shaped characters.
Page 29 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
• Then we can distinguish in which region a point lie by looking at the value
of the dot product
n.[P(t) – f ], as shown in Fig.
• If dot product is negative i.e.,
n.[P(t) – f ] < 0 … (2)
then the vector P(t) – f ] is pointed away from the interior of R.
• If dot product is zero i.e.,
n.[P(t) – f ] = 0 … (3)
then the vector P(t) – f ] is pointed parallel to the plane containing f and
perpendicular to the normal.
• If dot product is positive i.e.,
n.[P(t) – f ] > 0 … (4)
Page 31 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Line drawing algorithm DDA follows this method for line drawing.
This method uses small line segments to generate a character. The small
series of line segments are drawn like a stroke of pen to form a
character.
We can build our own stroke method character generator by calls to the
line drawing algorithm. Here it is necessary to decide which line
segments are needed for each character and then drawing these
segments using line drawing algorithm.
2)BITMAP METHOD
Bitmap method is a called dot-matrix method as the name suggests this
method use array of bits for generating a character. These dots are the
points for array whose size is fixed.
In bit matrix method when the dots is stored in the form of array the
value 1 in array represent the characters i.e. where the dots appear
we represent that position with numerical value 1 and the value where
dots are not present is represented by 0 in array.
It is also called dot matrix because in this method characters are
represented by an array of dots in the matrix form. It is a two
dimensional array having columns and rows.
A 5x7 array is commonly used to represent characters. However 7x9 and
9x13 arrays are also used. Higher resolution devices such as inkjet printer or
laser printer may use character arrays that are over 100x100.
Page 28 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
#define N 32
#define K 3
#define MAX N * K
int main(){
int d, x, y, cx, cy, px, py;
char pts[MAX][MAX];
point curr, prev;
for(x = 0; x < MAX; ++x)
Page 26 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Dot products for three points inside, outside and on the boundary of the
clipping region
• As shown in Fig. if the point f lies in the boundary plane or edge for which
n is the inner normal, then that point t on the line P(t) which satisfies,
n.[P(t) – f ] = 0 condition is the intersection of the line with the
boundary edge.
• To get the formal statement of the Cyrus-Beck algorithm we substitute
value of P(t) in equation 3.
n . [P(t) – f ] = n . [P1 + (P2 – P1)t – f ] = 0 … (5)
• The relation should be applied for each boundary plane or edge of the
window to get the intersection points. Thus in general form equation (5) can
be written as,
ni . [P1 + (P2 – P1)t – fi ] = 0 … (6)
where, i is edge number.
• Solving equation (6) we get,
ni . [P1 – fi ] + ni . (P2 –P1)t = 0 … (7)
• Here the vector P2 – P1 defines the direction of the line. The direction of
the line is important to correctly identify the visibility of the line. The vector
P1 - fi is proportional to the distance from the
end point of the line to the boundary point.
• Let us define,
D = P2 – P1 as the direction of a line and
Wi = P1 – fi as weighting factor.
• Substituting newly defined variable D and Wi in Equation (7) we get,
ni.Wi + (ni . D)t = 0 … (8)
Page 32 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 30 | 3 3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Page 33 | 3 3