You are on page 1of 5

LOVELY PROFESSIONAL UNIVERSITY

Homework Title/No. : ____3____ Course Code :____CSE(405)_______

Course Instructor : lect. Ruchika singhal Course Tutor(if applicable) :_______

Date of Allotment : Date of submission : 06th april 2011

Student’s Roll No. :__A11___ Section No. :____D1804______

Declaration :

I declare that this assignment is my individual work. I have not copied from any other student’s
work or from any other source except where due acknowledgement is made explicitly in the text,
nor has any part been written for me by another person.

Student’s Signature: PRAKASH KUMAR

Evaluator’s comments :

___________________________________________________________________________

Marks obtained :______________________ out of _________________________

Part - A

Q1. How can scaling with respect to a point P 0(.x0,y0,z0) be defined in terms of scaling with
respect to the origin?
Ans:-
Scaling about a fixed point P0(.x0,y0,z0) can be accomplished by the following:

1. Translating to origin
2. Scaling
3. Translating back to original position.
Scaling transformation w.r.t origin as:-

The equation is as:-

X’= x*sx
Y’=y*sy
Z’= z*sz
Where sx,sy,sz are scaling factors
Then the scaling transformation matrix is as-

Q2. Develop a text clipping algorithm that clips individual characters assuming that the
characters are defined in a pixel grid of a specified size.

Ans:-

Q3. Find the transformation which aligns vector V=I+J+K with the vector N=2I-J-K.

Ans:-
As given that v= i+j+k so, | v |= √ 12+ 12 + 12= √ 3
And N = 2i –j-k so, |N|= √ 22+ (-12) +(- 12)= √ 4+1+1=√ 6

Then the transformation vector matrix is as:-

AV = √ 6/ √ 3 - 1/√ 3√ 6 -1/√ 3√ 6 0
0 1/√ 6 -1/√ 6 0
1/√ 3 1/√ 3 1/√ 3 0
0 0 0 1

PART B

Q4.Draw the flowchart illustrating the concept of hodgeman Sutherland clipping algorithm, and write the
pseudocode for the same.

Ans this is the algorithm begins with an input list of all vertices in the subject polygon. Next, one
side of the clip polygon is extended infinitely in both directions, and the path of the subject polygon is
traversed. Vertices from the input list are inserted into an output list if they lie on the visible side of
the extended clip polygon line, and new vertices are added to the output list where the subject
polygon path crosses the extended clip polygon line.
This process is repeated iteratively for each clip polygon side, using the output list from one stage as
the input list for the next. Once all sides of the clip polygon have been processed, the final generated
list of vertices defines a new single polygon that is entirely visible. Note that if the subject polygon
was concave at vertices outside the clipping polygon, the new polygon may have coincident (i.e.
overlapping) edges – this is acceptable for rendering, but not for other applications such as computing
shadows.
   
All steps of clipping concave polygon 'W' by 5-sided convex polygon
The Wailer–Atherton algorithm overcomes this by returning a set of divided polygons, but is more
complex and computationally more expensive, so Sutherland–Hodgeman is used for many rendering
applications. Sutherland–Hodgman can also be extended into 3D space by clipping the polygon paths
based on the boundaries of planes defined by the viewing space.
Pseudo code
Given a list of edges in a clip polygon, and a list of vertices in a subject polygon, the following
procedure clips the subject polygon against the clip polygon.
 List output List = subject Polygon;
 For (Edge clip Edge in clip Polygon) do
    List input List = output List;
    Point S = outputList.last;
    for (Point E in output List) do
       If (E inside clip Edge) then
          if (S not inside clip Edge) then
             intputList.add (ComputeIntersection(S, E, clipEdge));
          End if
          inputList.add (E);

Q5. Perform the line clipping with the use of cohen Sutherland to clip line p1(70,20) and
p2(100,10) against a clip window lower left hand corner(50,10) and upper right hand
corner(80,40).

Ans
After clipping:

Q.6. A clipping window ABCD is specified as A(0,0), B(40,0), C(40,40) and


D(0,40) . Using the Midpoint subdivision algorithm to find the visible portion,
if any of the line segment joining the points P(-10,20) and Q(50,10).

Ans. Here for the given problem, the end point codes of point P will be 0001 and that of Q will
be 0010. Both end point codes are not zero and their logical AND are zero, hence we can
conclude that the line cannot be rejected as invisible.
Mid point is Xm= (X1+X2) /2= (50 + (-10)) /2 = 20

Ym= (Y1+Y2)/2= (10 + 20) /2 = 15 End point code for midpoint Pm(XmYm) is (0000). Neither segment
PPm nor PmQ is either totally visible or trivially invisible. Lets keep segment PPm for later processing, and
we
continue with PmQ. This subdivision process continues until we find an intersection point with window edge
i.e. (40,Y).
Table shows how the subdivision continues:
P Q Pm Comment
(-10,20) (50,10) (20,15) Save PPm & continue with PmQ
(20,15) (50,10) (35,12) continue with PmQ ,as PPm is totally visible
(35,12) (50,10) (42,11) Continue with PPm, as PmQ is totally invisible
(35,12) (42,11) (38,11) Continue with PmQ
(38,11) (42,11) (40,11) Success. This is the intersection point of line with right
window edge.
(-10,20) (20,15) (5,17) Recall saved PPm & continues with PPm , as PmQ is
totally visible.
(-10,20) (5,17) (-3,18) Continue with PmQ, as Ppm is totally invisible
(-3,18) (5,17) (1,17) Continue with PPm
 (-3,18) (1,17) (-1,17) Continue with PmQ
(-1,17) (1,17) (0,17) Success. This is the intersection point of line with left
window edge.
Hence, Visible portion of line segment PQ is from (0, 17) to (40, 11).

You might also like