Top Banner
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6504-COMPUTER GRAPHICS Anna University 2 & 16 Mark Questions & Answers Year / Semester: III / V Regulation: 2013 Academic year: 2017 - 2018
17

DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Mar 12, 2018

Download

Documents

ngokhue
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

DHANALAKSHMI COLLEGE OF ENGINEERING,

CHENNAI

Department of Computer Science and Engineering

CS6504-COMPUTER GRAPHICS

Anna University 2 & 16 Mark Questions & Answers

Year / Semester: III / V

Regulation: 2013

Academic year: 2017 - 2018

Page 2: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

UNIT-II TWO DIMENSIONAL GRAPHICS

PART - A 1. What is Transformation? Transformation is the process of introducing changes in the shape size and orientation of the object using scaling rotation reflection shearing & translation etc. 2. Write short notes on active and passive transformations. In the active transformation the points x and y represent different coordinates of the same coordinate system. Here all the points are acted upon by the same transformation and hence the shape of the object is not distorted.

In a passive transformation the points x and y represent same points in the space but in a different coordinate system. Here the change in the coordinates is merely due to the change in the type of the user coordinate system. . 3. What is translation? Translation is the process of changing the position of an object in a straight-line path from one coordinate location to another. Every point (x, y) in the object must undergo a displacement to (x´,y´).

4. What is rotation? A 2-D rotation is done by repositioning the coordinates along a circular path, in X = rcos (q + f) and Y = r sin (q + f). 5. What is scaling? The scaling transformations changes the shape of an object and can be carried out by multiplying each vertex (x,y) by scaling factor Sx,Sy where Sx is the scaling factor of x and Sy is the scaling factor of y. 6. What is shearing? The shearing transformation actually slants the object along the X direction or the Y direction as required.ie; this transformation slants the shape of an object along a required plane.

7. What is reflection? The reflection is actually the transformation that produces a mirror image of an object. For this use some angles and lines of reflection.

8. Distinguish between window port & view port? A portion of a picture that is to be displayed by a window is known as window port. The display area of the part selected or the form in which the selected part is viewed is known as view port.

9. What is meant by clipping? Give its types of clipping. Clipping is the method of cutting a graphics display to neatly fit a predefined graphics region or the

view port.

Page 3: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Point clipping

Line clipping Area clipping Curve clipping

Text clipping

10. What is covering (exterior clipping)? This is just opposite to clipping. This removes the lines coming inside the windows and displays the remaining. Covering is mainly used to make labels on the complex pictures. 11. What is the need of homogeneous coordinates? To perform more than one transformation at a time, use homogeneous coordinates or matrixes. They reduce unwanted calculations intermediate steps saves time and memory and produce a sequence of transformations. 12. Distinguish between uniform scaling and differential scaling. When the scaling factors sx and sy are assigned to the same value, a uniform scaling is produced that maintains relative object proportions. Unequal values for sx and sy result in a differential scaling that is often used in design application. . 13. What is fixed point scaling? The location of a scaled object can be controlled by a position called the fixed point that is to remain unchanged after the scaling transformation. . 14. What is meant by affine transformation? A coordinate transformation of the form X= axxx +axyy+bx, y ‟ayxx+ayy y+by is called a two-dimensional affine transformation. Each of the transformed coordinates x „and y „is a linear function of the original coordinates x and y, and parameters aij and bk are constants determined by the transformation type. 15. Distinguish between bitBlt from pixBlt. Raster functions that manipulate rectangular pixel arrays are generally referred to as raster ops. Moving a block of pixels from one location to another is also called a block transfer of pixel values. On a bilevel system, this operation is called a bitBlt (bit-block transfer), on multilevel system t is called pixBlt. 16. List out the various Text clipping.

• All-or-none string clipping -if all of the string is inside a clip window, keep it otherwise discards.

• All-or-none character clipping – discard only those characters that are not completely inside

the window. Any character that either overlaps or is outside a window boundary is clipped.

• Individual characters – if an individual character overlaps a clip window boundary, clip off

the parts of the character that are outside the window.

17. What is fixed point scaling? The location of a scaled object can be controlled by a position called the fixed point that is to remain unchanged after the scaling transformation.

Page 4: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

18. List out the various Text clipping. • All-or-none string clipping - if all of the string is inside a clip window, keep it otherwise

discards.

• All-or-none character clipping – discard only those characters that are not completely inside the window. Any character that either overlaps or is outside a window boundary is clipped.

• Individual characters – if an individual character overlaps a clip window boundary, clip

off the parts of the character that are outside the window.

19. Write down the shear transformation matrix. (nov/dec 2012)

A transformation that distorts the shape of an object such that the transformed shape appears

