CGR Unit IV Windowing and Clipping

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Unit-IV Windowing and Clipping

Second Year Diploma Courses in Computer Science & Engineering /


Computer Engineering / Computer Technology / Information Technology Branch.

Computer Graphics
As per MSBTE ‘I’ Scheme Syllabus
CGR-22318

Unit-IV
Windowing and Clipping
Total Marks- 18

Contents:
4.1 Windowing and Clipping Concept
4.2 Window to Viewport Transformation
4.3 Line Clipping
4.3.1 Cohen Sutherland Clipping Algorithm
4.3.2 Cyrus-beck Line Clipping Algorithm
4.3.3 Liang Barsky Line Clipping Algorithm
4.3.4 Midpoint Subdivision Line Clipping Algorithm
4.4 Polygon Clipping:
4.5 Text Clipping

CGR-22318 www.freestudyroom.xyz Page 1


Unit-IV Windowing and Clipping

Unit-IV Windowing and Clipping

4.3.1 Windowing and Clipping Concept:


Window: world-coordinate area selected for display is called a window. A window defines a
rectangular area in world coordinates.
Windowing: The process of selecting and viewing the picture with different views is called
windowing.
Clipping: The process which is divides each elements of the picture into its visible and invisible
portions, allowing the invisible portion to be discarded is called clipping.

4.3.2 Window to Viewport Transformation:


The window defines what is to be viewed; the viewport defines where it is to be displayed.
1. Window-to-Viewport transformation is the process of transforming a two-dimensional, world-
coordinate scene to device coordinates.
2. In particular, objects inside the world or clipping window are mapped to the viewport. The
viewport is displayed in the interface window on the screen.

Figure: window and viewport

The picture is stored in the computer memory using any convenient Cartesian co-ordinate system,
referred to as World Co-Ordinate System (WCS). However, when picture is displayed on the display
device it is measured in Physical Device Co-Ordinate System (PDCS) corresponding to the display
device.
The viewing transformation which maps picture co-ordinates in the WCS to display co-ordinates in
PDCS is performed by the following transformations.
• Converting world co-ordinates to viewing co-ordinates.
• Normalizing viewing co-ordinates.
• Converting normalized viewing co-ordinates to device co-ordinates.

CGR-22318 www.freestudyroom.xyz Page 2


Unit-IV Windowing and Clipping

Figure: Two-dimensional viewing-transformation pipeline.


The steps involved in viewing transformation:-
1. Construct the scene in world co-ordinate using the output primitives and attributes.
2. Obtain a particular orientation for the window by setting a two-dimensional viewing co-ordinate
system in the world co-ordinate plane and define a window in the viewing co-ordinate system.
3. Use viewing co-ordinates reference frame to provide a method for setting up arbitrary orientations
for rectangular windows.
4. Once the viewing reference frame is established, transform descriptions in world co-ordinates to
5. Define a view port in normalized co-ordinates and map the viewing co-ordinates description of the
scene to normalized co-ordinates.
6. Clip all the parts of the picture which lie outside the viewport.
4.3.3 Line clipping:
In line clipping, we will cut the portion of line which is outside of window and keep only the portion
that is inside the window.
The line clipping algorithms are:
1. Cohen Sutherland Line Clipping Algorithm
2. Cyrus-beck Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm
4. Midpoint Subdivision Line Clipping Algorithm
4.3.1 Cohen Sutherland Line Clipping Algorithm
This algorithm uses the clipping window as shown in the following figure. The minimum coordinate
for the clipping region is (XW_{min}, YW_{min}) and the maximum coordinate for the clipping
region is (XW_{max}, YW_{max}).

CGR-22318 www.freestudyroom.xyz Page 3


Unit-IV Windowing and Clipping

Cohen-Sutherland algorithm divides a two-dimensional space into 9 regions and then efficiently
determines the lines and portions of lines that are inside the given rectangular area. Each region have
four bit codes are called as region codes or out-codes. These 4 bits represent the Top, Bottom,
Right, and Left of the region. These codes identify the location of the point relative to the boundaries
of the clipping rectangle as shown in fig.

Top Bottom Right Left

1001 1000 1010

0000
0001 0010
window

0101 0100 0110

Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT corner.
There are 3 possibilities for the line −
 Line can be completely inside the window (This line should be accepted).
 Line can be completely outside of the window (This line will be completely removed from the
region).
 Line can be partially inside the window (We will find intersection point and draw only that
portion of line that is inside region).

