November, 2018 Mechanical Engineering Fifth Semester ...

15
1. Answer all questions (1X12=12 Marks) a) What is a line segment? b) Vectors c) Graphic primitives d) world coordinate system e) Incremental methods f) The refresh line g) What is initializing of a polygon? h) What is Interfacing in polygons? i) Transformations j) Segment table k) Viewing transformation l) What is clipping? UNIT I 2. a) Explain the condition to generate the perpendicular lines in computer graphics. 6M b) Discuss the importance of the primitive operations. 6M (OR) 3. a) Illustrate about Normalized device co-ordinates related to Graphic primitives. 6M b) Write a brief note on Pixels and Frame buffers. 6M UNIT II 4. a) Illustrate about co-ordinate system and classify. 6M b) Explain about the functional operation of inherent memory devices. 6M (OR) 5. a) Explain about the functional operation of the CRT device. 6M b) Develop an algorithm to generate the β€˜Circle’. 6M UNIT III 6. a) Explore the concept related to the Inverse transformations. 6M b) Discuss about Initialising and Antialiasing related to polygons. 6M (OR) 7. a) Generate a transformation to rotate about an arbitrary point. 6M b) Illustrate the process for representation of polygons. 6M UNIT IV 8. a) Develop an algorithm for the Segment creation. 6M b) Differentiate between the Windowing and Clipping operations. 6M (OR) 9. a) Explain about the Cohen-Sutherland algorithm. 7M b) Develop the methodology to delete a segment. 5M III/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION November, 2018 Mechanical Engineering Fifth Semester Computer Graphics Time: Three Hours Maximum: 60 Marks Answer Question No.1 compulsorily. (1X12 = 12 Marks) Answer ONE question from each unit. (4X12=48 Marks)

Transcript of November, 2018 Mechanical Engineering Fifth Semester ...

1. Answer all questions (1X12=12 Marks)

a) What is a line segment?

b) Vectors

c) Graphic primitives

d) world coordinate system

e) Incremental methods

f) The refresh line

g) What is initializing of a polygon?

h) What is Interfacing in polygons?

i) Transformations

j) Segment table

k) Viewing transformation

l) What is clipping?

UNIT I

2. a) Explain the condition to generate the perpendicular lines in computer graphics. 6M

b) Discuss the importance of the primitive operations. 6M

(OR)

3. a) Illustrate about Normalized device co-ordinates related to Graphic primitives. 6M

b) Write a brief note on Pixels and Frame buffers. 6M

UNIT II

4. a) Illustrate about co-ordinate system and classify. 6M

b) Explain about the functional operation of inherent memory devices. 6M

(OR)

5. a) Explain about the functional operation of the CRT device. 6M

b) Develop an algorithm to generate the β€˜Circle’.

6M

UNIT III 6. a) Explore the concept related to the Inverse transformations. 6M

b) Discuss about Initialising and Antialiasing related to polygons. 6M

(OR) 7. a) Generate a transformation to rotate about an arbitrary point. 6M

b) Illustrate the process for representation of polygons. 6M

UNIT IV 8. a) Develop an algorithm for the Segment creation. 6M

b) Differentiate between the Windowing and Clipping operations. 6M

(OR) 9. a) Explain about the Cohen-Sutherland algorithm. 7M

b) Develop the methodology to delete a segment. 5M

III/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION

November, 2018 Mechanical Engineering

Fifth Semester Computer Graphics Time: Three Hours Maximum: 60 Marks

Answer Question No.1 compulsorily. (1X12 = 12 Marks)

Answer ONE question from each unit. (4X12=48 Marks)

III/IV B.Tech (Regular) DEGREE EXAMINATION

November, 2018 Mechanical Engineering

Fifth Semester Computer Graphics

SCHEME OF EVALUATION

III/IV B.Tech (Regular) DEGREE EXAMINATION

November, 2018 Mechanical Engineering

Fifth Semester Computer Graphics

SCHEME OF EVALUATION 1.

a)

b)

c)

d)

e)

f)

g)

h)

i)

j)

k)

l)

A line segment may be specified by its two end-points.

A vector has a single direction and a length.

Graphics primitives are functions that are used to specify lines and characters

that make up the picture.