as if the object were composed of internal layers that had been caused to slide over each other is called a shear. 20. What is the use of clipping?(may/june 2012) Clipping in computer graphics is to remove objects, lines or line segments that are outside the viewing volume. 21. How will you clip a point?(may/june 2013)

Assuming that the clip window is a rectangle in standard position, we save a point P=(x,y) for display if the following inequalities are satisfied:

xwmin ≤ x≤ xwmax ywmin ≤ y≤ ywmax where the edges of the clip window (xwmin ,xwmax, ywmin, ywmax) can be either the world-coordinate window boundaries or viewport boundaries. If any one of these inequalities is not satisfied, the points are clipped (not saved for display).

22. What is meant by viewing transformation? The mapping of a part of world coordinate scene to device coordinates are called viewing transformation. Two dimensional viewing transformation is simply referred to as window to viewport transformation or the windowing transformation.

PART – B

1. Explain in detail on two dimensional geometric transformations with suitable examples.

CONCEPTS:

Changes in orientations, size and shape are accomplished with geometric transformations that alter

the coordinate description of objects. Basic transformation

Translation T(tx, ty)

Page 5: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Translation distances Scale S(sx,sy)

Scale factors Rotation R()

Rotation angle

Translation

A translation is applied to an object by representing it along a straight line path from one coordinate

location to another adding translation distances, tx, ty to original coordinate position (x,y) to move

the point to a new position (x",y") to x’ = x + tx, y’ = y + tyThe translation distance point (tx,ty) is

called translation vector or shift vector. Translation equation can be expressed as single matrix

equation by using column vectors to represent the coordinate.

Rotations:

A two-dimensional rotation is applied to an object by repositioning it along a circular path on xy

plane. To generate a rotation, specify a rotation angle θ and the position (xr,yr) of the rotation point

(pivot

point) about which the object is to be rotated.

Scaling :

A scaling transformation alters the size of an object. This operation can be carried out for polygons

by multiplying the coordinate values (x,y) to each vertex by scaling factor Sx & Sy to produce the

transformed coordinates (x*,y*).

SIGNIFICANCE:

This concept is used to implement a object transformation,resize and rotating in different angle.

2.Explain in detail the matrix representations and homogeneous coordinates, composite

transformations.

Page 6: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Many graphics applications involve sequences of geometric transformations. Ananimation, for

example, might require an object to be translated and rotated at eachincrement of the motion. In

order to combine sequence of transformations we haveto eliminate the matrix addition. To achieve

this we have represent matrix as 3 X 3instead of 2 X 2 introducing an additional dummy coordinate

h. Here points arespecified by three numbers instead of two. This coordinate system is called

asHomogeneous coordinate system and it allows to express transformation equationas matrix

multiplication

Cartesian coordinate position (x,y) is represented as homogeneous coordinate triple(x,y,h)

Represent coordinates as (x,y,h)

Actual coordinates drawn will be (x/h,y/h)

General Pivot-point Rotation

Translate the object so that pivot-position is moved to the coordinate origin

Rotate the object about the coordinate origin

Translate the object so that the pivot point is returned to its original position

General fixed point scaling

Translate object so that the fixed point coincides with the coordinate origin

Scale the object with respect to the coordinate origin Use the inverse translation of step 1 to return

the object to its original position

3. Explain in detail the two dimensional viewing.

CONCEPT:

The viewing pipeline

A world coordinate area selected for display is called a window. An area on a display device to

which a window is mapped is called a view port. The window defines what is to be viewed the view

port defines where it is to be displayed. The mapping of a part of a world coordinate scene to device

coordinate is referred to as viewing transformation. The two dimensional viewing transformation is

referred to as window to view port transformation of windowing transformation.

Page 7: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

The viewing transformation in several steps, as indicated in Fig. First, we construct the scene in

world coordinates using the output primitives. Next to obtain a particular orientation for the window,

we can set up a two-dimensional viewing-coordinate system in the world coordinate plane, and

define a window in the viewing-coordinate system.

The viewing- coordinate reference frame is used to provide a method for setting up arbitrary

orientations for rectangular windows. Once the viewing reference frame is established, we can

transform descriptions in world coordinates to viewing coordinates.

We then define a viewport in normalized coordinates (in the range from 0 to 1) and map the

viewing-coordinate description of the scene to normalized coordinates. At the final step all parts of

the picture that lie outside the viewport are clipped, and the contents of the viewport are transferred

to device coordinates.

SIGNIFICANCE:

Changing the position of the viewport, we can view objects at different positions on the display area

of an output device.

4. Explain in detail with various clipping operations on point, line, and polygon.

CONCEPT

Point clipping

Line clipping (Straight-line segment)

Area clipping

Curve clipping

Page 8: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Text clipping

