Sie sind auf Seite 1von 7

Computer Graphics

Computer Graphics

CSE 405

Assignment 3

Submitted To:
Submitted By:

Ms Hardarshan Kaur
Angad Singh

RB1801B37

6
Computer Graphics

Ques1: Define 2D Clipping. List various types of Clipping.


Ans1: Procedure that identifies that portion of a picture that are either inside
or outside of a specified region of space is referred to as a clipping.
Types of clipping are:
• Line clipping.
• Point clipping
• Polygon clipping
• Text clipping
• Exterior clipping.

Ques2: Cohen-Sutherland Algorithm is used for what purpose.


Explain it
Ans2: It is a line clipping algorithm. The algorithm divides a 2D space into 9
regions, of which only the middle part (viewport) is visible. In case of this non
trivial situation the algorithm finds one of the two points that are outside the
viewport region (there will be at least one point outside). The intersection of
the outer point and extended viewport border is then calculated (i.e. with the
parametric equation for the line) and this new point replaces the outer point.
The algorithm repeats until a trivial accepts or reject occurs.
• It is not the most efficient algorithm
• It is one the most commonly used
• The key technique is 4-bit code:

TBRL where
• T is set (to 1) if y > top
• B is set (to 1) if y < bottom
• R is set (to 1) if x > right
• L is set (to 1) if x < left

Window Region

Algorithm

6
Computer Graphics

• Assume two endpoints are p0 and p1


• If code(p0) OR code(p1) is 0000,the line can be trivially accepted, the
line is drawn
• If code(p0) AND code(p1) is NOT 0000,the line can be trivially rejected,
the line is not drawn at all
• Otherwise, compute the intersection points of the line segment and
window boundary lines(make sure to check all the boundary lines)

Ques3: Differentiate between Sutherland-Hodgeman Clipping


Algorithm and Weiler Atherton Clipping Algorithm.
Ans3: Sutherland and Hodgman’s polygon-clipping algorithm uses a divide-
and-conquer strategy: It solves a series of simple and identical problems
that, when combined, solve the overall problem. The simple problem is to clip
a polygon against a single infinite clip edge. Four clip edges, each defining
one boundary of the clip rectangle, successively clip a polygon against a clip
rectangle. There are four Cases of polygon clipping against one edge. The
clip boundary determines a visible and invisible region. The edges from
vertex i to vertex i+1 can be one of four types:
Case 1: Wholly inside visible region – save endpoint
Case 2: Exit visible region – save the intersection
Case 3: Wholly outside visible region – save nothing
Case 4: Enter visible region – save intersection and endpoint

Weiler Atherton Clipping


In this technique, the vertex-processing procedures for window boundaries
are modified so that concave polygons are displayed correctly. This clipping
procedure was developed as a method for identifying visible surfaces, and so
it can be applied with arbitrary polygon-clipping regions. The basic idea in
this algorithm is that instead of always proceeding around the polygon edges
as vertices are processed, we sometimes want to follow the window
boundaries. Which path we follow depends on the polygon-processing
direction(clockwise or counterclockwise) and whether the pair of polygon
vertices currently being processed represents an outside-to-inside pair or an
inside-to-outside pair. For clockwise processing of polygon vertices, we use
the following rules:
• For an outside-top inside pair of vertices, follow the polygon boundary
• For an inside-to-outside pair of vertices, follow the window boundary in
a clockwise direction

Ques4: Differentiate between 2-D Transformation and 3-D


Transformation
Ans4: 2D is 'flat', using the X & Y (horizontal and vertical) axis', the image
has only two dimensions and if turned to the side becomes a line.
Transformations are a fundamental part of computer graphics.

6
Computer Graphics

Transformations are used to position objects, to shape objects, to change


viewing positions, and even to change how something is viewed.
There are 4 main types of transformations that one can perform in 2
dimensions:
• Translation
• Shearing
• Rotation
• scaling

The 3D transformation matrix A is a 3*3 matrix:


A ={ a1 a2 a3 }= a11 a12 a13
a21 a22 a23
a31 a32 a33
The linear map, which takes a vector v in the [e1; e2; e3] system to a vector
^v in the [a1; a2; a3] system, has the form ^v = Av. Therefore,
e1 -> a1 e2 -> a2 e3 -> a3:
One measure of the behavior of a linear map is the determinant of the matrix
A, or jAj. In 3D the determinant measures the volume of the parallelepiped
formed by the ai vectors (positioned at the origin). One other difference
between 2D and 3D transformations: rotations
are not commutative in 3D.

3D Linear Maps
1: Scaling
A = {s11 0 0
0 s22 0
0 0 s33}
therefore
|A| = s11s22s33

2:Refection
A = {+-1 0 0
0 +-1 0
0 0 +-1}
such that |A| = -1

Ques5: Explain general pivot point rotation, scaling in both 2-D and
3-D transformation

Ans5: To generate a rotation, we specify a rotation angle and the position P


when the pivot point in at the coordinate origin. In figure r in the constant
distance of the point from the origin, angle φ in the original angular position
of the point from the horizontal and θ in the rotation angle. Using standard

6
Computer Graphics

trigonometric identifies, we can express the transformed coordinates in


terms of angles θ and φ as

We can control the location of a scaled object by choosing a position, called


the fixed
point.that is to remain unchanged after the scaling transformation. Co-
ordinate for the
fixed point(Xf,Yf) can be chosen as one of the vertices,the object centroid, or
any other
position.

Ques 6:expain window to view port transformation. Explain with the


help of diagram

Ans6: A world coordinate area selected for display is called a window. An


window defines what is to displayed. An area on the display device to which a

6
Computer Graphics

window is mapped is called a viewport.


An view port defines where is to be displayed

Window to view port transformation:

We want to map a point from WDC to Ndc, as shown below:

We can see from above that to maintain relative position we must have the
following relationship:

Xw - Xwmin Xv - Xvmin
---------------- = ---------------------
Xwmax - Xwmin Xvmax - Xvmin
Yw - Ywmin Yv - Yvmin
---------------- = ---------------------
Ywmax - Ywmin Yvmax - Yvmin

We can rewrite above as

Xv = [(Xvmax - Xvmin)/(Xwmax - Xwmin)] * (Xw - Xwmin) + Xvmin


= Sx * (Xw - Xwmin) + Xvmin = Sx * Xw + Cx

where Sx = (Xvmax - Xvmin)/(Xwmax - Xwmin)


Cx = Sx * (- Xwmin) + Xvmin

Similarly for Y

Yv = [(Yvmax - Yvmin) / (Ywmax - Ywmin)] * (Yw - Ywmin) + Yvmin


= Sy * (Yw - Ywmin) + Yvmin = Sy * Yw + Cy

6
Computer Graphics

Note that Sx, Sy are "scaling"


factors.

If Sx = Sy the objects will


retain same shape, else will
be distorted, as shown in the
example.

Das könnte Ihnen auch gefallen