Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

1|Page

Chapter 5: Windows and Viewports and clipping algorithms

“The process of selecting and viewing an image with different views, called windowing.” All the
objects in the real world have a size. We can measure the size and location of an object by the
unit.

For Example-We use the meter unit to measure both size and the location of the object.  

When we represent the image of an object on the screen, then we use the screen coordinate
system. The screen coordinate system is used to define the location of the object. When we select
the screen coordinate system, then the image can be displayed on the screen. “The Capability to
show some part of an object in a window is known as windowing.” “The rectangular area
describes in the world coordinate system is called the window.”

Viewport:

“The viewport can be defined as an area on the screen which is used to display the object.” The
window is an area space for the object. Viewport surrounds the object. We need the coordinate
transformation to display the object on the screen. We can define many viewports on a different
area of the screen and also see the same object from a different angle in the viewport.

Window to Viewport transformation:

“Window to viewport transformation is a process of converting two-dimensional or world into a


device coordinate.”

The object inside the clipping window is mapped to the viewport. The viewport is displayed
inside the interface window on the screen. We can use the clipping window to select the part of
an object, and the viewport is used to display the selected part of the object on the screen or
output device.

CPU College Computer Graphics Chapter 5


2|Page

Steps for Window to Viewport Transformation: We can follow the following steps for
transform window to viewport:

Step 1: Translation of the window towards the Origin- If we shift the window towards the
origin, the upper left, and the lower-left corner of the window will be negative (-). The
translation factor also should be negative (-).

Step 2: Resize the window to viewport size- To Convert the size of the window into the size of
the viewport, we will use the following formulas:

 Sx =   XVmax – XVmin / XWmax – XWmin
 Sy =   YVmax – YVmin / YWmax – YWmin

Step 3: Translation of window (Position of window and viewport must be same)- If the
lower-left corner of viewport is (0, 0), then the window lower-left corner is already shifted on
origin after following step 1.

If the lower-left corner is not equal to (0, 0), then the translation factor should be positive (+).

It may be possible that sometimes the size of viewport is greater or smaller than the window. In
that situation, we have to enlarge or compress the size of the window according to the
viewport. We can perform it using some mathematical calculations.

A point on window = (XW, YW)

CPU College Computer Graphics Chapter 5


3|Page

Corresponding point on viewport = (XV, YV)

 To calculate (XV, YV) –

Normalized point on window = (XW- XWmin / XWmax - XWmin)

                                                    (YW- YWmin / YWmax - YWmin)

Normalized point on viewport = (XV- XVmin / XVmax - XVmin)

                                                     (YV- YVmin / YVmax - YVmin)

Now, the position of object in viewport and window are same-

For Coordinate x:

(XW- XWmin / XWmax - XWmin) = (XV- XVmin / XVmax - XVmin)

For Coordinate y:

(YW- YWmin / YWmax - YWmin) = (YV- YVmin / YVmax - YVmin)

Now, we get

XV = XVmin + (XW- XWmin) Sx

YV = YVmin + (YW- YWmin) Sy

Here Sx and Sy are the scaling factor for x and y coordinate.

  Sx =   XVmax – XVmin / XWmax – XWmin

 Sy =   YVmax – YVmin / YWmax – YWmin

Some Important Points:

1. We can select the world coordinate system according to the application program.

2. We can select the screen coordinate system according to the desired design.

3. Viewing transformation is a connection between the world and the screen coordinates.

Advantages:

We can easily represent images on the display screen according to the user’s needs.

CPU College Computer Graphics Chapter 5


4|Page

Numerical exercise

1. Find normalization transformation that maps a window whose lower-left corner is at (1,1)
and upper right corner is at (3,5) onto:
A. Viewport with lower-left corner (0,0) and upper right corner (1,1)
B. Viewport with lower left corner (0,0) and upper right corner (1/2,1/2)

wxmin=1, wymin=1 , wxmax=3, wymax=5

a) vxmin=0 , vymin=0

Also, vxmax=1, vymax=1

b) vxmin=0, vymin=0

