You are on page 1of 18

MC0072- Computer Graphics

ASSIGNMENT SET 1

1. Explain how to modify the line clipping algorithm to clip polygons. Ans: A polygon is nothing but the collection of lines . therefore, we might think that line clipping algorithm can be used directly for polygon cliping. However , when a close polygon is clipped as a collecion of lines with the line cliping algorithm, the orignal close polygon became one or more open polygon or discrete lines as shown in the figur , thus we need to modify the line clip algorithm to clip polygons.

We consider polygon as a closed solid area . Hence after clipping it should remain closed. To achive this we require we require an algorithm that will generate addition line segment which make the polygon as a closed area for example in below figure the line a b, c d, d e, f g, and h i, are added to polygon discription to make it closed.

Page | 1

MC0072- Computer Graphics

Ading line c d, an d e, is particularly difficult . Conciderable difficulty also occure when cipping a polygon results in several disjoint smaller polygon as shown in the figure for example, the lines a b, c d, d e, and g f, are frequently included in the clipped polygon discription is not desired .

1. If the first vertex of the edge is outside the window boundary and the second vertex of the edge is inside then the intersection point of polygon edge with the window bondary and the second vertex are added to the output vertex list. 2. If both vertices of the edge are inside the window boundary , only the second vertex is added to the output vertex list.

Page | 2

MC0072- Computer Graphics

3. If the first vertex of the edge is inside the window boundary and the second vertex of the edge is outside, only the edge intersection with the window boundary is added to the output vertex list. 4. The both vertex of the edge are outside the window boundary , nothing is added to the output list. Once all vertices are processed for one chip window boundary , the output list of vertices is cliped againt the next window boundary. Going through above four cases we can realize that there are two key processes in this algorithm 1. Determining the visibility of a point or vertex ( inside outside test ) and 2. Determining the intersection of the polygon edge and the clipping plane. One way of determining the visibility of a point or vertex is described here . Consider that two points A and B define the window boundary and point under consideration is V , then these three points define a plane . Two vectors which lie in that plane are AB and AV . If the plan is consider on xy plane , then the vector cross product AV x AB has only a z component given by ( XV - XA ) ( YB YA ) (YB YA ) (XB - XA) . the sign of the Z component desides the position of point V with respect to window Boundary. If Z is : Positive Point is on the write side of the window boundary Zero -- Point is on the window boundary.

Negative Point is on the left side of the boundary

2. What is DDA line drawing algorithm explain it with the suitable example? discuss the merit and demerit of the algorithm ? Ans: DNA Line Algorithm 1: Read the line end points (X1,Y1) and (X2,Y2) such that they are equal . [ If equal then plot that point and end ] 2: x = 3. If Length= Else
Page | 3

then

and y =

MC0072- Computer Graphics

Length= end if 4. = (x2-x1)/length = (y2-y1)/length This makes either or equal to 1 because the length is either| x2-x1| or |y2-y1|, the incremental value for either x or y is 1. 5. x = x1+0.5 * sign ( y = y1+0.5*sign( ) )

[Here the sign function makes the algorithm worl in all quadrant. It returns 1, 0,1 depending on whether its argument is <0, =0, >0 respectively. The factor 0.5 makes it possible to round the values in the integer function rather than truncating them] 6. i=1 [begins the loop, in this loop points are plotted] 7. while(i length) { Plot (Integer(x), Integer(y)) x= x+x y= y+y i=i+1 } 8. stop Let us see few examples to illustrate this algorithm. Ex.1: Consider the line from (0,0) to (4,6). Use the simple DDA algorithm to rasterize this line. Sol: Evaluating steps 1 to 5 in the DDA algorithm we have x1=0, x2= 4, y1=0, y2=6 therefor Length = x = y= =6

/ Length = 4/6 /Length = 6/6-1

Initial values for x= 0+0.5*sign ( 4/6 ) = 0.5 y= 0+ 0.5 * sign(1)=0.5 Tabulating the results of each iteration in the step 6 we get,
Page | 4

MC0072- Computer Graphics

The results are plotted as shown in the It shows that the rasterized line lies to both sides of the actual line, i.e. the algorithm is orientation dependent