Clipping

Clip window is a rectangle in standard position. A point P=(x,y) for display, if following inequalities

are satisfied: xwmin <= x <= xwmax

ywmin <= y <= ywmax

Line Clipping

A line clipping procedure involves several parts. First we test a given line segment whether it lies

completely inside the clipping window. If it does not we try to determine whether it lies completely

outside the window . Finally if we can not identify a line as completely inside or completely outside,

we perform intersection calculations with one or more clipping boundaries.

All other lines cross one or more clipping boundaries. For a line segment with end points (x1,y1) and

(x2,y2) one or both end points outside clipping rectangle, the parametric representation could be

used to determine values of u for an intersection with the clipping boundary coordinates.

If the value of u for an intersection with a rectangle boundary edge is outside the range of 0 to 1, the

line does not enter the interior of the window at that boundary. If the value of u is within the range

from 0 to 1, the line segment does indeed cross into the clipping area. This method can be applied to

each clipping boundary edge in to determined whether any part of line segment is to displayed.

Cohen-Sutherland Line Clipping

This is one of the oldest and most popular line-clipping procedures. The method speeds up the

processing of line segments by performing initial tests that reduce the number of intersections that

must be calculated. Every line endpoint in a picture is assigned a four digit binary code called

a region code that identifies the location of the point relative to the boundaries of the clipping

rectangle.

Page 9: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

POLYGON CLIPPING

To clip polygons, we need to modify the line-clipping procedures. A polygon boundary processed

with a line clipper may be displayed as a series of unconnected line segments (Fig.), depending on

the orientation of the polygon to the clipping window.

Sutherland – Hodgeman polygon clipping:

A polygon can be clipped by processing the polygon boundary as a whole against each window

edge. This could be accomplished by processing all polygon vertices against each clip rectangle

boundary. There are four possible cases when processing vertices in sequence around the perimeter

of a polygon. As each point of adjacent polygon vertices is passed to a window boundary clipper,

make the following tests:

Page 10: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

1. If the first vertex is outside the window boundary and second vertex is inside, both the intersection

point of the polygon edge with window boundary and second vertex are added to output vertex list.

2. If both input vertices are inside the window boundary, only the second vertex is added to the

output vertex list.

3. If first vertex is inside the window boundary and second vertex is outside only the edge

intersection with window boundary is added to output vertex list.

If both input vertices are outside the window boundary nothing is added to the output list.

Curve Clipping

Curve-clipping procedures will involve nonlinear equations, and this requires more processing than

for objects with linear boundaries. The bounding rectangle for a circle or other curved object can be

used first to test for overlap with a rectangular clip window

TEXT CLIPPING

An alternative to rejecting an entire character string that overlaps a window boundary is to use

the all-or-none character-clippingstrategy. Here we discard only those characters that are not

completely inside the window .In this case, the boundary limits of individual characters are

compared to the window. Any character that either overlaps or is outside a window boundary is

clipped.

Page 11: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Exterior clipping:

Procedure for clipping a picture to the interior of a region by eliminating everything outside the

clipping region. By these procedures the inside region of the picture is saved. To clip a picture to the

exterior of a specified region. The picture parts to be saved are those that are outside the region. This

is called as exterior clipping.

SIGNIFICANCE:

A line clipping procedure involves several parts. First we test a given line segment whether it lies

completely inside the clipping window.

APPLICATIONS:

Implement clipping algorithms

Implementation of Transformations

5. Explain in detail the cohen sutherland line clipping algorithm with examples.

The Cohen–Sutherland algorithm is a computer-graphics algorithm used for line clipping. The

algorithm divides a two-dimensional space into 9 regions and then efficiently determines the lines

and portions of lines that are visible in the central region of interest (the viewport).

The algorithm includes, excludes or partially includes the line based on whether:

Both endpoints are in the viewport region (bitwise OR of endpoints = 0): trivial accept.

Both endpoints share at least one non-visible region, which implies that the line does not

cross the visible region. (bitwise AND of endpoints ≠ 0): trivial reject.

Both endpoints are in different regions: in case of this nontrivial situation the algorithm finds

one of the two points that is outside the viewport region (there will be at least one point

outside). The intersection of the outpoint and extended viewport border is then calculated

(i.e. with the parametric equation for the line), and this new point replaces the outpoint. The

algorithm repeats until a trivial accept or reject occurs.

Page 12: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

The numbers in the figure below are called outcodes. An outcode is computed for each of the two

points in the line. The outcode will have 4 bits for two-dimensional clipping, or 6 bits in the three-

dimensional case. The first bit is set to 1 if the point is above the viewport. The bits in the 2D

outcode represent: top, bottom, right, left. For example, the outcode 1010 represents a point that is