This is the base reference system for the overall model, to which all other model

coordinates relate.

DDA, Bresenham’s algorithms.

In raster scan display the beam is moved all over the screen one scan line at a

time, that single line of scan may be called as refresh line.

An initialization routine is needed to set default values for filling and fill-style

parameters.

Polygons can be shown either filled or outline. Providing a method of indicating

this choice is called interfacing of polygons.

Computer graphics allows the programmer to define objects and altering or

manipulation of objects. This simulated manipulation of objects is referred to as

transformation.

The data structure used to store the information about segments is called

segment table.

Mapping the image or picture from the world coordinate system to device

coordinate system is called viewing transformation.

Removing unwanted portion from an image is called clipping.

2. a)

2. b)

UNIT-I

we can determine if two lines are perpendicular by examining their slopes.

Suppose two lines,

y = m1 x + b1

and

y = m2 x + b2

If first line is perpendicular to the second, then a line parallel to the first (that is,

a line with the same slope) will also be perpendicular to the second. For

example, y = m1 x should be perpendicular to y = m2 x + b2. The same argument

applies to the second line: y = m2 x will be perpendicular to y = m1 x. now these

are two lines which intersect at origin as shown in the above figure.

Consider a point (x1,y1) on the line y = m1 x so that y1 = m1 x1 and a point (x2,y2)

on y = m2 x so that y2 = m2 x2. The three points (x1, y1), (x2, y2), and (0, 0) form

a triangle. If the two lines are perpendicular, they will form a right triangle and

the Pythagorean theorem will apply. The distance between (0, 0) and (x1, y1)

squared plus the distance between (0, 0) and (x2,y2) squared will equal the square

of the hypotenuse between (x1,y1) and (x2,y2). The distance formula gives

x12 + y1

2 + x22 + y2

2 = (x1 – x2)2 + (y1 – y2)

2

simplifying gives

0 = -2y1y2 -2x1x2

Or 𝑦1

π‘₯1 = -

π‘₯2

𝑦2

But since y1 = m1 x1 and y2 = m2 x2, we have

m1 = - 1

π‘š2

Therefore, if two lines are perpendicular, the slope of one will be negative

reciprocal of the slope of the other.

Graphic primitives are the functions that we use to specify the actual lines and

characters that make up the picture. These functions must be chosen carefully to

provide the application programmer with convenient methods of describing

pictures and at the same time to take advantage of the capabilities of the display

hardware.

3. a)

3. b)

Graphics primitives are used to display straight line, text strings, circular arcs

and other simple graphical items.

Primitive functions used in graphics package in general are,

MOVE-ABS-2

MOVE-REL-2

LINE-ABS-2

LINE-REL-2

Different display devices may have different screen sizes as measured in pixels.

Size of the screen pixels increase as the resolution of the screen increases. In

high resolution monitors the picture defined in pixels is large in size, whereas in

low resolution monitors the picture defined in pixels is small in size. To avoid

this and to make the program to be device independent, the coordinates have to

be specified in some other units other than pixels and then use the interpreter to

convert these coordinates to the appropriate pixel value for the particular display

device. These device independent units are called normalized device

coordinates. In these the screen measures 1 unit wide and 1 unit length. The

lower left corner of the screen is origin, and upper right corner is the point (1,1).

The point (0.5,0.5) is the center of the screen no matter what the physical

dimensions or resolution of the actual display device.

The interpreter uses simple linear formula to convert the normalized device

coordinates to be actual screen coordinates.

xs = WIDTH * xn + WIDTH-START

&

ys = HEIGHT * yn + HEIGHT-START

where xn, , yn are normalized device coordinates

xs , ys are actual screen coordinates

bottom most pixel is HEIGHT-START

left most pixel is WIDTH-START

number of pixels in horizontal direction is WIDTH

number of pixels in vertical direction is HEIGHT

Pixel, In computer graphics, short form of picture element is sometimes called as

pixel(smallest addressable point on the screen). A pixel has only two colour

values(typically black and white), it can be encoded by 1 bit of information. If

more than two bits are used to represent a pixel, a large range of colours can be

represented.

Frame Buffer, Image can be displayed on the screen after creating it by a

4. a)

computer program in a special part of the computer memory called frame buffer.