Result for s simple DDA Ex. 2 : Consider the line from (0,0) to (-6,-6). Use the simple DDA algorithm to rasterize this line. Sol : x1=0, x2= -6,y1=0, y2=-6 Therefore Therefore Lenth = | X2 -- X1 | = | Y2-Y1| = 6 Ax = Ay = -1 Initial values for x= 0+0.5*sign (-1) = -0.5 y= 0+ 0.5 * sign(-1) = -0.5 Tabulating the results of each iteration in the step 6 we get,

Page | 5

MC0072- Computer Graphics

The results are plotted as shown in the It shows that the rasterized line lies on the actual line and it is 450 line.

Advantages of DDA Algorithm 1. It is the simplest algorithm and it does not require special skills for implementation. 2. It is a faster method for calculating pixel positions than the direct use of equation y=mx + b. It eliminates the multiplication in the equation by making use of raster characteristics, so that appropriate increments are applied in the x or y direction to find the pixel positions along the line path Disadvantages of DDA Algorithm 1. Floating point arithmetic in DDA algorithm is still time-consuming. 2. The algorithm is orientation dependent. Hence end point accuracy is poor.

3. Write a short note on: A) Reflection B) Sheer C) Rotation about an arbitrary axis Ans: A ) Reflection A reflection is a transformation that produces a mirror image of an object relative to an axis of reflection. We can choose an axis of reflection in the xy plane or perpendicular to the xy plane. The table below gives examples of some common reflection.

Page | 6

MC0072- Computer Graphics

Reflection about y axis

B) Shear : A transformation that slants the shape of an objects is called the shear transformation. Two common shearing transformations are used. One shifts x coordinate values and other shifts y coordinate values. However, in both the cases only one coordinate (x or y) changes its coordinates and other preserves its values. 1 X shear : The x shear preserves they coordinates, but changes the x values which causes vertical lines to tilt right or left as shown in the fig. 6.7. The transformation matrix for x shear is given as

Page | 7

MC0072- Computer Graphics

2 Y Shear: The y shear preserves the x coordinates, but changes the y values which causes horizontal lines to transform into lines which slope up or down, as shown in the

The transformation matrix for y shear is given as

C) Rotation about an arbitrary axis: A rotation matrix for any axis that does not coincide with a coordinate axis can be set up as a composite transformation involving combinations of translation and the coordinate-axes rotations. In a special case where an object is to be rotated about an axis that is parallel to one of the coordinate axes we can obtain the resultant coordinates with the following transformation sequence. 1. Translate the object so that the rotation axis coincides with the parallel coordinate axis 2. Perform the specified rotation about that axis. 3. Translate the object so that the rotation axis is moved back to its original position When an object is to be rotated about an axis that is not parallel to one of the coordinate axes, we have to perform some additional transformations. The sequence of these transformations is given below. 1. Translate the object so that rotation axis specified by unit vector u passes through the coordinate origin. 2. Rotate the object so that the axis of rotation coincides with one of the coordinate axes. Usually the z axis is preferred. To coincide the axis of rotation to z axis we have to first perform rotation
Page | 8

MC0072- Computer Graphics

of unit vector u about x axis to bring it into xz plane and then perform rotation about y axis to coincide it with z axis. 3. Perform the desired rotation about the z axis 4. Apply the inverse rotation about y axis and then about x axis to bring the rotation axis back to its original orientation. 5. Apply the inverse translation to move the rotation axis back to its original position. As shown in the Fig. the rotation axis is defined with two coordinate points P1 and P2 and unit vector u is defined along the rotation of axis as

Where V is the axis vector defined by two points P1 and P2 as V = P2 P1= (x2 x1, y2 y1, z2 z1) The components a, b and c of unit vector us are the direction cosines for the rotation axis and they can be defined as

4. Write a short note on: a) Replicating pixels b) Moving pen c) Filling area between boundaries d) Approximation by thick polyline e) Line style ad pen style. Ans:

Page | 9

MC0072- Computer Graphics

A ) Replicating pixels : A quick extension to the scan-conversation ineer loop to write multiple pixel at each computed pixel works resonably well fo lines: Here , pixel are duplicated in columns for lines with 1 < slope < 1 and in rows for all other lines . The effect, however , is that the line ends are always vertical or horizontal , which is not pleasing for rather thick lines as shown in figure