A method used to test lines for total clipping is equivalent to the logical AND operator.

 If the result of logical AND operation with two end point codes is not 0000, then the line is
completely outside the clipping region.
 The lines that cannot be identified as completely inside or outside a clipping window by these
tests are checked for intersection with the window boundaries.
 The intersection points with a clipping boundary can be calculated using the slope-intercept form
of the line equation.
 The equation for line passing through points p1(x1,y1) and p2(x2,y2) is
y = m (x-x1) + y1
or y = m (x-x2) + y2
where, m= (slope of the line)
Therefore, the intersections with the clipping boundaries of the window are given as :
 Left : xL, y= m(xL-x1)+y1; m
 Right : xR, y= m(xR-x1)+y1; m
 Top : yT, x= x1+ (yT-y1); m
 Bottom : yB, x= x1+ (yB-y1); m

CGR-22318 www.freestudyroom.xyz Page 4


Unit-IV Windowing and Clipping

Advantage of Cohen Sutherland Line Clipping:


1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.

Algorithm:
1. Read two end points of the line P1(x1,y1) and P2(x2,y2).
2. Read two corners (left-top and right-bottom) of the window, (Wx1, Wy1) and (Wx2, Wy2).
3. Assign the region codes for two end points P1 and P2 using following steps:
Initialize code with bit 0000
Set Bit 1 - if (X<Wx1) for left region
Set Bit 2 - if (X>Wx2) for right region
Set Bit 3 - if (Y<Wy1) for bottom region
Set Bit 4 - if (Y>Wy2) for top region
4. Check for visibility of line P1 P2
a. If region codes for both endpoints P1 and P2 are zero then the line is completely visible.
Hence draw the line and go to stop.
b. If region codes for endpoints are not zero and the logical ANDing of them is also non-zero
then the line is completely invisible, so reject the line and stop.
c. If region codes for endpoints do not satisfy the condition in (4a) and (4b) the line is partially
visible.
5. Determine the intersecting edge of the clipping window by inspecting the region codes of two
end points.
a. If region codes for both the end points are non-zero, find intersection points P’1 and P’2 with
boundary edge of the clipping window with respect to point P1 and point P2, respectively.
b. If region codes for any one end point is non-zero then find intersection points P’1 or P’2 with
the boundary edge of the clipping window with respect to it.
6. Divide the line segments considering intersection points.
7. Reject the line segment if any one end point of it appears outsides the clipping window.
8. Draw the remaining line segments.
9. Stop.
Example:
1. Consider the clipping window and the lines shown in fig. Find the region codes for each end
point and identify whether the line is completely visible, partially visible or completely
invisible.
P9

P4
P2

P6 P10
P1 P8
P3
P5

P7

CGR-22318 www.freestudyroom.xyz Page 5


Unit-IV Windowing and Clipping

Solution:
The fig. (a) shows the clipping window and lines with region codes. These codes are tabulated and
end points are logically ANDed to identify the visibility of the line in Table (a)

P9
1001 1000 1010

P4 P2
P10
0001 0000
P6 0010
P1 P8
P3
P5

0101 0100 0110


P7

Fig. (a)

Logical
Line End Point Codes Result
ANDing
P1 P2 0000 0000 0000 Completely
Visible
P3 P4 0001 0001 0001 Completely
Invisible
P5 P6 0001 0000 0000 Partially
Visible
P7 P8 0100 0010 0000 Partially
Visible
P9 P10 1000 0010 0000 Partially
Visible
Fig. (a)
2. Use the Cohen-Sutherland out code algorithm to clip two lines p 1(40,50)-p2(75,45) and
p3(70,20)-p4(100,10) against a window A(50,10), B(80,10), C(80,40) and D(50,40).
Solution:
For Line 1: Given, p1(40,50) p2(75,45) and
Window: XL=50, YB=10, XR=80, YT=40 P2 (75,45)
1000 I2 (80,40)
(50,40)

0001 0010
I1

p1 (40,15)
(50,10) 0100 (80,10)

CGR-22318 www.freestudyroom.xyz Page 6


Unit-IV Windowing and Clipping

Line End point codes ANDing Result


p1 p2 0001 1000 0000 Partially Visible

Slop (m) = = = =

For XL(I1), y = m(xL-x1)+y1


= (50-40)+15

= (10)+15 = 23.57
For YT(I2) x= x1+ (yT - y1)

x= 40+ (40 - 15)

x= 40+ (25)= 69.16