Frame buffer contains an internal representation of the image. It collects and

stores the pixel values for use by the display device.

In a 2-D coordinate system the X axis generally points from left to right, and the

Y axis generally points from bottom to top. ( Although some windowing systems

will have their Y coordinates going from top to bottom. )

When we add the third coordinate, Z, we have a choice as to whether the Z-axis

points into the screen or out of the screen

Multiple Coordinate Systems in a Graphics Program

In a typical graphics program, we may need to deal with a number of different

coordinate systems, and a good part of the work is the conversion of coordinates

from one system to another. Here is a list of some of the coordinate systems :

World Coordinate System - Also known as the "universe" or

sometimes "model" coordinate system. This is the base reference system

for the overall model, ( generally in 3D ), to which all other model

coordinates relate.

Object Coordinate System - When each object is created in a modelling

program, the modeler must pick some point to be the origin of that

particular object, and the orientation of the object to a set of model axes.

For example when modelling a desk, the modeler might choose a point in

the center of the desk top for the origin, or the point in the center of the

desk at floor level, or the bottom of one of the legs of the desk. When

this object is moved to a point in the world coordinate system, it is really

the origin of the object ( in object coordinate system ) that is moved to

the new world coordinates, and all other points in the model are moved

by an equal amount.

Hierarchical Coordinate Systems - Sometimes objects in a scene are

arranged in a hierarchy, so that the "position" of one object in the

hierarchy is relative to its parent in the hierarchy scheme, rather than to

the world coordinate system. For example, a hand may be positioned

relative to an arm, and the arm relative to the torso. When the arm

moves, the hand moves with it, and when the torso moves, all three

objects move together.

Viewpoint Coordinate System - Also known as the "camera" coordinate

system. This coordinate system is based upon the viewpoint of the

observer, and changes as they change their view. Moving an object

"forward" in this coordinate system moves it along the direction that the

viewer happens to be looking at the time.

Model Window Coordinate System - this coordinate system refers to

the subset of the overall model world that is to be displayed on the

screen. Depending on the viewing parameters selected, the model

window may be rectilinear or a distorted viewing frustum of some kind.

Screen Coordinate System - This 2D coordinate system refers to the

physical coordinates of the pixels on the computer screen, based on

current screen resolution. ( E.g. 1024x768 )

Viewport Coordinate System - This coordinate system refers to a

subset of the screen space where the model window is to be displayed.

Typically the viewport will occupy the entire screen window, or even the

entire screen, but it is also possible to set up multiple smaller viewports

4. b)

5. a)

within a single screen window.

Direct view storage tube is an example of inherent memory devise. A direct

view storage tube (DVST) uses the storage grid which stores the picture

information as a change distribution just behind the phosphor coated screen. The

below figure shows the general arrangement of DVST. It contains of two

electron guns: a primary gun and a flood gun.

Arrangement of the DVST

A primary gun stores the picture pattern and the flood gun maintains the picture

display.

A primary gun produces high speed electrons which strike on the grid to draw

the picture pattern. As electron beam strikes on the storage grid with high speed,

it knocks out electrons from the storage grid keeping the net positive charge. The

knocked out electrons are attracted towards the collector. The net positive charge

on the storage grid is nothing but the picture pattern. The continues low speed

electrons from the flood gun pass through the control grid and are attracted to

the positive charged areas of the storage grid. The low speed electrons then

penetrate the storage grid and strike the phosphor coating without affecting the

positive charge pattern on the storage grid. During this process the collector just

behind the storage grid smooths out the flow of flood electrons.

Cathode Ray Tube (CRT) is a computer display screen, used to display the

output in a standard composite video signal. The working of CRT depends on

movement of an electron beam which moves back and forth across the back of

the screen. The source of the electron beam is the electron gun; the gun is

located in the narrow, cylindrical neck at the extreme rear of a CRT which

produces a stream of electrons through thermionic emission. Usually, A CRT

has a fluorescent screen to display the output signal. A simple CRT is shown in

below.

Cathode Ray Tube

A cathode ray tube consists of one or more electron guns, possibly internal

electrostatic deflection plates and a phosphor target. CRT has three electron

beams – one for each (Red, Green, and Blue) is clearly shown in figure. The