Also, vxmax=1/2 , vymax=1/2

a) Sx = (vxmax– vxmin) / (wxmax– wxmin) , Sy = ( vymax– vymin) / (wymax– wymin)

While, Putting the values:

Sx = 1-0/3-1 = 1/2 ,

Sy=1-0/5-1 = ¼

b) Sx = (vxmax– vxmin) / (wxmax– wxmin), Sy = ( vymax– vymin) / (wymax– wymin)

While, Putting the values:

Sx = (1/2-0)/3-1 = (½)/2 = 1/4

CPU College Computer Graphics Chapter 5


5|Page

Sy=(1/2-0)/5-1 = (1/2)/4 = 1/8

Panning

“Panning is a process or photographic technique that is used to combine slow shutter speed with
camera movement to make a speed sense around the moving object.”

We can define panning as a way to keep the main object in focus and blurring the background.
The word panning is derived from ‘panorama’ that indicates a broad view. In other words,
panning is a device used for constantly exposing and including off-screen space into the image.

If we talk about video technology, Panning is defined as horizontal scrolling of pictures expand
over the display. In 3D modeling, panning is referred as the parallel moving to view plane. The
camera moves perpendicular to the pointed direction. The image captured by the panning camera
is known as a panning shot.

CPU College Computer Graphics Chapter 5


6|Page

Fig: An Example of Panning shot

Advantages of Panning

There are following advantages of Panning:

 Shots become more dynamic through panning.


 It helps to track the movement of the subject.
 It provides a more expensive feel to viewers.

Inking:

“When we sample a graphical input device’s location at regular intervals and represent a point at
each sampled position, then a measure of the device’s motion will be shown. This technique is
sharply producing drawing on the paper, called inking.”

Use of inking:

 It is used for online character- recognition programs.

CPU College Computer Graphics Chapter 5


7|Page

 It helps to draw sketches, tattoos, etc.

Zooming Effect

Zooming Effect is Successively mapping different sized windows on a fixed size viewport. As
the windows are made smaller, so we zoom in on some part of a scene to view details that were
not visible in large windows. Also, We can obtain more overview by zooming out from a section
of a scene with successively larger windows.

CPU College Computer Graphics Chapter 5


8|Page

Clipping
“The Clipping is a type of transformation used in computer graphics to remove lines, objects,
and segments of lines that are outside the computer screen or viewing pane.” The clipping is a
process of deciding the visible and invisible part of the image, object, or any line segment.

We only select the visible part and remove the invisible part of the line. The process clipping can
be used in two-dimensional and three-dimensional graphics.

Clipping in two-dimensional (2D) Graphics

We can also describe clipping in two-dimensional graphics. In the two-dimensional graphics


system, the clipping is a process in which all pixels of an image lie inside the boundary of view
pane (window). We can also control pixel rendering to make creative and functional clip area.

Clipping in three-dimensional (3D) Graphics

In three-dimensional graphics, we can use the term clipping in many ways to define various
features. The clipping is a term that describes some operations that work in a three-dimensional
plane with rectangular shapes. We can extend the clipping to higher dimensionality. We can use
various methods and algorithms to increase the dimensionality of clipping.        

Applications of clipping

We can use clipping for drawing operations.

 It is used for separating the important part of an image.

 The Solid modeling technique in clipping helps to build three-dimensional objects.

 We can perform various operations that correlate with the pointing of an object. For
example, delete, copy, insert, and moving selected parts of an object, etc.

 Clipping helps us to describe the visible and invisible parts of 3D objects.  

Types of lines
The lines are divided into three types.
 Visible Line: The line lying inside the view pane, is a visible line.
 Invisible Line: The line lying outside the view pane, is an invisible line.

CPU College Computer Graphics Chapter 5


9|Page

 Clipped Line: “A line that lies inside or outside the window is called clipped line.” A
point where the line cut the view pane is known as the Intersection point of the line
Examples of Lines
There are some figures given below that represents the types of line.