Point I1 = (50, 23.69) and Point I2 = (69.16, 40)
For Line 2: Given, p3(70,20) p4(100,10)
1000 (80,40)
(50,40)

0001 0010
P3 (70,20)
I2
P4 (100,10)
(50,10) 0100 (80,10)

Line End point codes ANDing Result


P3 p4 0000 0010 0000 Partially Visible
Slop (m) = = = =
For XR(I2), y = m(xR-x1)+y1
= (80-70)+20

= (10)+20 = 16.66
Point I2 = (80, 16.66)
4.3.2 Cyrus-Beck Line Clipping Algorithm:
Cyrus-beck algorithm is applicable to an arbitrary convex region. This algorithm uses a parametric
equation of a line segment to find the intersection points of a line with the clipping edges. The
parametric equation of a line segment from point p1 to point p2 is –
P (t) = p1 + (p2- p1) t; 0 t 1
Where, t is a parameter, t=0 at point p1 and t=1 at point p2.
Consider a convex clipping region R, b is a boundary point of the convex region R and n is an inner
normal for one of its boundaries, as shown in the fig. (a).

CGR-22318 www.freestudyroom.xyz Page 7


Unit-IV Windowing and Clipping

Then we can distinguish in which region a point lie by looking at the value of the dot product
n . [P(t) – b], as shown in fig.(b).
y Boundary Point (b)
R-Convex Region

x
0 Fig.(a)
1. If dot product is negative i.e. n . [P(t) – b] < 0
Then, the vector P(t) – b is pointed as outside of the clipping region R.
2. If dot product is zero i.e. n . [P(t) – b] = 0
Then, the vector P(t) – b is pointed as on the boundary of the clipping region R.
3. If dot product is positive i.e. n . [P(t) – b] > 0
Then, the vector P(t) – b is pointed as inside of the clipping region R.
P2
b
n
n .[P(t)–b]>0
n .[P(t)–b]<0 n
n n .[P(t)–b]=0
p1

Clipping edge
Fig.(b) - Dot products for three points inside, outside and on the boundary of the clipping region

If the point b lies in the boundary plane or edge for which n is the inner normal, then that point t on the
line P(t) which satisfies n .[P(t)–b]=0 condition is the intersection of the line with the boundary edge.
Generalization of Dot Product:
n .[P(t)–b]=0
Substitute the value of parameter P(t) in above equation.
n.[(P1+(p2-p1)t)-b]=0
n.(P1-b)+n.(P2-P1)t=0
Where P1-b is weight factor (W) and
P2-P1 is Distance parameter (D) of two endpoints
So given equation become-
n.W + n.Dt = 0
n.Dt=-n.W
t=–
Algorithm:
1. Read end points of line P1 and P2.
2. Read vertex coordinates of clipping window.
3. Calculate D = P2 – P1.
4. Assign boundary point b with particular edge.
5. Find inner normal vector for corresponding edge.
6. Calculate D.n and W = P1 – b.
7. If D.n > 0
tL = –
else

CGR-22318 www.freestudyroom.xyz Page 8


Unit-IV Windowing and Clipping

tU = –
end if
8. Repeat steps 4 through 7 for each edge of clipping window.
9. Find maximum lower limit and minimum upper limit.
10. If maximum lower limit and minimum upper limit do not satisfy condition 0 ≤ t ≤ 1 then
ignore line.
11. Calculate intersection points by substituting values of maximum lower limit and minimum
upper limit in parametric equation of line P1P2.
12. Draw line segment P(tL) to P(tU).
13. Stop.
Example: Fig. shows the Hexagonal clipping window. The line P1(-2,1) to P2(6,3) is to be clipped to
this window. Find the intersection points.
V4
6
5 V5
4 V3
3 I2 P2(6,3)
V2 I1
2 V6
P1(-2,1) 1
V1
-2 -1 1 2 3 4 5 6

Solution: We know that, Distance parameter-


D= P2- P1=[6 3]-[-2 1]=[8 2]
For the edge (V1 V2),
1. Assign boundary point i.e. V1(3,0)
Calculate edge weight for boundary point b(3,0)-
W= P1-b=[-2 1]-[3 0] = [-5 1]
2. Find out inner normal:
n = [1 1]
Calculate the value of Dot product (D.n)-
D.n = [8 2].[1 1] = [(8 * 1) + (2 * 1)]=[8+2]=10
Here, Dot product D.n is greater than 0 (D.n > 0),
Find out the lower limit –