electron beam produces a tiny, bright visible spot when it strikes the phosphor-

coated screen. In every monitor device the entire front area of the tube is

scanned repetitively and systematically in a fixed pattern called a raster. An

image (raster) is displayed by scanning the electron beam across the screen. The

phosphor’s targets are begins to fade after a short time, the image needs to be

refreshed continuously. Thus CRT produces the three color images which are

primary colors. Here we used a 50 Hz rate to eliminate the flicker by refreshing

the screen.

Main parts of the cathode ray tube are cathode, control grid, deflecting plates

and screen.

Cathode

The heater keeps the cathode at a higher temperature and electrons flow from the

heated cathode towards the surface of the cathode. The accelerating anode has a

small hole at its center and is maintained at a high potential, which is of positive

polarity. The order of this voltage is 1 to 20 kV, relative to the cathode. This

potential difference creates an electric field directed from right to left in the

region between the accelerating anode and the cathode. Electrons pass through

the hole in the anode travel with constant horizontal velocity from the anode to

the fluorescent screen. The electrons strike the screen area and it glows brightly.

The Control Grid

The control grid regulates the brightness of the spot on the screen. By

controlling the number of electrons by the anode and hence the focusing anode

ensures that electrons leaving the cathode in slightly different directions are

focused down to a narrow beam and all arrive at the same spot on the screen.

The whole assembly of cathode, control grid, focusing anode, and accelerating

electrode is called the electron gun.

Deflecting Plates

Two pairs of deflecting plates allow the beam of electrons. An electric field

between the first pair of plates deflects the electrons horizontally, and an electric

field between the second pair deflects them vertically, the electrons travel in a

straight line from the hole in the accelerating anode to the center of the screen

when no deflecting fields are present, where they produce a bright spot.

Screen

This may be circular or rectangular. Screen is coated with special type of

fluorescent material. Fluorescent material absorbs its energy and re-emits light in

the form of photons when electron beam hits the screen. When it happens some

of them bounces back just like bouncing of cricket ball from a wall. These are

5. b)

6. a)

called as secondary electrons. They must be absorbed and returned back to

cathode, if it is not so they accumulate near screen and produce space charge or

electrons cloud. To avoid this, aquadag coating is applied on funnel part of CRT

from inside.

Circle drawing algorithm:

Step1: obtain the radius of the circle r

Step2: set the initial decision parameter d = 3- 2r

Step3: set the base values of the coordinates x=0 and y=r

Step4: compute the next pixel on the circle and update the decision parameter

While (x <= y)

Plot (x,y)

If (d<0)

d=d+4x+6

else

d= d+4(x-y)+10

end if

x= x+1

end while

Step5: finish

Inverse transformation means for a given transformed point P2 (x2 , y2) finding

the original point P1(x1,y1). Which is nothing but applying transformation itself.

Using inverse transformation matrix we can find out this. The multiplication of

matrix (T) and its inverse matrix (T-1) results in identity matrix (I).

i.e., TT-1 = T-1T = I

It is already clear that to transform a point P1 to point P2 we need transformation

matrix T

P2 = P1 T

Now multiply both sides of this equation by the inverse of matrix T.

P2 T-1 = P1 T T-1 = P1 I = P1

Inverse transformation matrices for various transformations

Scaling,

[

1

𝑠π‘₯0 0

01

𝑠𝑦0

0 0 1]

Translation, [1 0 βˆ’π‘‘π‘₯0 1 βˆ’π‘‘π‘¦0 0 1

]

Rotation, [cos πœƒ sin πœƒ 0βˆ’sin πœƒ cos πœƒ 0

0 0 1]

Where sx, sy are scaling factors in x and y direction.

tx , ty are translation distances in x and y direction.

6. b)

7. a)

7. b)

ΞΈ is the angle of rotation.

Initializing is a routine which is essential for filling of the polygons. In this

routine default values for filling and fill- style parameters are set.

Aliasing is a problem for the edges of the polygon just as it is for lines. Many

raster displays allow only two pixel states (on or off). For these displays lines

may have jagged or staircase appearance when they step from one row or

column to the next. This phenomenon is called aliasing.

Minimizing aliasing effect is called antialiasing. One approach to reduce aliasing