Furthermore , lines that are horizontal and vertical have different thickness for lines at an angle , where the thickness of the primitive is defined as the distence between the primitives boundaries parpendicular to its tangent. Thus if the thickness paramater is t , a horizontal or horizontal or verticalline has thickness t , whereas one drawn at 45o has an average thickness of This is another result of having fewer pixels in the line at an angle, as first noted in Section ; it descreses the brightness contrast with horizontal and vertical lines of the same thickness. Still another problem with pixel replication is the generic problem of even-numbered width: We cannot center the duplicated column or row about the selected pixel, so we must choose a side of the primitive to have an extra pixel. Altogether, pixel replication is an efficient but crude approximation that works best for primitives that are not very thick. b) Moving pen : Choosing a rectangular pen whose center or corner travels along the single-pixel outline of the primitive works reasonably ell for lines; it produces the line shown in figure below

Notice that this line ios similar to that produced by pixel replication but is thicker at the endpoints. As with pixel replication, because the pen stays vertically aligned, the perceived thickness of the primitive varies as a function of the primitives angle, but in the opposite way:

Page | 10

MC0072- Computer Graphics

The width is thinnest for horizontal segments and thickest for segments with slope of . An ellipse are, for example , varies in thickness alone its entire trajectory, being of the specified thickness when the tangent is nearly horizontal or vertical, and thickened by a factor of around . this problem would be eliminated if the square turned to follow the path, but it is much better to use a circular cross-section so that the thickness is angle-independent. Now lets look at how to implement the moving-pen algorithm for the simple case of an upright rectangular or circular cross-section ( also called footprint ) so that its center or corner is at the chosen pixel; for a circular footprint and a pattern drawn in opaque mode, we must in ddition mask off the bits outside the circular region, which is not as easy task unless our low-level copy pixel has a write mask for the destination region. The bure-force copy solution writes pixels more than once , since the pens footprints overlap at adjacent pixels. A better technique that also handle the circularcross-section problem is to use the snaps of the footprint to compute spans for successive footprints at adjacent pixels. As in the filling d) Approximation by thick polyline We can do piecewise-linear approximation of any primitive by computing points on the boundary ( with floating-point coordinates ) , then connecting these points with line segments to from a polyline. The advantage of this approach is that the algorithms for both line clipping and line scan conversion ( for thin primitives ) , and for polygon clipping and polygon scan conversion ( for thick primitives ) , are efficient. Naturall, the segnates must be quite short in places where the primitive changes direction rapidly. Ellipse ares cane be represented as ratios of parametric polynomials, which lend themselves readily to such piecewise-linear approximation. The individual line segments are then drawn as rectangles with the specified thickness. To make the thick approximation look nice, however, we must solve the problem of making thick lines join smoothly . e) Line style ad pen style. SRGPs line-style atribute can affect any outline primitive. In general, we must use conditional logic to test whether or not to write a pixel, writing only for 1s. we store the pattern write mask as a string of 16 booleans (e.g., a 16-bit integer ); it should therefore repeat every 16 pixels. We modify the unconditional WritePixel statemet in the line scan-conversion algorithm to handle this.There is a drawback to this technique, however. Since each bit in the mask corresponds to an iteration of the loop, and not to a unit distance along the line . the length of dashes varies with the angle of the line; a dash at an angle is longer than is a horizontal or vertical dash. For engineering drawings, this variation is unacceptable, and the dashes must be calculated and scan-coverted as individual line segments of length invariant with angle. Thick line are created as sequences of alternating solid and transparent rectangles whose vertices are calculated exactly as a function of
Page | 11

MC0072- Computer Graphics

the line style selected. The rectangles are then scan-converted individually; for horizontal and vertical line , the program may be able to copypixel the rectangle. Line style and pen style interact in thick outline primitive. The line style is used to calculate the rectangle for each dash, and each rectangle is filled with the selected pen pattern.

Page | 12

MC0072- Computer Graphics

ASSIGNMENT SET 2 ---------------------------------------------------------------------------------------------------------------------------1. Write a short note on a) Input technology Ans: Input TechnologyInput technology has also improved greatly over the years. Number of input devices were developed over the years. These devices are punch cards, light pens, keyboard, tables, mouse and scanners. b) Software technology