tL = – =– =– =0.4
Similar calculation with each edge gives the complete results of the Cyrus-Beck algorithm. These
results are tabulated in table-
Edge n b W W.n D.n tL tU
V1 V2 [1 1] (3, 0) [-5 1] -4 10 0.4
V2 V3 [1 0] (1, 4) [-3 -3] -3 8 0.375
V3 V4 [1 -1] (1, 4) [-3 -3] 0 6 0
V4 V5 [-1 -1] (5, 4) [-7 -3] 10 -10 1
V5 V6 [-1 0] (5, 4) [-7 -3] 7 -8 0.875
V6 V1 [-1 1] (3, 0) [-5 1] 6 -6 1
Referring above table we have,
CGR-22318 www.freestudyroom.xyz Page 9
Unit-IV Windowing and Clipping

The maximum lower limit (tL) = 0.4 and


The minimum upper limit (tU) = 0.875
Substituting these values of t in parametric equation
We get,
P(t) = p1 + (p2- p1)t
P(0.4) = [-2 1] + [8 2] (0.4)
= [-2 1] + [3.2 0.8]
= [1.2 1.8]
P(0.4) = [-2 1] + [8 2] (0.875)
= [-2 1] + [7 1.75]
= [5 2.75]
Thus, the two intersection points to line P1 P2 are [1.2 1.8] and [5 2.75] with edges V1 V2 and V5 V6
respectively.
4.3.3 Liang-Barsky Clipping Line Algorithm:
Liang and Barsky have developed more efficient algorithm than Cyrus-Beck algorithm, using parametric
equations and is also efficient than Cohen-Sutherland algorithm.
The parametric equations are given as,

The point clipping conditions for Liang-Barsky approach in the parametric form can be given as

Liang-Barsky expresses these four inequalities with two parameters p and q as follows:

Where parameters p and q are defined as

CGR-22318 www.freestudyroom.xyz Page 10


Unit-IV Windowing and Clipping

Liang-Barsky algorithm calculates two values of Parameter t : t1 and t2 that define that part of the line
that lies within the clip rectangle. The value of t1 is determined by checking the rectangle edges for
which the line proceeds from the outside to the inside (p <0). The value of t1 is taken as a largest value
amongst various values of intersections with all edges. On the other hand, the value of t2 is determined
by checking the rectangle edges for which the line proceeds from the inside to the outside (p > 0). The
minimum of the calculated value is taken as a value for t2.

Now, if t1 > t2, the line is completely outside the clipping window and it can be rejected. Otherwise the
values of t1 and t2 are substituted in the parametric equations to get the end points of the clipped line.

CGR-22318 www.freestudyroom.xyz Page 11


Unit-IV Windowing and Clipping

CGR-22318 www.freestudyroom.xyz Page 12


Unit-IV Windowing and Clipping

Example: Apply the Liang-Barsky algorithm to the line with coordinates (30, 60) and (60, 25)
against the window (Xmin, Ymin)=(10, 10) and (Xmax, Ymax)=(50, 50).
Solution: Here,
X1 = 30 Y1 = 60
X2 = 60 Y2 = 25
Xwmin = 10 Ywmin = 10
Xwmax = 50 Ywmax = 50
Now calculate the value of parameters pi and qi :
p1 = - = -(x2-x1) = -(60 – 30) = -30
p2 = = (x2-x1) = (60 – 30) = 30
p3 = - = -(y2-y1) = -(25 – 60) = -35
p4 = = (y2-y1) = (25 – 60) = 35
q1 = X1-Xwmin = 30 – 10 = 20
q2 = X1-Xwmax = 50 – 30 = 20
q3 = Y1-Ywmin = 60 – 10 = 50
q4 = Y1-Ywmax = 50 – 60 = -10
= = - 0.667
= = 0.667
= = 1.4285
= = 0.2857
t1 = max (- 0.667, 0.2857)
= 0.2857 since for these values p < 0
t2 = min (0.667, 1.4285)
= 0.667 since for these values p > 0
Here t1 < t2 and the end points of clipped line are :
(x1, y1)
60
(Xwmax, Ywmax)
50 (XX1, YY1)
(38.571, 50)
40 (XX2, YY2)

30
(50, 36.655)
(x2, y2)
20

10
(Xwmin, Ywmin)

CGR-22318 www.freestudyroom.xyz Page 13


Unit-IV Windowing and Clipping

10 20 30 40 50 60
XX1 = X1 + t1
= 30 + 0.2857 30 = 38.571
YY1 = Y1 + t1
= 60 + 0.2857 (-30) = 50
XX2 = X1 + t2
= 30 + 0.667 30 = 50
YY2 = Y1 + t2
= 60 + 0.667 (-35) = 36.655