effect is to increase the resolution of the display devise.

To rotate an object about an arbitrary point (xa,ya), the following steps are

considered.

Translate the arbitrary point ( xa, ya ) to the origin.

Rotate it about the origin.

Finally, translate back to the original position.

Applying these transformations sequentially we get rotation transformation

matrix about arbitrary point.

First transformation matrix which moves point ( xa, ya ) to origin is

T1 = [1 0 βˆ’π‘₯π‘Ž

0 1 βˆ’π‘¦π‘Ž

0 0 1

]

Second transformation matrix for rotation about origin in counter clockwise

direction is

R = [cosπœƒ βˆ’ sin πœƒ 0sin πœƒ cos πœƒ 0

0 0 1]

Third transformation matrix to translate back to original position is

T2 = [1 0 π‘₯π‘Ž

0 1 π‘¦π‘Ž

0 0 1

]

Over all transformation matrix is

R = T1 * R * T2

= [1 0 βˆ’π‘₯π‘Ž

0 1 βˆ’π‘¦π‘Ž

0 0 1

] * [cosπœƒ βˆ’ sin πœƒ 0sin πœƒ cos πœƒ 0

0 0 1] * [

1 0 π‘₯π‘Ž

0 1 π‘¦π‘Ž

0 0 1

]

= [cos πœƒ βˆ’ sin πœƒ βˆ’π‘₯π‘Ž

sin πœƒ cosπœƒ βˆ’π‘¦π‘Ž

0 0 1

]* [1 0 π‘₯π‘Ž

0 1 π‘¦π‘Ž

0 0 1

]

= [cos πœƒ βˆ’ sin πœƒ π‘₯π‘Ž cosπœƒ βˆ’ π‘¦π‘Ž sin πœƒ βˆ’ π‘₯π‘Ž

sin πœƒ cosπœƒ π‘₯π‘Ž sin πœƒ + π‘¦π‘Ž cosπœƒ βˆ’ π‘¦π‘Ž

0 0 1

]

The information required to specify the polygon is the number of sides and the

coordinates of vertex points. To add polygon to the graphic system one must

know the representation of polygon. The representation of polygon specifies the

devise, how to draw the polygon. There are different approaches to represent the

polygon,

Polygon drawing primitive, on some devices polygon shapes can directly be

8. a)

8. b)

drawn. On such devices polygons are saved as a unit.

Trapezoid primitive, some graphic devices support trapezoid primitive. In such

devices, trapezoids are formed from two scan lines and two line segments as

shown in the below figure. Here, trapezoids are drawn by stepping down the line

segments with two vector generators and, for each scan line, filling in all the

pixels between them. Therefore every polygon is broken up into trapezoids and

is represented as aa series of trapezoids.

Lines and points, most of the graphics devices do not provide any polygon

support at all. In such cases polygons are represented using lines and points. A

polygon is represented as a unit and it is stored in the display file.

Algorithm CREATE-SEGMENT

Argument SEGMENT-NAME the segment name

Global NOW-OPEN the segment currently open

FREE the index of the next free display-file cell

SEGMENT-START, SEGMENT-SIZE, VISIBILITY

ANGLE, SCALE-X, SCALE-Y, TRANSLATE-X, TRANSLATE-Y

Arrays that make up the segment table

Constant NUMBER-OF-SEGMENTS size of the segment table

BEGIN

IF NOW-OPEN > 0 THEN RETURN ERROR β€˜SEGMENT STILL OPEN’;

IF SEGMENT-NAME < 1 OR SEGMENT-NAME > NUMBER-OF-

SEGMENTS

THEN

RETURN ERROR β€˜INVALIND SEGMENT NAME’;

IF SEGMENT-SIZE[SEGMENT-NAME] > 0 THEN

RETURN ERROR β€˜SEGMENT ALREADY EXISTS’;

SEGMENT-START[SEGMENT-NAME] ← FREE;

SEGMENT-SIZE[SEGMENT-NAME]← 0;

VISIBILITY[SEGMENT-NAME] ← VISIBILITY[0];

ANGLE[SEGMENT-NAME] ← ANGLE[0];

SCALE-X[SEGMENT-NAME] ← SCALE-X[0];