Software Technology Like output and input technology there is a lot of development in the software technology. In early days low level software were available. Over the years software technology moved from low level to device dependent and then to device independent packages. The device independent packages are high level packages with can drive a wide variety of display and printer devices. As a need for the device independent package a standardization is made and specification are decided. The first graphics specification to be officially standardized was GKS (the Graphical Kernel System). GKS supports the grouping of logically related primitives such as lines, polygons, and character strings and their attributes in collected form called segments. In 1988, a 3D extension of GKS, became an official standard, as did a much more sophisticated but even more complex graphics system called PHIGS (Programmers Hierarchical Interactive Graphics System). PHIGS, as its name implies, supports nested hierarchical grouping of 3D primitives, called structures. In PHIGS, all primitives are subjected to geometric transformations such as scaling, rotation and translation to accomplish dynamic movement. PHIGS also supports a database of structures the programmer may edit and modify. PHIGS automatically updates the display whenever the database has been modified.

2. Describe the following with respect to methods of generating characters: A) Stroke method B) Starbust method C) Bitmap method

Ans: A) Stroke method

Page | 13

MC0072- Computer Graphics

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 as shown in the figure above. 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. B.Starbust method In this method a fix pattern of line segments are used to generate characters. As shown in the fig. 5.20, there are 24 line segments. 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

Figure shows 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-bit code
Page | 14

MC0072- Computer Graphics

3. Character quality is poor. It is worst for curve shaped characters. C) Bitmap method The third method for character generation is the bitmap method. 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. An 5 7 array is commonly used to represent characters as shown in the fig 5.21. However 7 9 and 9 13 arrays are also used. Higher resolution devices such as inkjet printer or laser printer may use character arrays that are over 100 100.

character A in 5

7 dot matrix format

Each dot in the matrix is a pixel. The character is placed on the screen by copying pixel values from the character array into some portion of the screens frame buffer. The value of the pixel controls the intensity of the pixel

3 . Discuss the homogeneous coordinates for translation, rotation and scaling.? Ans: Homogeneous Coordinates and Matrix Representation of 2D Transformations : In design and picture formation process, many times we may require to perform translation, rotations, and scaling to fit the picture components into their proper positions. In the previous section we have seen that each of the basic transformations can be expressed in the general matrix form P= P.M1 + M2

Page | 15

MC0072- Computer Graphics

To produce a sequence of transformations with above equations, such as translation followed by rotation and then scaling, we must calculate the transformed co-ordinates one step at a time. First, coordinates are rotated. But this sequential transformation process is not efficient. A more efficient approach is to combine sequence of transformations into one transformation so that the final coordinate positions are obtained directly from initial coordinates. This eliminates the calculation of intermediate coordinate values. In order to combine sequence of transformations we have to eliminate the matrix addition associated with the translation term in M2 .To achieve this we have to represent matrix M1 as 3 3 matrix instead of 2 2 introducing an additional dummy coordinate W. Here, points are specified by three numbers instead of two. This coordinate system is called homogeneous coordinate system and it allows us to express all transformation equations as matrix multiplication.

The homogeneous coordinate is represented by a triplet Where

For two dimensional transformations, we can have the homogeneous parameter W to be any non zero value. But it is convenient to have W = 1. Therefore, each two dimensional position can be represented with homogeneous coordinate as (x, y, 1). Summering it all up, we can say that the homogeneous coordinates allow combined transformation, eliminating the calculation of intermediate coordinate values and thus save required time for transformation and memory required to store the intermediate coordinate values. Let us see the homogeneous coordinates for three basic transformations. 1 Homogeneous Coordinates for Translation : The homogeneous coordinates for translation are given as

Page | 16

MC0072- Computer Graphics

2 Homogeneous Coordinates for Rotation : The homogeneous coordinates for rotation are given as

3 Homogeneous Coordinates for Scaling : The homogeneous coordinate for scaling are given as

4. With the help block diagram explain the display system with only frame buffer ? Ans:

Page | 17

MC0072- Computer Graphics

sss

Page | 18

You might also like