4.3.4 Midpoint Subdivision Line Clipping Algorithm:


 The Sutherland cohen subdivision line clipping algorithm requires the calculation of the intersection
of the line with the window edge. These calculations can be avoided by repetitively subdividing the
line at its midpoint.
 Like previous algorithm, initially the line is tested for visibility. If line is completely visible it is
draw and if it is completely invisible it is rejected.
 If line is partially visible then it is subdivided in two equal parts. The visibility tests are then applied
to each half.
 This subdivision process is repeated until we get completely visible and completely invisible line
segments. This is illustrated in following fig.
 As shown in fig. (a) line P1P2 is partial visible.
 It is subdivided in two equal parts P1 P3 and P3 P2 (see fig. (b)). Both the line segments are tested for
visibility and found to be partially visible.
 Both line segments are then subdivided in two equal parts to get midpoints P4 and P5 (see in fig.(c)).
 It is observed that line segments P1 P4 and P5 P2 are completely invisible and hence rejected.
 Line segment P3 P5 is completely visible and hence drawn.
 The remaining line segment P4 P3 is still partially visible. It is then subdivided to get midpoint P6.
 It is observed that P6 P3 is completely visible whereas P4 P6 is partial visible.
 Thus P6 P3line segment is draw and P4 P6 line segment is further subdivided into equal parts to get
midpoint P7 .
 It is observed that line segment P4 P7 is completely invisible and line segment P7 P6 is completely
visible (see fig. (f)) and there is no further partially visible segment.

CGR-22318 www.freestudyroom.xyz Page 14


Unit-IV Windowing and Clipping

Midpoint subdivision algorithm:


1) Read two end points of line P1 (x1,y1) and P2 (x2,y2).
2) Read corners of window (Wx1, Wy1) and (Wx2, Wy2).
3) Assign region codes for P1 and P2. A region code is a 4 digit bit code which indicates one of
nine regions having the end point of line.
Initialize code with bits 0000
Set Bit 1 if (x<Wx1)
Set Bit 2 if (x>Wx2)
Set Bit 3 if (y<Wy2)
Set Bit 4 if (y>Wy1)
4) Check visibility of line P1P2
a) If region codes for both end points P1 and P2 are zero Line is completely visible. Hence draw
Line and Go to Step 6.
b) If region codes for both end points P1 and P2 are not zero and logical ANDing of them is
also nonzero then the line is completely invisible. So reject line and Go to Step 6.

CGR-22318 www.freestudyroom.xyz Page 15


Unit-IV Windowing and Clipping

c) If region codes for two end points do not satisfy the conditions in a) and b) the line is
partially visible.
5) Divide partially visible line segments to equal parts and repeat steps 3 through 5 for both
subdivided line segments until you get completely visible and completely invisible line
segments.
6) Stop.
4.4 Polygon Clipping:
 A polygon is nothing but the collection of lines. Therefore, we might think that line clipping
algorithm can be used directly for polygon clipping. However, when a closed polygon is clipped
as a collection of lines with the line clipping algorithm, the original closed polygon becomes one
or more open polygon or discrete lines as shown in fig. Thus, we need to modify the line clipping
algorithm to clip polygon.

(a) Before Clipping (b) After Clipping


 We consider a polygon as a closed solid area. Hence after clipping it should remain closed. To
achieve this we require an algorithm that will generate additional line segment which make the
polygon as a closed area.
Sutherland-Hodgeman Polygon Clipping:
 In Sutherland-Hodgeman, a polygon is clipped by processing the polygon boundary as a whole
against each window edge. Clipping window must be convex.
 This could be accomplished by processing all polygon vertices against each clip rectangle boundary
in turn beginning with the original set of polygon vertices, first clip the polygon against the left
rectangle boundary to produce a new sequence of vertices.
 The new set of vertices could then be successively passed to a right boundary clipper, a top boundary
clipper and a bottom boundary clipper.
 At each step a new set of polygon vertices us generated and passed to the next window boundary
clipper. This is the logic used in Sutherland-Hodgeman algorithm.

CGR-22318 www.freestudyroom.xyz Page 16


Unit-IV Windowing and Clipping

 The output of algorithm is a list of polygon vertices all of which are on the visible side of clipping
plane. Such each edge of the polygon is individually compared with the clipping plane.
 This is achieved by processing two vertices of each edge of the polygon around the clipping