We can use the clipping process with world coordinates. The object and images in view pane can
be mapped to device coordinates.                     

CPU College Computer Graphics Chapter 5


10 | P a g e

Types of clipping
We can divide clipping into following types-
1. Line clipping 3. Text clipping 5. Curve clipping
2. Point clipping 4. Exterior Clipping 6. Polygon clipping

Line Clipping in Computer Graphics


The line clipping is a process in which we can cut the part of the line, which lies outside
the view pane. Only those lines are visible, which lie inside the view pane.   
The line clipping process is implemented by following line clipping algorithms-

 Cohen Sutherland Line Clipping Algorithm


 Liang-Barsky Line Clipping Algorithm
 Midpoint Subdivision Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm


This algorithm was named by “Danny Cohen” and “Ivan Sutherland.”
The algorithm will work in the following steps:

 In this algorithm, we will divide the view pane into nine equal segments (as shown in the
below figure) that only serve the viewport.

 Now, we will represent the top, bottom, left, and right corner of the window with 4 bits.
This 4bit can be described with the following point that:
 If an object lies within any particular corner position, that corner value will be 1, else it
will be 0.
 The allocation of bits depends on “TBRL” (Top, Bottom, Right, Left) rule.
 Suppose, if the point of a line appears in the top-left corner, then according to TBRL, the
value is 1001. We will allot the bits as-
 For the top corner, because the object is present at the top corner.
 For the bottom corner, because the object does not lie at the bottom.
 For the right corner, because the object does not lie at the right side.
 For the left corner, because the object lies at the top-left corner.
 In this way, we check TBRL for each segment and allot the bits accordingly.  

CPU College Computer Graphics Chapter 5


11 | P a g e

In Cohen- Sutherland Algorithm we will divide the lines into following Sections-

 Visible Line: When both points (starting and ending) of the line are entirely situated
inside the window.
 Invisible Line: When both points (Starting and ending) of the line are completely
situated outside the window.    

If we have (xmin, xmax) and (ymin, ymax) coordinates of the view pane (window).
Then, it should be described as-
x0, x1 > xmax
y0, y1 > ymax
x0, x1 < xmin
y0, y1 < ymin

 Clipped Line: Every line has two endpoints. Let (x0, y0) and (x1, y1) are points of the line. If
one point of the line situated inside the window and the other one is outside the window, then
the line is known as Clipped Line.

CPU College Computer Graphics Chapter 5


12 | P a g e

Algorithm of Cohen-Sutherland Line Clipping:


Step 1: Assign the bit code for both endpoints of the line.
Step 2: Now,implement OR operation on both endpoints of the line.
Step 3: If the OR = 0000,
             Then
                       {The line is acceptable (Visible)}
             Else
                        {Implement AND operation on endpoints}
              Then
                        If AND != 0000
              Then  
                        {The line is not acceptable (Invisible)}
               Else
                          AND = 0000
                            {The line needs to be clip}               
Step 4: If a line needs to be clipped, first find an intersection point of all boundaries with the
following formula-
                m = (y1-y0) (x1-x0)
Step 4.1: When the line intersects the left side boundary of the window port.
                y0 = y1+ m(x-x1)
               Here x = xwmin (Minimum value of x coordinate)  
Step 4.2: When the line intersects the right-side boundary of the window port.
                y0 = y1+m(x-x1)
               Here x = xwmax (Maximum value of x coordinate)
Step 4.3: When the line intersects Top side boundary of the window port.      
                x0 = x1+(y-y1)/m                    
                Here y = ywmax (Maximum value of y coordinate)
Step 4.4: When the line intersects the bottom side boundary of the window port.                       
                 x0 = x1+(y-y1)/m
                 Here y = ywmin (Minimum value of y coordinate)

CPU College Computer Graphics Chapter 5


13 | P a g e

Example: In the below-mentioned example, we have different lines. The different


category of the line-

 Line AB is a clipped case.


 The line CD is completely visible.
 Line EF is completely invisible.
 Line GH is a clipped case.
 Line KL is completely invisible.
 Line IJ is a clipped case.
 The endpoints of lines are lies as follows-