top-right of the viewport.

left central right

top 1001 1000 1010

central 0001 0000 0010

bottom 0101 0100 0110

6. Explain in detail the Mid point subdivision algorithm with example.

The strength of this algorithm over the Cohen-Sutherland algorithm is that it requires no floating

point arithmetic to find the point of intersection with the line and the clip boundary. The midpoint

subdivison algorithm clips a line by finding the endpoints of the visible portion of the line segment.

Each endpoint can be found by an identical process and given appropriate hardware, this can be done

in parallel for both endpoints.

We still use the region codes do find line segments that are trivally accepted or rejected. When a line

crosses the boundary, the midpoint is computed as follows:

Xmid = (X1+X2)/2

Ymid = (Y1+Y2)/2

Essentially we have two scenerios that can exist and they look like the following:

This algorithm wants to find the visible point of the line segment(P0P1) that is farthest from P0.

Midpoint subdivision algorithm:

Step#1: Is P1 visible? If it is, then P1 is the farthest point from P0 and the process is complete;

otherwise, it is invisible, continue.

Step#2: Is segment(P0P1) entirely invisible? If it is, then clip entire line; otherwise, continue.

Page 13: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Step#3: We will take a guess at the farthest point from P0 which is Pm (midpoint of the

segment(P0P1)). If segment(PmP1) can be trivally rejected, then go to Step#2 using segment(P0Pm);

otherwise, go to Step#2 using segment(PmP1).

What are the terminating conditions of the midpoint subdivision algorithm?

Remember that while the process is going on for segment(P0P1) and a similar process is going on

for segment(P1P0).

Problem: Given set_window(10,50,10,50) and segment(P0P1) such that P0=(20,15) and P1=(20,8),

show how the midpoint subdivision algorithm would proceed and clip the line segment(P0,P1) to the

window.

How would the midpoint subdivision algorithm handle the following case?

7. Explain in detail Liang-Barsky line clipping algorithm with example.

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.

Page 14: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

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).

o if or ignore it and go to the next edge

o otherwise classify the tvalue as entering or exiting value (using inner product to

classify)

o 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.

8. Explain in detail the widow-to-viewport coordinate transformation with pictorial representations.

Window-to-Viewport mapping is the process of mapping or transforming a two-dimensional,

world-coordinate scene to device coordinates. In particular, objects inside the world or clipping

window are mapped to the viewport. The viewport is displayed in the interface window on the

screen.

World Coordinate System - This is object space or the space in which the application

model is defined.

Screen Coordinate System - The space in which the image is displayed.

World Window (or clipping) - This is the rectangle in the world defining the region that is

to be displayed.

Page 15: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Interface Window - The window opened on the raster graphics screen in which the image

will be displayed.

Viewport - The rectangular portion of the interface window that defines where the image

will actually appear (usually the entire interface window but in some cases modified to be a

portion of the interface window).

Viewing Transformation - The process of mapping a world window in World Coordinates

to the Viewport.

Description

Window-to-Viewport mapping is the process of mapping or transforming a two-dimensional,

world-coordinate scene to device coordinates. In particular, objects inside the world or clipping

window are mapped to the viewport. The viewport is displayed in the interface window on the

screen. In other words, the clipping window is used to select the part of the scene that is to be

displayed. The viewport then positions the scene on the output device.

example

Page 16: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

Development of the Window-To-Viewport Mapping

This mapping or transformation involves developing formulas that start with a point in the world

window, say (xw, yw). The formula is used to produce a corresponding point in viewport

coordinates, say (xv, yv). We would like for this mapping to be "proportional" in the sense that if xw

is 30% of the way from the left edge of the world window, then xv is 30% of the way from the left

edge of the viewport. Similarly, if yw is 30% of the way from the bottom edge of the world window,

then yv is 30% of the way from the bottom edge of the viewport. The picture below shows this

proportionality.

Using this proportionality, the following ratios must be equal.

By solving these equations for the unknown viewport position (xv, yv), the following becomes true:

The scale factors (Sx, Sy) would be:

And the translation factors (Tx, Ty) would be:

Page 17: DHANALAKSHMI COLLEGE OF ENGINEERING, · PDF fileDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI ... Clipping in computer graphics is to remove objects, ... window boundaries or viewport

The position of the viewport can be changed allowing objects to be viewed at different positions on

the Interface Window. Multiple viewports can also be used to display different sections of a scene at

different screen positions. Also, by changing the dimensions of the viewport, the size and

proportions of the objects being displayed can be manipulated. Thus, a zooming affect can be

achieved by successively mapping different dimensioned clipping windows on a fixed sized

viewport.

If the aspect ratio of the world window and the viewport are different, then the image may look

distorted.