boundary or plane.
This results in four possible relationships between the edge and clipping plane.
1. If first vertex of polygon edge is outside and second is inside window boundary, then intersection
point of polygon edge with window boundary and second vertex are added to output vertices set
as shown in Fig. 6.13.
2. If both vertices of edge are inside window boundary, then add only second vertex to output set as
shown in Fig. 6.14.
3. If first vertex of edge is inside and second is outside of window boundary then point of
intersection of edge with window boundary is stored in output set as shown in Fig. 6.15.
4. If both vertices of edges are outside of window boundary then those vertices are rejected as
shown in Fig. 6.16.

CGR-22318 www.freestudyroom.xyz Page 17


Unit-IV Windowing and Clipping

 Going through above four cases we can realize that there are two key processes in this algorithm:
1. Determine the visibility of point or vertex (Inside – Outside Test)
2. Determine the intersection of the polygon edge and clipping plane.

One key of determining the visibility of a point or vertex is described here.


 Consider that two points A and B define the window boundary and point under consideration is V,
then these three points define a plane.
 Two vectors which lie in that plane are AB and AV. If this plane is considered in the xy plane, then
the vector cross product AV AB has only a z component given by
(xV - xA) (yB - yA) - (yV - yA) (xB - xA)
 The sign of the z component decides the position of point V with respect to window boundary.
If z is :
Positive - Point is on the right side of the window boundary

CGR-22318 www.freestudyroom.xyz Page 18


Unit-IV Windowing and Clipping

Zero - Point is on the window boundary


Negative - Point is on the left side of the window boundary
The second key process in Sutherland-Hodgeman polygon clipping algorithm is to determine the
intersection of the polygon edge and clipping plane. Any of the line intersection techniques can be used
for this purpose.
 Assume that we're clipping a polygon’s edge with vertices at (x1, y1) and (x2,y2) against a clip
window with vertices at (xmin, ymin) and (xmax, ymax).
1. The location (IX, IY) of the intersection of the edge with the left side of the window is:
a. IX = xmin
b. IY = slope*(xmin – x1) + y1, where the slope = (y2 – y1)/(x2 – x1).
2. The location of the intersection of the edge with the right side of the window is:
a. IX = xmax
b. IY = slope*(xmax – x1) + y1, where the slope = (y2 – y1)/(x2 – x1)
3. The intersection of the polygon's edge with the top side of the window is:
a. IX = x1 + (ymax – y1) / slope
b. IY = ymax
4. Finally, the intersection of the edge with the bottom side of the window is:
a. IX = x1 + (ymin – y1) / slope
b. IY = ymin
Algorithm for Sutherland-Hodgeman Polygon Clipping:
Step 1: Read co-ordinates of all vertices of the polygon.
Step 2: Read co-ordinates of the clipping window.
Step 3: Consider the left edge of window.
Step 4: Compare vertices of each of polygon, individually with the clipping plane.
Step 5: Save the resulting intersections and vertices in the new list of vertices according to four
possible relationships between the edge and the clipping boundary.
Step 6: Repeat the steps 4 and 5 for remaining edges of clipping window. Each time resultant list of
vertices is successively passed to process next edge of clipping window.
Step 7: Stop.

4.5 Text Clipping

Various techniques are used to provide text clipping in a computer graphics. It depends on the methods
used to generate characters and the requirements of a particular application. There are three methods for
text clipping which are listed below −

 All or none string clipping


 All or none character clipping
 Text clipping

CGR-22318 www.freestudyroom.xyz Page 19


Unit-IV Windowing and Clipping

All or none string clipping –

In all or none string clipping method, either we keep the entire string or we reject entire string based on the
clipping window. As shown in the below figure, STRING2 is entirely inside the clipping window so we keep it
and STRING1 being only partially inside the window, we reject.

All or none character clipping –

This clipping method is based on characters rather than entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then −

 You reject only the portion of the string being outside


 If the character is on the boundary of the clipping window, then we discard that entire character
and keep the rest string.

Text clipping –

This clipping method is based on characters rather than the entire string. In this method if the string is
entirely inside the clipping window, then we keep it. If it is partially outside the window, then

 You reject only the portion of string being outside.

CGR-22318 www.freestudyroom.xyz Page 20


Unit-IV Windowing and Clipping

 If the character is on the boundary of the clipping window, then we discard only that portion of
character that is outside of the clipping window.

CGR-22318 www.freestudyroom.xyz Page 21

You might also like