o A ? 0000 o E ? 0100 o I ? 0000
o B ? 1010 o F ? 0100 o J ? 0010
o C ? 0000 o G ? 0001 o K ? 1000
o D ? 0000 o H ? 0000 o L ? 1000

Liang-Barsky Line Clipping Algorithm:

The algorithm was introduced by “You-Dong Liang” and “Brian A. Barsky.” It is used for line
clipping. It is a more powerful algorithm than the Cohen-Sutherland algorithm.
We use the following concepts in this algorithm-

 We can use the parametric equation of line and inequalities.

CPU College Computer Graphics Chapter 5


14 | P a g e

 These are used to describe the range of windows to find out the intersection points
between the line and the clipping window.
 The parametric line is also known as “Cyrus-Beck.”

In this algorithm, we have to find the intersection point based on a time interval.  
Time interval (t) can be defined as travelling time between initial position (0) to final
position (1). Then we have,
0 < t < 1 (Here, t lies between 0 and 1)
We have the formula to find x and y points of the line-
 x= x1 + t. ?x (For point x)
 y= y1 + t. ?y (For point y)
To check that the point lies between the window or outside the equation is-
 Xwmin <= x1 + t. ?x <= Xwmax
 Ywmin <= y1 + t. ?y <= Ywmax
These two conditions can be written as-
 x1 + t. ?x >= Xwmin
 x1 + t. ?x <= Xwmax
 y1 + t. ?y >= Ywmin
 y1 + t. ?y <= Ywmax
We can take a common expression for above four conditions. It will be-
 t.pk <= qk (Here the value of k is multiple)
 t = qk / pk
o p1 = -?x                   q1 = x1 - xwmin (For left boundary)
 p2 = ?x                     q2 = xwmax - x1 (For right boundary)
 p3 = -?y                    q3 = y1 - ywmin (For bottom boundary)
 p4 = ?y                     q4 = ywmax – y1(For top Boundary) 

Algorithm of Liang-Barsky Line Clipping:

Step 1: Set the endpoints of the line (x1, y1) and (x2, y2).

CPU College Computer Graphics Chapter 5


15 | P a g e

Step 2: Calculate the value of p1, p2,p3, p4 and q1, q2, q3,q4.


Step 3:  Now we calculate the value of t
               t1 = 0 (For initial point)
               t2 = 1 (For final point)
Step 4: Now, we have to calculate the value of pk and qk
             If  
                    pk = 0
             then
                    {The line is parallel to the window}
              If
                     Qk < 0
               then
                       {The line is completely outside the window}
Step 5: If we have non zero value of pk -
If
                    

                     pk < 0
           then
                     t1 = max (0, qk / pk)
            If  
                     pk > 0
            then             
                      t2 = min (1, qk / pk)
Now, if t1 < t2 {If t1 value is changed
                         Then the first point is outside the window.
                                 If t2 value is changed
                          Then the second point is outside the window}
        else
                t1 > t2
        then
                 {Line is completely outside the window}
Step 6: Stop.

CPU College Computer Graphics Chapter 5


16 | P a g e

Example: Let a rectangular window size with (5, 9). The points of the line are (4, 12) and
(8, 8). Use the Liang- Barsky algorithm to clip the line and find the intersection point.   
Solution:
We have, The initial point of the line (p1) = (4, 12)
The ending point of the line (p2) = (8, 8)
 x1 = 4, x2 = 8
 y1 = 12, y2 = 8
xwmin = 5, xwmax = 9
ywmin = 5, ywmax = 9
Step 1: We have to calculate the value of ?x and?y-
              ?x = x2- x1= 8-4 = 4
              ?y = y2- y1= 8-12 = -4
Step 2: Now, we will calculate-
                p1 = -4              q1 = 4-5 = -1
                p2 = 4                q2 = 9-4 = 5
                p3 = 4                q3 = 12-5 = 7
                p4 = -4               q4 = 9-12 = -3
