I Internal Examination 2017-18 (Model Paper) B.Tech III Year VI semester, Computer Science & Engineering Subject: 6CS4 Computer Graphics & Multimedia Technology Time: 1:30 Hr M.M:40 Question No. Question Marks CO Mapped Q.1(a) Solution Q.1(b) Solution Unit-1 In a raster system with resolution 2048*1280. Calculate the number of pixels could be accessed per second by a display controller that refreshes at rate of 50 frames per second. Also calculate the access time per pixel in the system. Resolution : 2048 * 1280 = 2621440 Since controller can access 50 frames in one second Therefore, total no. of pixels accessed = 50 * 2621440 = 131072000 per sec Access time / Pixel = 1 / total pixels accessed per sec = 1 / 131072000 = 7.62 * e-9 per sec Explain DDA s line drawing algorithm. A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line. In the following three algorithms, we refer the one point of line as X0,Y0 and the second point of line as X1,Y1. DDA Algorithm Digital Differential Analyzer (DDA) algorithm is the simple line generation algorithm which is explained step by step here. Step 1 Get the input of two end points (X0,Y0) and (X1,Y1). Step 2 Calculate the difference between two end points. dx = X1 - X0 dy = Y1 - Y0 Step 3 Based on the calculated difference in step-2, you need to identify the number of steps to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate. 06 CO364.1 10 CO364.1 if (absolute(dx) > absolute(dy)) Steps = absolute(dx); else Steps = absolute(dy); Step 4 Calculate the increment in x coordinate and y coordinate. Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps; Step 5 Put the pixel by successfully incrementing x and y coordinates accordingly and complete the drawing of the line. Q.1(a) Solution for(int v=0; v < Steps; v++) { } x = x + Xincrement; y = y + Yincrement; putpixel(round(x), Round(y)); OR Part Discuss anti aliasing briefly. Explain various methods used to develop anti-aliasing routines. Aliasing: 1. A problem with high resolution texturing is aliasing, which occurs when adjacent pixels in a rendered image are sampled from pixels that are far apart in a texture image. 2. By down-sampling reducing the size of a texture aliasing can be reduced for far away or small objects, but then textured objects look blurry when close to the viewer. 3. What we really want is a high resolution texture for nearby viewing, and downsampled textures for distant viewing. 4. A technique called mip-mapping gives us this by pre-rendering a texture image at several different scales. 5. For example, a 256 256 image might be down-sampled to 128 128, 64 64, 32 32, 16 16, and so on. 6. Then it is up to the renderer to select the correct mipmap to reduce aliasing artifacts at the scale of the rendered texture. 06 CO364.1 1. An aliased high resolution texture image (left) and the same texture after mipmapping (right). Anti-aliasing:
Drawing a circle on the screen is a little complex than drawing a line. There are two 1. Antialiasing is a term for techniques that are designed to mitigate the effects of aliasing. 2. The idea is that when a pixel is only partially covered by a shape, the color of the pixel should bea mixture of the color of the shape and the color of the background. 3. When drawing a black lineon a white background, the color of a partially covered pixel would be gray, with the shade ofgray depending on the fraction of the pixel that is covered by the line. 4. Here, for example, is a geometric line, shown on the left, along with two approximations of thatline made by coloring pixels. The lines are greatly magnified so that you can see the individualpixels. 5. The line on the right is drawn using antialiasing, while the one in the middle is not: 1. Note that antialiasing does not give a perfect image, but it can reduce the jaggies that are caused by aliasing. Methods of Anti-aliasing: Basically, there are only three main methods of anti-aliasing: Super-sampling Multisampling Post-Processing Post-Processing Postfiltering, also known as super sampling is the more popular approach to antialiasing. For each displayed pixel, a postfiltering method takes several samples from the scene and computes an average of the samples to determine the pixel's color. The two steps in the postfiltering process are: o Sample the scene at n times the display resolution. For example, suppose the display resolution is 512 512. Sampling at three times the width and three times the height of the display resolution would yield 1536 1536 samples. The color of each pixel in the rendered image will be an average of several samples. For example, if sampling were performed at three times the width and three times the height of the display resolution, then a pixel's color would be an average of nine samples. A filter provides the weights used to compute the average. Q.1(b) Write Mid Point Circle drawing algorithm and show how it draws a circle whose radius is 4 and centred at origin. 10 CO364.1
Solution popular algorithms for generating a circle Bresenham s Algorithmand 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 The equation of circle is X2+Y2=r2, where r is radius. Mid Point Algorithm Step 1 Input radius r and circle center (xc,yc)(xc,yc) and obtain the first point on the circumference of the circle centered on the origin as (x0, y0) = (0, r) Step 2 Calculate the initial value of decision parameter as P0P0 = 5/4 r (See the following description for simplification of this equation.) f(x, y) = x2 + y2 - r2 = 0 f(xi - 1/2 + e, yi + 1) = (xi - 1/2 + e)2 + (yi + 1)2 - r2 = (xi- 1/2)2 + (yi + 1)2 - r2 + 2(xi - 1/2)e + e2 = f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0
Let di = f(xi - 1/2, yi + 1) = -2(xi - 1/2)e - e2 Thus, If e < 0 then di > 0 so choose point S = (xi - 1, yi + 1). di+1 = f(xi - 1-1/2, yi + 1 + 1) = ((xi - 1/2) - 1)2 + ((yi + 1) + 1)2 - r2 = di - 2(xi - 1) + 2(yi + 1) + 1 = di + 2(yi + 1 - xi + 1) + 1 If e >= 0 then di <= 0 so choose point T = (xi, yi + 1) di+1 = f(xi - 1/2, yi + 1 + 1) = di + 2yi+1 + 1 The initial value of di is d0 = f(r - 1/2, 0 + 1) = (r - 1/2)2 + 12 - r2 = 5/4 - r {1-r can be used if r is an integer}
When point S = (xi - 1, yi + 1) is chosen then di+1 = di + -2xi+1 + 2yi+1 + 1 When point T = (xi, yi + 1) is chosen then di+1 = di + 2yi+1 + 1 Step 3 At each XKXK position starting at K=0, perform the following test If PK < 0 then next point on circle (0,0) is (XK+1,YK) and PK+1 = PK + 2XK+1 + 1 Else PK+1 = PK + 2XK+1 + 1 2YK+1 Where, 2XK+1 = 2XK+2 and 2YK+1 = 2YK-2. 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 (XC,YC)(XC,YC) and plot the coordinate values. X = X + XC, Y = Y + YC Step 6 Repeat step-3 through 5 until X >= Y. Draw a circle whose radius is 4 and centred at origin Solution: r = 4 The initial point (x, y) = (0,4) Calculate the initial decision parameters p = 1.25 4 = -3 P = -3 < 0 First Plot (0,4) Here p<0 so X = 0+1 =1 Y = 4 P = p+2x+1 = -3+2*1+1 = -3+2+1=0 x<y i.e., 1<4 & p>=0 So plot (1,4) x = 1+1 =2 y = 4-1 = 3 p = p + 2x-2y+1 = 0 + 2*2-2*3+1= 0+4-6+1 = -1 x<y and p<0 so plot (2,3)
x = 2+1=3 y=3 p = -1+2*3+1 = 6 Plot(3,3) Unit-2 Q.2 Solution Explain basic principle to draw a eclipse. Also explain mid-point eclipse algorithm. An ellipse is a set of points such that the sum of the distances from two fixed positions (foci) is the same for all points.if the distances to any two foci from any point P=(x,y) on the ellipse are labeled d1 and d2 then the general equation of an an ellipse can be stated as d1 + d2 is constant. An ellipse in standard position is symmetric between quadrants. But it not symmetric between the two octants of the quadrant. So, we must calculate the pixel positions along the elliptical arc throughout one quadrant, then we obtained positions in the remaining three quadrants by symmetry. Midpoint Ellipse Algorithm In Mathematical term, d1 + d2 = constant For an ellipse with center point (h,k), the standard rectangular expression can be written as { (x-h)/a }2 + { (y-k)/b }2 = 1 So, lets assume a ellipse with center at origin ((h,k)= (0,0)), having major and minor axis a and b respectively, By putting all this value in above equation, we get (x/a)2 + (y/b)2 = 1 On solving: (x/a)2 + (y/b)2-1 = 0 In first region, the equation will be: f(x, y) = a2x2 + b2y2 - a2b2 The mid points will be F(Xmid, Ymid) = (Xk+1, Yk 1/2) having following properties: F(Xmid, Ymid) < 0, when midpoints will lie inside the ellipse boundary. F(Xmid, Ymid) = 0, when midpoints will lie on ellipse boundary. F(Xmid, Ymid) > 0, when midpoints will lie outside the ellipse boundary. Now, put this midpoints value in first region equation: F(Xmid, Ymid) = b2(xk+1)2 + a2(yk - 1/2)2 a2b2 16 CO364.1
On solving: P k = b2(xk+1)2 + a2(yk2 + ¼ - Yk) a2b2 P k = b2(xk2 + 1 + 2Xk) + a2(yk2 + ¼ -Yk) a2b2 and P k+1 = b2(xk+12 + 1 + 2Xk+1) + a2(yk+12 + ¼ -Yk+1) a2b2 Initial decision parameter of Region-1 is (0, b), hence putting this value in above equation: P o=b2(0+1+0) + a2(b2 + ¼ -b) a2b2 P o = b2 + a2b2 + a2/4 a2b a2b2 P o= b2 + a2/4 a2b P o= a2/4 a2b + b2 This is the initial decision parameter of region 1. Now, substracting P'k from P'k+1 P k+1 P k = b2(xk+12 X2k) +2b2(Xk+1-Xk) + a2(yk+12 Yk2) + a2(yk+1 - Yk) P k+1 P k = b2(xk+1 Xk)(Xk+1 + Xk) +2b2(Xk+1-Xk) + a2(yk+1 Yk)(Yk+1 + Yk) -a2(yk+1 - Yk) If P is negative: Xk+1 Xk = 1 Yk+1 Yk = 0 hence P k+1 = P k + 2b2 Xk+1 + b2 This is the decision parameter for less than zero of region 1. If P is positive: Xk+1 Xk = 1 Yk+1 Yk = -1 hence P k+1 = P k +b2(xk+1 + Xk) + 2b2 + a2(-1)(yk+1 + Yk) a2(-1) P k+1 = P k + 2b2 Xk+1 + b2 2a2 Yk+1 This is the decision parameter for greater than zero of region 1 Over Region R2 Now lets solve the derivation for region 2 F(X,Y) = b2x2 + a2y2 a2b2 F(Xmid, Ymid) = (Xk+1/2, Yk 1) F(Xmid, Ymid) = b2(xk + 1/2)2 + a2(yk - 1)2 a2b2
hence P k = b2(xk + 1/2)2 + a2(yk - 1)2 a2b2 P k = b2(x2k + 1/4 + Xk) + a2(y2k + 1-2Yk) a2b2 P k+1 = b2(xk+12 + 1/4 + Xk+1) + a2(yk+12 + 1-2Yk+1) a2b2 Initial decision parameter of Region R2 (X0, Y0): P 0 = b2(x0 + 1/2)2 + a2( Y0-1)2 a2b2 This is the initial decision parameter of region R2. Now, substracting P'k from P'k+1: P k+1 P k = b2(x2k+1 Xk2) +b2(xk+1 - Xk) + a2(yk+12 Y2k) -2a2(Yk+1 - Yk) P k+1 P k = b2(xk+1 Xk)(Xk+1 + Xk) +b2(xk+1-xk) + a2(yk+1 Yk)(Yk+1 + Yk) - 2a2(Yk+1 - Yk) If P is positive: Xk+1 Xk = 0 Yk+1 Yk = -1 Hence P k+1 = P k 2a2 Yk+1 + a2 This is the decision parameter for greater than zero of region 2. If P is negative: Xk+1 Xk = 1 Yk+1 Yk = -1 Hence P k+1 = P k + 2b2 Xk+1-2a2 Yk+1 + a2 This is the decision parameter for less than zero of region 2. Algorithm 1.Input rx,ry and ellipse center (xc,yc) and obtain the first point on an ellipse centered on the origin as (x0,y0)=(0,ry) 2.Calculate the initial value of the decision parameter in region 1 as p10 = r2y-r2xry + ¼ r2x 3.At each xk position in region 1,starting at k=0,perform the following test if p1k<0, the next point along the ellipse centered on (0,0)is (xk+1,yk) otherwise the next point along the circle is (xk+1,yk-1) and p1k+1 = p1k + 2r2yxk+1 2r2yxk+1 + r2y with 2r2yxk+1 = 2r2yxk + 2r2y 2r2xyk-2r2xyk 2r2x
Q.2(a) 4.Calculate the initial value of the decision parameter in region 2 using the last point (x0,y0) calculated in region as p20 = r2y (x0+1/2)2 + r2x(y0-1)2-r2xr2y 5.At each yk position in region2 starting at k=0,perform the following test if p2k>0 the next point along the ellipse centered on (0,0) is (xk,yk-1) and p2k+1=p2k-2r2xyk+1 + r2x otherwise the next point along the circle is (xk+1,yk-1) and p2k+1 = p2k + 2r2yxk+1 2r2xyk+1 +r2x using the same incremental calculations for x and y as in region1 6.Determine symmetry points in the other three quadrants. 7.Move each calculated pixel position (x,y) onto the elliptical path centered on (xc,yc) and plot the coordinate values. X=x+xc,y=y+yc 8.Repeat the steps for region1 until 2r2yx > = 2r2xy OR Part Explain the need of homogeneous coordinate? Prove that two successive scaling are multiplicative. 08 CO364.2 Solution 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 P(X, Y) can be converted to homogenous coordinates by P (Xh, Yh, h). Composite Transformation If a transformation of the plane T1 is followed by a second plane transformation T2, then the result itself may be represented by a single transformation T which is the composition of T1 and T2 taken in that order. This is written as T = T1 T2. Composite transformation can be achieved by concatenation of transformation matrices to obtain a combined transformation matrix.
A combined matrix [T][X] = [X] [T1] [T2] [T3] [T4]. [Tn] Where [Ti] is any combination of Translation Scaling Shearing Rotation Reflection The change in the order of transformation would lead to different results, as in general matrix multiplication is not cumulative, that is [A]. [B] [B]. [A] and the order of multiplication. The basic purpose of composing transformations is to gain efficiency by applying a single composed transformation to a point, rather than applying a series of transformation, one after another. For example, to rotate an object about an arbitrary point (Xp, Yp), we have to carry out three steps Translate point (Xp, Yp) to the origin. Rotate it about the origin. Translations Finally, translate the center of rotation back where it belonged. Two successive translations of an object can be carried out by first concatenating the translations matrices, then applying the composite matrix to the coordinate points. Specifying the two successive translation distances as (Tx1, Ty1) and (Tx2, Ty2), we calculate the composite matrix as Which demonstrates that two successive translations are additive. Scalings Concatenating transformation matrices for two successive scaling operations produces the following composite scaling matrix: S(Sx1, Sy1). S(Sx2, Sy2) = S(Sx1.Sx2, Sy1.Sy2) The resulting matrix in this case indicates that successive scaling operations are multiplicative. That is, if we were to triple the size of an object twice in succession, the final size would be nine times that of the original. Rotations The composite matrix for two successive rotations is calculated as
R(θ1). R(θ2) = R(θ1 + θ2) Using the trigonometric identities for the sine and cosine of the sum of two angles, we can express the elements of the product matrix for two successive rotations in the xy plane about the coordinate origin as Q.2(b) As is the case with translations, successive rotations are additive. Translate a square ABCD with the coordinated A(0,0), B(3,0), C(3,3,), D(0,3) by 2 units in both directions and then scale it by 1.5 units in X-direction and 0.5 Units in Y direction. 08 CO364.2 Solution
Q.3 Solution Unit-3 Differentiate 4-Connected area filling approach from 8-Connected approach. 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. 08 CO364.2 Algorithm Step 1 Initialize the value of seed point (seedx, seedy), fcolor and bcol. 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)!= bcol && getpixel(x, y)!= fcolor 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. BoundaryFill (seedx 1, seedy, fcol, dcol) BoundaryFill (seedx + 1, seedy, fcol, dcol) BoundaryFill (seedx, seedy - 1, fcol, dcol) BoundaryFill (seedx 1, seedy + 1, fcol, dcol) Step 6 Exit 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 bcol. 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)!= bcol && getpixel(x, y)!= fcolor 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 BoundaryFill (seedx 1, seedy, fcol, dcol) BoundaryFill (seedx + 1, seedy, fcol, dcol) BoundaryFill (seedx, seedy - 1, fcol, dcol) BoundaryFill (seedx, seedy + 1, fcol, dcol) BoundaryFill (seedx 1, seedy + 1, fcol, dcol) BoundaryFill (seedx + 1, seedy + 1, fcol, dcol) BoundaryFill (seedx + 1, seedy - 1, fcol, dcol) BoundaryFill (seedx 1, seedy - 1, fcol, dcol) Step 6 Exit
OR Part Q.3 Write a short note on: (A)Aliasing & Flickers in display processor (B) Shearing 08 CO364.2 Solution (A)Aliasing & Flickers in display processor Aliasing: 1. A problem with high resolution texturing is aliasing, which occurs when adjacent pixels in a rendered image are sampled from pixels that are far apart in a texture image. 2. By down-sampling reducing the size of a texture aliasing can be reduced for far away or small objects, but then textured objects look blurry when close to the viewer. 3. What we really want is a high resolution texture for nearby viewing, and downsampled textures for distant viewing. 4. A technique called mip-mapping gives us this by pre-rendering a texture image at several different scales. 5. For example, a 256 256 image might be down-sampled to 128 128, 64 64, 32 32, 16 16, and so on. 6. Then it is up to the renderer to select the correct mipmap to reduce aliasing artifacts at the scale of the rendered texture. An aliased high resolution texture image (left) and the same texture after mipmapping (right). Flickers in display processor The phenomenon whereby a display screen appears to flicker. Screen flicker results from a variety of factors, the most important of which is the monitor's refresh rate, the speed with which the screen is redrawn. If the refresh rate is too slow, the screen will appear to glimmer. Another factor that affects screen flicker is the persistence of the screen phosphors. Low-persistence phosphors fade more quickly than high-persistence monitors, making screen flicker more likely. Screen flicker can also be affected by lighting. Finally, screen flicker is a subjective perception that affects people differently. Some people perceive screen flicker where others do not.
(B) Shearing A transformation that slants the shape of an object is called the shear transformation. There are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and other shifts Y coordinate values. However; in both the cases only one coordinate changes its coordinates and other preserves its values. Shearing is also termed as Skewing. X-Shear The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines to tilt right or left as shown in below figure. The transformation matrix for X-Shear can be represented as X' = X + Shx. Y Y = Y Y-Shear The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to transform into lines which slopes up or down as shown in the following figure.
The Y-Shear can be represented in matrix from as Y = Y + Shy. X X = X