SCALE-Y[SEGMENT-NAME] ← SCALE-Y[0];

TRANSLATE-X[SEGMENT-NAME] ← TRANSLATE-X[0];

TRANSLATE-Y[SEGMENT-NAME] ← TRANSLATE-Y[0];

NOW-OPEN ← SEGMENT-NAME;

RETURN;

END;

Windowing, when drawings or images are very large and complex, they are

difficult to read and observe. In such situations it is useful to display only those

portions of the drawing that are of immediate interest. This gives the effect of

looking at the image through a rectangular box called window. We can enlarge

9. a)

9. b)

this window portions of a drawing to resumed size, and display on the screen.

The method of selecting and enlarging portions of a drawing is called

windowing.

Clipping, removing unwanted portion from the image is called clipping. The

region against which an image is to clipped is called a clip window or clipping

window. The main application of clipping are extracting part of a defines scene

of viewing, drawing and painting operations that allow parts of a picture to be

selected for copying, moving or duplicating.

Cohen-Sutherland Line Clipping Algorithm

This algorithm divides screen and its boundaries into nine equal parts. Every part

is assigned a four bit binary code. These four bit codes are called out codes.

These codes identify the location of a point relative to the boundaries of the

clipping rectangle as shown below.

Algorithm:

1. Read the two end points of the given line segment as P1 (x1,y1)P2 (x2,y2)

2. Read the window coordinates as Wx1, Wy1, Wx2, Wy2

3. Covert given line points into Sutherland 4-bit binary code.

4. If both end points P1 and P2 are zero then the line is completely inside.

So, draw the line and go to step 10.

5. If both end points are not zero, then take logical and operation of both the

end points and check the result. If result is non zero then the line is

completely outside (invisible) then goto step 10.

6. If both the above conditions are not satisfied then that line is partially

visible. Now determine intersection points with window sides. If both

end points are non-zero, find intersection with boundary edges of

clipping window with respect to point P1 and P2. If one end point is zero

and other is non-zero then find intersection points P11, P2

1 with boundary

edge of clipping window with respect to it.

7. Divide the line segment at intersection points.

8. Reject the line segment if any one end point of it appears outside the

clipping window.

9. Draw the remaining line segments.

10. End.

Algorithm DELETE-SEGMENT

Argument SEGMENT-NAME the segment name

Global NOW-OPEN the segment currently open

FREE the index of the next free display-file cell

DF-OP, DF-X, DF-Y the display file arrays

SEGMENT-START, SEGMENT-SIZE, VISIBILITY part of the

segment table

Constant NUMBER-OF-SEGMENTS size of the segment table

Local GET the location of an instruction to be moved

PUT the location to which an instruction should be moved

SIZE the size of the deleted segment

I a variable for stepping through the segment table

BEGIN

IF SEGMENT-NAME < 0 OR SEGMENT-NAME > NUMBER-OF-

SEGMENTS

THEN

RETURN ERROR β€˜INVALID SEGEMNT NAME’;

IF SEGMENT-NAME = NOW-OPEN AND SEGMENT-NAME β‰  0 THEN

RETURN ERROR β€˜SEGMENT STILL OPEN’;

IF SEGMENT-SIZE[SEGMENT-NAME] = 0 THEN RETURN;

PUT ← SEGMENT-START[SEGMENT-NAME];

SIZE ← SEGMENT-SIZE[SEGMENT-NAME];

GET ← PUT + SIZE;

Shift the display file elements

WHILE GET < FREE

DO

BEGIN

DF-OP[PUT] ← DF-OP[GET];

DF-X[PUT] ← DF-X[GET];

DF-Y[PUT] ← DF-Y[GET];

PUT ← PUT + 1;

GET ← GET + 1;

END;

Recover the deleted storage

FREE ← PUT;

Update the segment table

FOR I = 0 TO NUMBER OF SEGMENTS

DO

IF SEGMENT-START[I] > SEGMENT-START[SEGMENT-NAME]

THEN

SEGMENT-START[I] ← SEGMENT-START[I] – SIZE;

SEGMENT-SIZE[SEGMENT-NAME] ← 0;

IF VISIBILITY[SEGMENT-NAME] THEN NEW-FRAME;

RETURN;

END;