Step 3: Now we will calculate t1 value-
          If p1, p4 < 0
          Then t1 =max (0, qk /pk)
                     =max (0, q1 /p1, q4 /p4)
              =max (0, 1/4, 3/4)
           t1 = 3/4
If p2, p3 > 0
Then t2 = min (1, qk /pk)
            = min (1, q2 /p2, q3 /p3)
            = min (1, 5/4, 7/4)
         t2 = 1
Step 4: Now, we have to calculate the intersection point.
           x = x1 + t1. ?x= 4+ 3/4 * 4 = 7
                 y = y1 + t1. ?y= 12+ 3/4 *(-4) = 9
The coordinates intersection point = (7, 9)

CPU College Computer Graphics Chapter 5


17 | P a g e

Midpoint Subdivision Line Clipping Algorithm:


The midpoint subdivision algorithm is used to clip the line. The algorithm is based on finding the
midpoint of the line. We can divide the line into two equal parts. There should be following
categories of the line-
 Visible line  
 Invisible line
 Partially visible
We can calculate the midpoint of the line by the following formula-

pm = (p1 + p2)/2


Algorithm Midpoint Subdivision Line Clipping:

Step 1: Assign the bit code for both endpoints of the line.
Step 2: Now, implement OR operation on both endpoints of the line.
Step 3: If the OR = 0000,
             Then
                       {The line is Visible}
             Else
                        {Implement AND operation on endpoints}
              Then
                        If AND ? 0000
              Then  
                        {The line is Invisible}
               Else

CPU College Computer Graphics Chapter 5


18 | P a g e

                          AND = 0000


                            {The line is the partially visible}
Step 4:  For partially visible line, we need to find the midpoint.
              Xm = (x1 + x2)/2 (For x coordinate)            
              Ym = (y1 + y2)/2 (For y coordinate)
Step 5: Weneed to check that the line is near to the boundary of the window or not.
Step 6: If the line is visible or invisible, then repeat steps 1 to 5.
Step 7: Stop.

Example: A window contains the size (0, 50, 0, 50). A line PQ has the coordinates (-10, 40) and
(30, -20). Find the visible point of the line using midpoint subdivision.

Solution: We have,
The coordinates for x and y = P (-10, 40)
The coordinates for x and y = Q (30, -20)
Now,
Step 1: We have to compute the midpoint of the line segment PQ.
Q = [(-10 + 30) /2, (40 - 20)/2]
    = (10, 10)
Now the new coordinates of Q = (10, 10)
Step 2: Now, we will find
Q’’ = midpoint of the Q’ and Q
Q’’ = [(10 + 30) /2, (10 + (-20))/2]  
       = (20, -5)
Now the new coordinates of Q’’ = (20, -5)
Here (20, -5) is much better than (10, 10)
Now we have to find Q’’’ then,
Q’’’ = [(20 + 30) /2, (-5 + (-20))/2]
        = (25, -12.5)
Now the new coordinates of Q’’’ = (25, -12.5)
We can clip the line from Q’’ to Q from the top side.
Step 3: Now, we will take left hand side part. The endpoints are P and Q’’’
We will find the midpoint of P and Q’’’
P (-10,40) and Q’’’ (25, -12.5)
P’ = [(-10 + 25) /2, (40 + (-12.5))/2]

CPU College Computer Graphics Chapter 5


19 | P a g e

    = (7.5, 27.5)


Now we will find the midpoint of P and P’’
P (-10, 40) and P’ (7.5, 27.5)
P’’ = [(-10 + 7.5) /2, (40 + (27.5))/2]
      = (-1.25, 33.75)
Now we will find midpoint of P’’ and P
P’’’ = P (-10, 40) and P’’ (-1.25, 33.75)
       = [(-10 + (-1.25)) /2, (40 + 33.75)/2]
        = (5.62, 36.87)
Now we will clip the line from P to P’’’
Finally, we have P’’’ = (5.62, 36.87)
                            Q’’’ = (25, -12.5)

