Application of sutherland hodgman polygon clipping, Computer Graphics

Assignment Help:

For good understanding of the application of the rules specified above see the following figure, where the shaded region demonstrates the clipped polygon.

801_Application of Sutherland Hodgman Polygon Clipping.png

Figure: Sutherland-Hodgman Polygon Clipping

Pseudo code for Sutherland - Hodgman Algorithm

Define variables

In VertexArray is the array of input polygon vertices

outVerteArray is the array of output polygon vertices

Nin is the number of entries in inVertexArray

Nout is the number of entries in outVertexArray

n is the number of edges of the clip polygon

ClipEdge[x] is the xth edge of clip polygon defined by a pair of vertices

s, p are the start and end point respectively of current polygon edge

i is the intersection point with a clip boundary

j is the vertex loop counter

Define Functions

AddNewVertex(newVertex, Nout, outVertexArray)

: Adds newVertex to outVertexArray and then updates Nout

InsideTest(testVertex, clipEdge[x])

: Checks whether the vertex lies inside the clip edge or not;

  retures         TRUE is inside else returns FALSE

Intersect (first, second, clipEdge[x])

: Clip polygon edge (first, second) against clipEdge[x], outputs the intersection point

{                                        :  begin main

x = 1

while (x ≤ n)                     : Loop through all the n clip edges

{

Nout = 0                            : Flush the outVertexArray

s = inVertexArray[Nin] : Start with the last vertex in inVertexArray

for j = 1 to Nin do             : Loop through Nin number of polygon vertices (edges)

{

p = inVertexArrray[j]

if InsideTest(p, clipEdge[x] = = TRUE then                     : Case A

and D

if InsideTest(s, clipEdge[x] = = TRUE then

AddNewVertex(p, Nout, outVertexArray)                        : Case A

else

i = Intersect(s, p, clipEdge[x])                           :  Case D

AddNewVertex(i, Nout, outVertexArray)

AddNewVertex(p, Nout, outVertexArray)

end if

else      :  i.e. if InsideTest(p, clipEdge[x] = = FALSE

(Cases 2 and 3)

if InsideTest(s, clipEdge[x]) = =TRUE then                     : Case B

{

 Intersect(s, p, clipEdge[x])

AddNewVertex(i, Nout, outVertexArray)

end if                                        : No action for case C

 

s = p                                         : Advance to next pair of vertices j = j + 1

end if                                         :  end {for}

}

x = x + 1                                     : Proceed to the next ClipEdge[x +1]

Nin = Nout

inVertexArray = outVertexArray            :  The output vertex array for the current clip edge becomes the input vertex array for the next clip edge

}                                        : end while

}                                        : end main


Related Discussions:- Application of sutherland hodgman polygon clipping

Basic structures for multimedia interactive applications, Question: (a)...

Question: (a) Sound often gives the only effective way to convey an idea, elicit an emotion, or dramatise a point. Explain two situations of the use of sound that would be con

Z- buffer algorithm, Q.   Describe the z- Buffer algorithm for hidden surfa...

Q.   Describe the z- Buffer algorithm for hidden surface removal. Ans. Z- buffer method: This method compares surface depths at each pixel position on the projection plane. T

2d shape primitives, 2D Shape Primitives You have already learnt to plo...

2D Shape Primitives You have already learnt to plot a point or a pixel on any display device. In this unit, we shall introduce you to various devices available for data input o

Image precision, what is image precision in computer graphics

what is image precision in computer graphics

Exemplify bresenham line generation algorithm by digitizing, Example: Exem...

Example: Exemplify the Bresenham line generation algorithm through digitizing the line along with end points (20, 10) and (30, 18) Solution: m =    (y2 - y1)/( x2 - x1)  =

Polygonalization of the surface, Remember in polygonalization of the surfac...

Remember in polygonalization of the surface, following rules must be followed. Any two polygons  (i)  share a common edge,   (ii)  Share a common vertext,  (iii)  Arc disj

Interactive Computer Graphics, Explain the different input modes used in in...

Explain the different input modes used in interactive computer graphics.

Horizontal retrace - hardware primitives, Horizontal Retrace - Hardware Pri...

Horizontal Retrace - Hardware Primitives Horizontal retrace refers to the time an electron beam takes to traverse a scan line.Vertical retrace means the time taken by the elect

Handling mouse input, When you set up your project, create the class as an ...

When you set up your project, create the class as an "ACM Graphics Program", rather than a plain class. This will perform the necessary preparations for you to use mouse input in y

Translate a square - 2-d and 3-d transformations, Example1: Translate a sq...

Example1: Translate a square ABCD along with the coordinates as: A(0,0),B(5,0),C(5,5),D(0,5) via 2 units in x-direction and 3 units in y-direction. Solution: We can show the

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd