1.How can scaling with respect to a point P0(.x0,y0,z0) be defined in terms of scaling with respect to the origin? Scaling Scaling refers to enlarging or shrinking the size of vector components along axis directions. For example, a vector can be scaled up | along all directions or scaled down along the X axis only. To scale, we usually apply the scaling matrix below: a 0 0 0 0 b 0 0 0 0 c 0 0 0 0 1 Where p, q, and r are the scaling factor along the X, Y, and Z direction, respectively. The figure below shows the effect of scaling | by 2 along the X axis and scaling by 0.5 along the Y axis. 2.Obtain the matrix to align the vector V=I+J+K with the vector K. V=ai+bJ+cK=I+J+K |V|=βπ2 +π 2 + π 2 =β12 + 12 + 12 =β3 Ξ»=βπ 2 + π 2 =β12 + 12 =β2 β2 β3 Av = 1 0 β3 β1 1 1 β2 β3 β3 β3 0 β1 β1 1 β2β3 β2 β3 0 0 0 0 0 1 3.Find the transformation which aligns vector V=I+J+K with the vector N=2I-J-K. Ans : Av.N=π. πβπ .AV Finding AV Here |V|=β3 Ξ=β2 a=1,b=1,c=1 Then β2 β3 Av = 1 0 0 β3 β1 1 1 β2 β3 β3 β3 0 β1 β1 1 β2β3 β2 β3 0 0 0 0 1 π. πβπ according to Q. GIVEN N=2I-J-K. β22 + 12 + 12 =β6 Ξ»=β2 ,a=2,b=1,c=1 π¨βπ v = β2 2 2 β6 β2β6 β6 0 1 β1 β2 β6 2 β1 β6 β2 0 0 β1 β6 0 0 0 0 1 Vβ= Av.N.V=π¨βπ v Av .v = β2 πΌ β β2 π½ 2 β β2 β6 πΎ THEN 2 Vβ=β2 π PART B 4.Draw the flowchart illustrating the concept of hodgeman Sutherland clipping algorithm, and write the pseudocode for the same. Ans : An algorithm that clips a polygon must deal with many different cases. The case is particularly note worthy in that the concave polygon is clipped into two separate polygons. All in all, the task of clipping seems rather complex. Each edge of the polygon must be tested against each edge of the clip rectangle; new edges must be added, and existing edges must be discarded, retained, or divided. Multiple polygons may result from clipping a single polygon. We need an organized way to deal with all these cases. The following example illustrate a simple case of polygon clipping. 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.a Note the difference between this strategy for a polygon and the Cohen-Sutherland algorithm for clipping a line: The polygon clipper clips against four edges in succession, whereas the line clipper tests the outcode to see which edge is crossed, and clips only when necessary. Steps of Sutherland-Hodgman's polygon-clipping algorithm ο· ο· ο· ο· Polygons can be clipped against each edge of the window one at a time.Windows/edge intersections, if any, are easy to find since the X or Y coordinates aralready known. Vertices which are kept after clipping against one window edge are saved for clipping against the remaining edges. Note that the number of vertices usually changes and will often increases. We are using the Divide and Conquer approach. 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 Pseudo-Code of Sutherland and Hodgman's polygon-clipping Algorithm. type vertex = point; /*point hold real x,y*/ edge = array[1..2] of vertex; vertexArray = array[1..MAX] of vertex; /*MAX is a declared constant*/ procedure SutherlandHodgmanPolygoClip ( inVertexArray : vertexArray; /*Input vertex array*/ var outVertexArray : vertexArray; /*Output vertex array*/ inLength : integer; /*Number of entries in inVertexArray*/ var outLength : integer; /*Number of entries in outVertexArray*/ clipBoundary : edge); /*Edge of clip polygon*/ var s,p, /*Start, end point of current polygon edge*/ i : vertex; /*Intersection point with a clip boundary*/ j : integer; /*Vertex loop counter*/ procedure Output( newVertex : vertex; var outLength : integer; var outVertexArray : vertexArray); /*Adds newVertex to outVertexArray and then updates outLength */ begin ... end; function Inside(testVertex : vertex; clipBoundary : edge):boolean; /*Checks whether the vertex lies inside the clip edge or not*/ begin ... end; procedure Intersect(first,second:vertex; clipBoundary:edge; var intersectPt:vertex); /*Clips polygon edge (first,second) against clipBoundary, outputs the new point*/ begin ... end; begin outLength := 0; s := inVertexArray[inLength]; /*Start with the last vertex in inVertexArray*/ for j := 1 to inLength do begin p := inVertexArray[j]; /*Now s and p correspond to the vertices in Fig. 3.48*/ if Inside(p,clipBoundary) then /*Cases 1 and 4*/ if Inside(s, clipBoundary) then Output(p, outLength, outVertexArray) /*Case 1*/ else begin Intersect(s, p, clipBoundary, i); Output(i, outLength, outVertexArray); Output(p, outLength, outVertexArray) end else /*Cases 2 and 3*/ if Inside(s, clipBoundary) then /*Cases 2*/ begin Intersect(s, p, clipBoundary, i); Output(i, outLength, outVertexArray) end; /*No action for case 3*/ s := p /*Advance to next pair of vertices*/ end /*for*/ end; /*SutherlandHodgmanPolygonClip*/ 6.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 : using Cohen-Sutherland Algorithm Bit 1: Above Bit 2: Below Bit 3: Right Bit 4: Left Out code (p1 )=0000 Outcode (p2)=0010 AND for p1 and p2 is 0000 This is partially visible Here second bit is 1 .it means P2 IS outside the window as point p2 is Outside the window so We have line P2C will be discard (A) (b) Now our line will be P1C OUTCODE (P1)=0000 OUTCODE (C)=0000 Result of logical AND is 0000 X or Y value definingclip window edge m = (y2 β y1) / (x2 β x1); m=(100-70)/(10-20)= -3 newy = y1 + m*(xwmin β x1) findig slop for p1C M=y-y1/x-x1; Y=y1+m*(x-x1); Y=20+(-3)*(80-70) Y=20-30=-10 POINT for c (80,-10) (Y1=20,Xmx =80) 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 :THE outcode of p=0001 Outcode for Q=0010 Logical AND of P &Q is 0000 So they are partially visible Using Midpoint subdivision algorithm Xnew =(50+(-10)/2=20; Ynew=(10+20)/2=15; Now P1(20,15) MID between P1 & Q Xn= (50+20)/2=35 Yn =10+15)=12 POINT P2 are (35 ,12) SUBDIVISION MID POINT S SEGMENT ISENTO OF FURTHER SUBDIVISION 1 2 3 4 5 6 7 8 9 10 (20,15) (35,12) (42,11) (38,11) (40,11) (5,17) (-3,18) (1,17) (-1,17) (0,17) (-10,20) to (50,10) (20,15) to (50,10) (35,12) to (50,10 (35,12) to (42,11) (38,11)TO(42,11) 10,20) to (20,15) .(-10,20)to (5,17) (-3,18) to (5,17) (-3,18) to (1,17) So The Visible portion of line segment P& Q is from (0, 17) to(40, 11). **********************Thanks**********************
© Copyright 2025 Paperzz