Point Clipping
“Point clipping is a process which is used to define the point position.” The point is either inside
the view pane (window) or outside the view pane.
In computer graphics, the computer screen work like a two-dimensional coordinate system. Each
point does not need to be displayed inside the computer screen.
It includes two terms-
 Window: It means what to display?
 Clipping: It means discarding the portion that is outside the window.
Example: Let us have a view pane (window). The coordinates of the window are-
(xwmax, xwmin) - For X-axis of the window

CPU College Computer Graphics Chapter 5


20 | P a g e

(ywmax, ywmin) - For Y-axis of the window    


Let us assume a point coordinate (P, Q). If the point lies inside the window, then there is no need
to perform point clipping. But if the point lies outside the window, we need to perform clipping.
We can understand it by the following equation-
 xwmax <= P <= xwmin
 ywmax <= Q <= ywmin
There are four conditions; if these four are satisfied, then the point lies inside the window. If
anyone condition is not satisfied, then the point lies outside the window, it means we have to
perform clipping on the point.
xwmin <= P ywmin <= Q
xwmax => P ywmax => Q

Algorithm of Point Clipping:


Step 1: First, we set the value of xwmin and xwmax coordinates for the window.
Step 2: Now, set the coordinates of a given point (P, Q).
Step 3: Now check the above mention condition.
Step 4: If
                 Point coordinates lie between the (xwmin, xwmax) and (ywmin, ywmax)
            Then
                  {Display the point in the view pane}    
            Else
                  {Remove the point}
Step 5: Stop.

CPU College Computer Graphics Chapter 5


21 | P a g e

Polygon Clipping
“A Polygon can be described as the enclosed collection or group of the lines.”
In a polygon, all lines are connected. Lines can be a combination of edges and vertices, which
together form a polygon. A polygon refers to a two-dimensional architecture made up of a
number of straight lines.
Some Examples of the polygon:
1. Triangles 3. Hexagons
2. Pentagons 4. Quadrilaterals
The polygon’s name defines how many sides the architecture contains.
Triangle: It has three sides.

Pentagon: A pentagon has five sides.


Hexagon: It contains six sides.
Quadrilaterals: It contains four sides.
Types of Polygons
There are two basic types of polygons-
1. Concave Polygon
2. Convex Polygon
Concave Polygon: The concave polygon does not have any part of its diagonals in its exterior.
In a concave polygon, at least one angle should be greater than 180° (angle >180°). 

CPU College Computer Graphics Chapter 5


22 | P a g e

Convex Polygon: The convex polygon has at least one part of diagonal in its exterior. In a
convex polygon, all the angles should be less than 180° (angle<180°). 

Polygon Clipping
Polygon clipping is a process in which we only consider the part which is inside the view pane
or window. We will remove or clip the part that is outside the window. We will use the following
algorithms for polygon clipping-
 Sutherland-Hodgeman polygon clipping algorithm
 Weiler-Atherton polygon clipping algorithm
Sutherland-Hodgeman polygon clipping algorithm
The polygon clipping algorithm deals with four different clipping cases. The output of each case
is input for the next case.
Case1) Left clip: In the left side polygon clipping, we only remove the left part of the polygon,
which is outside the window. We only save the portion which is inside the window.

Case2) Right clip: In the right-side polygon clipping, we only remove the right part of the
polygon, which is outside the window. We only save the portion which is inside the window.

CPU College Computer Graphics Chapter 5


23 | P a g e

Case3) Top clip: On the top side polygon clipping, we only remove the top part of the polygon,
which is outside the window. We only save the portion which is inside the window.

Case4) Bottom clip: In the bottom side polygon clipping, we only remove the bottom part of the
polygon, which is outside the window. We only save the portion which is inside the window.

There should be the following conditions while we clip a polygon.


Condition 1(Out-In): If the first vertex of the polygon is outside and the second vertex is inside
the window, then the output will be the intersection point and second vertex.

CPU College Computer Graphics Chapter 5


24 | P a g e

Condition 2(In-Out): If the first vertex of the polygon is inside and the second vertex is outside
the window, then the output will be the intersection point.

Condition 3(In-In): If both vertices of the polygon are inside the window, then the output will
be the second vertex.

Condition 4(Out-Out): If both vertices of the polygon are outside the window, then the output
will be nothing. It means we found a clipped polygon.

Weiler-Atherton polygon clipping algorithm


This algorithm helps us to clip a filled area. The filled area may be a convex polygon or concave
polygon. This algorithm was introduced to identify the visible surfaces. This algorithm helps to
create individual polygons in some cases. In the Weiler-Atherton algorithm, we consider the
view pane boundaries instead of edges and vertices of the polygon.

CPU College Computer Graphics Chapter 5


25 | P a g e

Algorithm of Weiler-Atherton Polygon Clipping


Step 1: First,create a list of intersection points that are in the starting or ending state. (I1,
I2……. In).
Step 2: Now, create twomore lists; one for subject polygon and other for clip polygon.Fill
both lists with intersection points and vertices of the polygon.
Order of Subject Polygon list- Write down all the vertices of the polygon in the subject
polygon column.
Order of Clip Polygon list – Write down the points of the clipping window.
Step 3: Insert the vertices in both lists in such a way that the intersection point exists
between the correct vertices.
Step 4: Now, start from the first vertex of the polygon. Select the first intersection point as
an entering point and follow the same process until we reach the exiting point.
Step 5:  We can move from clip polygon list to subject polygon list and search for the
finishing intersection point. Repeat the process until we find the entering point.
Step 6: Now, the polygon is being clipped. Repeat the same process until each point has been
visited once.
Step 7: Stop.
Example: Consider a polygon with vertices ABCDEFG. Apply Weiler- Atherton algorithm to
find the clipped polygon?
Solution: Let us assume that the vertices of window = C1, C2, C3, C4
The vertices of polygon = ABCDEFG
First, create two lists, one for subject polygon and second for clip polygon.
Iteration 1-

The First new list is- A`, B, C, D`, A`.

CPU College Computer Graphics Chapter 5


26 | P a g e

Iteration 2-

The Second new list is- E`, E, F, F`, F`.


Explanation:
 Check A if it is an intersection point then, start from A otherwise, move to next.
 A` is an intersection point (A` will be saved in the new list) then check the next vertex.
 B is not an intersection point save that in the new list. Then move to next.
 C is also not an intersection point; save it in the new list and move to the next point.
 Now, move to D` (D` is an intersection point). We jump to clip polygon list to find D`.
 We will follow the same procedure for the next iteration.
 This process is repeated until we found the ending point.

Review Exercise

1. Clip a line A (-1,5) and B (3,8) using the Cohen Sutherland algorithm with window coordinates (-
3,1) and (2,6).
2. Explain the concepts of clipping window, view port, display window, and their relations
in a viewing pipeline.
3. Suppose the eye position is at (0, 0, 1), the look-at point is at (0, 0, 0), the view up vector
is (0, 1, 0), and the view plane is z = -1. Given a point P(2, -10, -2), compute coordinates
of the perspective point of P on the view plane in the view coordinate system.
4. What transformations are used in graphic pipeline from model to screen?
5. We saw that a fundamental operation in graphics system is to map a point (x, y), which
lies within a clipping rectangle, to a point (xs, ys), which lies in the viewport of a window
on the screen. Assume that the two rectangles are defined by  OpenGL function calls

CPU College Computer Graphics Chapter 5


27 | P a g e

glViewport(u, v, w, h);
gluOrtho2D(x_min, x_max, y_min, y_max);
Find the mathematical equations that map (x, y) into (xs, ys).
6. Consider a window that is bounded by these lines : y = 0; x = 0; y = 3 and x = 5. If
clipped against this window, the line segment joining the (-1, 0) and (4, 5) will connect
the points will be:

A. (0, 1) and (3, 2) C. (0, 1) and (3, 3)


B. (0, 1) and (4, 3) D. (0, 1) and (2, 3)

CPU College Computer Graphics Chapter 5

You might also like