CA1328136C - Polygon and polyline clipping for computer graphic displays - Google Patents

Polygon and polyline clipping for computer graphic displays

Info

Publication number
CA1328136C
CA1328136C CA000572974A CA572974A CA1328136C CA 1328136 C CA1328136 C CA 1328136C CA 000572974 A CA000572974 A CA 000572974A CA 572974 A CA572974 A CA 572974A CA 1328136 C CA1328136 C CA 1328136C
Authority
CA
Canada
Prior art keywords
dis
invisible
homing
polygon
vertex
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CA000572974A
Other languages
French (fr)
Inventor
Tina M. Nicholl
Khun Yee Fung
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
University of Western Ontario
Original Assignee
University of Western Ontario
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by University of Western Ontario filed Critical University of Western Ontario
Priority to CA000572974A priority Critical patent/CA1328136C/en
Application granted granted Critical
Publication of CA1328136C publication Critical patent/CA1328136C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T15/00Three-dimensional [3D] image rendering
    • G06T15/10Geometric effects
    • G06T15/30Clipping

Landscapes

  • Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Geometry (AREA)
  • Computer Graphics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Image Generation (AREA)

Abstract

ABSTRACT A method of clipping polygons against rectilinear rectangular windows is disclosed, in which groups of consecutive vertices of the polygons are processed together, using a coherence property of polygons, rather than processing each pair of vertices in isolation. The method does not generate repetitive sequences of window corners. As a by-product, there is also a new polyline clipping algorithm which also uses the coherence property.

Description

1 328 i 36 , . .

.
~CK~OU~g~ge_ln~ y~
F~el~ of the Inven~ion ~ his invention relate~ to clipping polygon~ again~t windows in computer graphics 6ystems and displays. A
modificatlon of the invention can be u~ed to clip polyline a~
: well. The invention relates particularly to clipping again~t rec~ilinear rectangular windows, but can b~ genaral~zed to ~ ~ , . . . .
handle arbitrarily shaped window~. . .
The purpose of clipping a polygon against ~ window 0 i5 to eliminate the part~ of the polygon which ars not in the window. Polygon clipping algorithm~ exi~t in almost all : graphics packages. Since ~uch algorithms are used millions o~
tlmes every dayl..the incorpo~ation of an efPicient poly~on clipping algorithm 1~ clearly advantageous to a graphic~
~ 15 sy~tem. : .
-t ' Since the optimal time comple~i~y of clipping ~imple polygons against a r~atilinear rectan~ular window i~ O~n~, where ~ is the number of vert~ce~ in the input polygon~ any improvement must onIy ba on reducing the mui~iplying factor of:
the time compl~xity. Neverthele~s, any improvement is still important becau~e o~ the ~requ~nt use o~ polygon clipplng routin2s in graphic~ applications.
.
~ i . ~

The representations of polygons and windows, the division of the 2-D plane and what tasks must be performed in a polygon clipping algorithm will now be discussed generally.
To repre~ent a polygon, a vertex i~ arbitrarily chosQn as the starting vertex and the vertices are listed in consecutive order from the starting vertex, as shown in Fig.1.
The ~irst vertex is also appended to the end of the sequence.
The boundary of the polygon is considered to be part of the polygon. Thus the polygon in Fig.l can be described as (a, b, c, d~ e, f, a).
The interior of a window is defined to be all points (x,y) such that xl~t is less than or equal to x which is less .. . . ................ .
than or ~qual to xrlgh~ and Y~tto~ is less than or equal to y which is less than or equal to Ytop~ A window is shown in Fig.2.
The lines x = Xl~t~ X = Xrl9ht~ y = Y~tto~ and y = Ytop are called the left, right, bottom and top boundary lines respectively. The intersection points of the boundary lines are called the window corners. Two parallel boundary lines are called boundary lines which are opposite to each other.
Therefore, the left and right boundary lines are opposite to . . .
each other, as are the top and bottom boundary lines.

Vertices of an input polygon which are not in the window are called invisible vertices and vertices that are in the window are called visible vertices.
.
The 2-D plane is divided into nine regions, as shown in Fig. 3. These are the left edge region, the left top corner region, the left bottom corner region, the right edge :~ `

. , - ,.... , .. ~ , ... ... ... .
:: . . . ~: :. . .

132~l36 region, the right top corner region, the right bottom corner region, the top edge region, the bottom edge region, and the window.
The parts of the boundary lines separating a region from the other regions are called th~ borders of the region.
For example, the right top corner region has two borders, namely the part of the right boundary line above the top boundary line and the part of the top boundary line to the right o~ the right boundary line. The borders of the right top corner region are in solid lines.
A boundary line divides the 2D plane into two sides.
The side of a boundary line on which the window lies is called the visible side of the boundary line. The other side is called the invisible side of the boundary line.

Tasks to Perform ; The clipping problem is actually a subset of the intersection problem. The aim of clipping an object against another object is to produce the intersection of these two objects. Of cour~e, in computer graphics, all ob~ects, the objects to be clipped as well as the output, must be represented by some data structures before they can be manipulated.
The intersection of a rectilinear rectangle and a polygon is a set o~ separate polygons. If the polygon is a simple polygon, the polygons in the set are all simple also.
There are three tasks which must be performed to produce the intersection of a rectilinear rectangular window . : .... : : .

~.~ `` 1328136 and a polygon: identi~ication of all the visible vertices and computakion of all the intersection points between the window boundaries and the polygon edges and the inclusion of the visible vertices and intersection points in the output;
computation to include corners of the window boundaries that are in the interior of the polygon; and the organization of the output vertices into separate polygons.
The third task is very time-consuming. Although it can still be done in linear time for simple polygons ... .
(non-selfintersecting polygons), it is usually avoided with penalty to the correctness of the output. For non-simple polygons, the third task cannot be performed in linear time.
.
So in fact most polygon clipping algorithms only perform the first and the second tasks.
Although strictly speaking algorithms that do not perform the third task are not correct, they are valuable for clipping simple polygons because they save time. For non-simple polygons, they are the alternatives to potentially , O(n') algorith~s.
The present invention is in the category of algorithms which do not perform the third task, i.e. which do not organize the output polygons.
.
Description of the Prior Art Two known polygon clipping algorithms are the Liang-Barsky and Sutherland-Hodgman algorithms. (See Liang, Y-D. and Barsky, B., "An Analysis and Algorithm for Polygon Clipping", Communications of the ACM, vol. 26~11), pp.868-877, .

. .
., . . ~ ~ . . . .
~ , . . . .
. .
,......................................................... . .

` ~328136 Novsmber 1983; and Sutherland, I.E. and Hodgman, G., "Reentrant Polygon Clipping", Communications of the ACM, vol.
17(1), pp. 32~42, January 1974.) The Sutherland-Hodgman algorithm's main idea is to clip the input polygon in pipe-line fashion against each boundary line in turn. Therefore, there are four phases in this algorithm: the first phase when the input polygon is clipped against the first boundary line, the second phase when the output of the first phase is clipped against the second ~oundary line, the third phase when the output of the second phase is clipped against the third boundary line, and the fourth phase when the output of the third phase is clipped against the fourth boundary line. The output of the fourth phase is the output polygon of the polygon clipping algorithm.
The window corners that are in the interior of the input polygon are not computed explicitly. These ~orners are included as intersection points.
The idea of the Sutherland-Hodgman algorithm is simple. It can also be implemented easily. Its disadvantages are two-fold. Firstly, the efficiency of discarding an invicible vertex of the input polygon depends chiefly on its position - very efficient if it is discarded in the first phase and inefficient when discarded in the last phase.
Secondly, redundant window corners might be included in some cases.
The output of the Sutherland-Hodgman algorithm is a single, possibly non-simple, polygon with portions o~ the polygon connected by edges which are extraneous in the sense `:

that they are not part of the intersection the input polygon makes with the window.
In the Liang-Barsky algorithm, each edge of the input polygon is treated as a vector. The relative positions of the entry points (the points an edge enters the visible side of a boundary line) and exit points (the points an edge exits the viæible side of a boundary line) are used to determine if an edge has any portion in the window. If a portion o~ an edge is in the window, the intersection points this edge makes with the window boundary are then computed.
In two cases will a window corner be included.
First, when the first endpoint of an edge is found to be in a corner region and the second endpoint is found to be not in the same corner region, the window corner of that corner region is included. Second, when a portion of an edge is found to be in a corner region where the edge enters with the first exit point and exits the corner region with the second entry point, the window corner of the corner region is included.
This scheme of including window corners might include many window corners that are not in the interior of the input polygon. It might also include a repetitive sequence o~ window corners.
As with the Sutherland-Hodgman algorithm, the output 25 is always a single, probably non-simple, polygon.
The only way generally known today to include window .,,~ , ~
corners correctly in linear time when clipping simple polygons i6 to use a Jordan sorting algorithm. ~See Fung, K.Y., :

. .

:, . : '' :
: :. . .
:: , : -: . ' :
:: , ; : :.
,'`:` ' , , ~ :` '`

-`~ 1 328 1 36 "Linear Time Algorithms ~or Clipping Simple and Convex Polygons", Master Thesis, The University of Western Ontario, 1988; and Hoffmann, K., Mehlhorn, K., Rosenstiehl, P., and Tarjan, Ro~ "Sorting Jordan Sequences in Linear Time Using Le~el-linked Search Trees", Information and Control, vol 68, pp.l70-184, 1986.) A Jordan sorting algorithm can be used to sort the intersection points on the boundary lines in linear time. From a sorted sequence of intersection points it can then be determined if a corner is in the interior of the input polygon. For non-simple polygons, there is no linear time algorithm. A general sorting algorithm must be used.
Since algorithms that do not organize output ... . .
polygons do not produce strictly correct output polygons; a method is needed to determine whether a polygon clipping algorithm produces a~ceptable output polygons.
An acceptable output polygon should have the minimum number of vertices possible. This is important because polygon clipping algorithms are used only when filling might be done to the output polygons. When filllng is not needed, then a polyline clipping algorithm is good enough. To speed up filling, there should be the least number of vertices possible.
Naturally, the other criterion is that visible , `` vertices and intersection points must be included correctly ~ 25 and in the correct order. However, since it is presumed that ~ , ., all polygon clipping algorikhms do this correctly, this will not be discussed in detail. Instead, the following description will concentrate on window corners because the :, ~: ' ~ , ~

. ~. , , ~ .
:, ~ 328 1 36 presence of window corners differentiates a polyline clipping algorithm from a polygon clipping algorithm.
The present inventors propose the following set of criteria for determining if an output polygon has the least numb~r of window corners possible:
1. The only difference between an acceptable output and the correct output must lie entirely on the window boundary. Aside from the boundaries of the polygons the interior of an acceptable output must be identical to that of correct output.
2. There should not be extraneous redundant window - corners which are not needed to connect portions of the resultant polygon together. (See Fig. ~: A
should not be included in the output.)
3. No repetitive window corners should be included.
For example, referring to Fig. 5, ~here should be a, A, B, b instead of a, A, B, B, A, A, B, b where a and b are intersection points and A and ~ are window corners.
4~ When the whole polygon is outside the window, no .
;~ ver~ices should be included in the output.
5. If the who1e window is in the int~rior of the ~` polygon, the output polygon should have only four ;.. ~. .
vertices which are the four corners of the window.;
" 25 The present inventors think that the output polygons . .; .
`; satisfying these criteria are the most desirable apart from the fully correct output polygons which require time-consuming . ~ ' operations .
, , , - .: :, ~ . .
~, ' . . ~ , :: ` :
~ ~ , '' ' - Using these criteria, the Sutherland-Hodgman algorithm fails criteria 2 and 3. The Liang-Barsky algorithm fails 2 to 5. Thus neither algorithm produces output polygons having the minimum number of vertices possible.
To decide which window corners should be included between two intersection points, the present inventors use the following test. If the edges of the polygon between the two succe~sive intersection points intersect one of the two borders of a corner region an odd number of times, this corner should be in~luded. Otherwise, it should not be included.
See Fig. 6,-in which corner A is included between a and b in the output because the edges of the polygon between a and b intersect the left boundary line only at C.
This criterion is added so that, referring to Fig.
7, the following two input polygons can be distinguished: The output for (i) should be (a, b, A, B, C, D, f, e, d, D, C, B, A, c) if a is the startîng vertex. In (ii), the output should be (a, b, f, e, d, c) when a is also the starting vertex.
If one of the intersection points is a window corner itself, this window corner can be included again, This is allowed because floating number operations are not precise and it is rather difficult to ascertain that an intersection point equals to a corner.
,`''. . .
SU~M~RY OF THE INVE~TION
It is an object of the invention to provide a method of clipping polygons which improves on the Sutherland~Hodgman , g ~ ' , ' ~ . .
:
:;
., ' :' .~ ~ '; ' ;~ ~

and Liang-Barsky algorithms and on the prior art generally, and which meets the above criteria.
Thus in accordance with the present invention there ; i5 provided a method of clipping polygons against rectilinear rectangular windows, in which groups of consecutive vertices of the polygons are processed together, rather than in sequential fashion.

.
The algorithm in the present invention clips polygons against a rectilinear rectangular window in an efficlent and ad~antageous manner, and meets the above criteria for poly~on clipping algorithms. The improvement in efficiancy is obtained by using the coherence property of polygons. Groups of consecutive vertices are processed together, instead o~ processing each vertex in isolation~
Also, with slight modification, the present invention can be turned into a new efficient polyline clipping algorithm.
Furthex features of the invention will be described ~ or will become apparent in the course of the following `; 20 detailed description.
.; .
, .
~IEF DESCRIPTI~N OF THE DRAWING~
In order that the invention may be more clearly understood, the preferred embodiment thereof will now be ; 25 described in detail by way of example, with reference to the .. .. .
accompanying drawings, in which:
:;
Fig. l is a drawing showing a polygon;

Fig. 2 is a drawing showing a window;

.~, 10 ., . - "

: ~ , ' :-` ` - 1 328 1 36 Fig. 3 is a drawing showing the regions into which the 2-D plane is divided;
Fig. 4 is a drawing showing an extraneous window corner;
Fig. 5 is a drawing illustrating a situation where repetitive window corners could arise;
Fig. 6 is a drawing showing a test to determine which window corners should be included between two inter~ection points;
Fig. 7 is a drawing showing two polygons which should produce dif~erent output polygons according to the test to which Fig. 6 relates;
.
Fig~ 8 is a drawing of a polygon used later in describing the invention; and Fig. 9 is a drawing showing cases for increasing or decreasing the homing registerO

~T~ILE~ DE$CRIPTIO~ QF THE PREFERR~D EMBODI~NT
There are two important improvsments in the new algorithm: greater efficiency in discarding the invisible 0 vertices and in including the visible vertices, and a better :`
' window corner inclusion scheme. It also satisfies the above-listed criteria for window corner inclusion. Also, with small modifications, the algorithm can be turned into a new polyline . ; . .
` 25 algorithm.
.. , ;, .
Since window corners are not included implicitly as in the Sutherland-Hodgman algorithm and must be included explicitly, this will be described separately later below.
.
`'` 11 . ~

1. Computing Visible Vextices and In~e~section Points The basic idea to discard invisible vertices in the algorithm of the present invantion is to take advantage of the fact that once it is known that ~he i~ vertex lies on the invisible side of a boundary line, only one comparison is needed to det~rmine whether the (i+1)~ vertex also lies on the invisible side of the same boundary line. Therefore, for a sequence of m consecutive vertices lying on the invisible side of the same boundary line, once the first of these vertices is known to be on the invisible sidel the following m-~ vertices can be processed using m-1 comparisons. The inventors call the property that a group of consecutive vertices are probably in tha same region a coherence property of polygons and indeed , 15 of polylines as well., '`, For a sequence o~ ~onsecutive visible vertices, each of them is simply checked against the window boundary lines to ~'~ include,each of them.
;', , The algorithm will now be described in greater ' 20 detail.
' , .
l.(a) ivision o~ V~r~ices ~ To explain th~ algorithm more clearly, the sequence ,` of vertices of an input polygon is divided into g~oups of ' 25 consecutive vertices with respect to the window.' ~ , .
l (a~i) The First _Group ;; ' ' ' .

: ' '' ' ,~ ~ ' '-' The first group consists of the first vertex of the polygon and vertices following it up to, if the first vertex is visible, the vertex preceding the first invisible vertex.
For example, in Fig.8, if e is the first vertex, then (e, f) is the first group. If the first vertex is invisible, the first group consists of the first vertex of the polygon up to the vertex preceding the first intersection point of the polygon. For example, in Fig. 8, if a i8 the first vertex, then the first group is (a, b, c). If the polygon is wholly outside the window or wholly inside the window, we will not have any intersection point. In these cases, the polygon has only the first group which contains all the vertices.

l.(a)(ii) The Last Group 15. Analogous to the first group, the last group contains the last vertex. If the last vertex is invisible, it 1 consists of the vertex immediately after the last intersection .
. point of the polygon and up to the last vertex of the polygon.

::`If the last vertex of the polygon is vi~ible, then this group . .
contains the vertex immediately after the last invisible vertex of the polygon and up to the last vertex of the polygon. In Fig. 8, if k is the last vertex, then the last group is (k). However, if j is the last vertex, then the last group i~ (h, i, j). - ;~
. ~
;i . .
.. . .
l.(a)(iii) Visible Groups and Invisib~_Groups :~ . A visible group is simply a group o~ consecutive ~ visible vertices starting from a vertex immediately after an : ~ . . .... .

` 1 328 1 36 invisible vertax and up to ~he visible vertex immediately preceding the next invisible vertexO
An invisible group consists of consecutive invisible vertice~ starting from an invisible ver~ex immediately after an intersection point to an invisible vertex immediately preceding another intersection point. In Fig. 8, (h, i, j) is an invisible group.
A polygon can then be seen as cvnsisting o~ the first group, any number of visible and invisible groups, and the last group.

.

2. ~rocessing the Groups ; How groups consisting of visible vertices and groups consistin~ of invisible vertices are processed will now be described separately.
;'', " ' ' . .
; 2.(a) Processinq of GrQu~s Consisting ~f Visible Vertices .. . . .
This section discusses how the visible groups are processed. If the first group consists of visible vertices, it is also processed in-the same way. Same for the last ~ group.
,: ' Let (x[m],y[m]) be the coordinates of the m~ vertex.
The index to the vertex being processed is i. The vertices of the input polygon are ætored in the array InputPolygon and the output vertices are stored in the array OutputPolygon.

.. ... .
The algorithm to process a group of visible vertlces is shown in Table l bPlow. All the vi~ible vertices of the visible group are first outputted. This takes four .

-..
- ~ .

' ' ..
.. , . . - .
. - ~ ~. ~' ~'' comparisons for each vertex excluding the overhead in the administration of the loop. If the group being processed i~
not the last group, the edge connecting the last vertex of this group and the first vertex of the next group (which must be an invisible group) is then clipped using a modified version of the Nicholl-Lee-Nicholl line clipping algorithm (see Nicholl, T.M., Lee, D.T., and Nicholl, R.A., I'An E~icient New Algorithm for 2D Line Clipping: Its Development and Analysis,l' SIGGRAPH'87 Conf.Proc., pp.253-262, 1987 for a description of the basic algorithm; and see below for a description of the modification. The DIS of the first vertex of the next group is the invisible side of the boundary line , ,~ , . . . . .

~ this edge intersects. The meaning of "DIS" will be explained '. later below.
: ... .
. . . .

~' 15 l'ABLE 1 ~ . .
~` .. : . .
''J' proc~duro Cllp~indo~t~lo~t,~risht,~bo~to~,rtop:ro~l;InputPolygon:polyson;var OutputPolggon:pol~o~;~ar DIS:l~togor;~ar i:~tog~r);
ar ~.~ E y ~ Y2 ~ y2: r~
~: oid~s:InvSido~
po~ ull, le~t, rightt botto~, top);
~' ` bogin L~putPolygo~.~izo then baBin chec~ uhqther tha curr~nt vert~x i8 1~ tha ~lndo~
~' ` po~:~Null ~ InputPolygon.s W ~la~t th po~
, ol~e 1~ IDpu~Polygon.s W ~rlght th~
J~ ' pOD: =~i8ht ;~ . ol~a i~ InputPoly~on.~CiJ~ybottom th~n po~:-bctto~ .
ol~o i~ InputPolygo~ >ytop thon . po~:,aeop;- ,, ~hilo~iC~InpuePolygo~.~izo~and(poa=~ull)do be~in (~ output a viDiblo ~ertax ~) OutputVoztos(OutputPolygo~,InputPolygo~.x~iJ,I~putPoiygon.~i]);

.~ .
. , .
.
... . , .. ~. , ,:

-pos:=Hull; 1 328 1 36 putPolyg~.x[i~<~ t the~
p~ t putPolygon.~tl~>~rl~ht th~n p~ right InputPolygo~.y~J<ybotto~ thnn po~:=botto~
clno 1~ InputPolygou.yCi]>gtop theu pos:=top;
~nd;
i~(i>InputPolygou.~ )thon bo~i~
OutputPolygon.siz~:=OutputPolygo~.~iz~
~nd b~in ~:sInputPo~y~on.x~i-1];
yl:=I~putPolygou.y~
x2:=IuputPoly~on.~i3;
y2:=InputPolygon.y~
clip.th~ ~dg~ ~parating th~ vi~lbl~ group ~it~ ~u iuvlslbl~
group b~ a modl~lod ~r~io~ o~ a procodur~ ln ~L~ algorl~hm 4) ' inDido(~ t,ytop,xright,ybottom,x~,yl,a:2,y2,~1d~
OutputV~rta~(OutputPolygon,x2,~2);
DIS:-~id~ti]; ~4 ~h~ bou~dar~ lino tho sdg~ ~nt~r~oct~ ~) ~ nd; . .. ..
: end;
~ ~d;
. .
.
,:~
~` 5 After the last vertex of a group consisting of visible :..
:~ vertices has been processed, a group consisting of invisible ~: vertices is processed.
.
.

; 2(b) Processina of Groups of Invisible Yertices If the first group consists of invisible vertices, four comparisons at most are used to find out beyond which boundary line the first vertex of the polygon lies. If it is in the invisible side of exactly one boundary line, this invislble side is called the "designated invisible side"
(DIS). If it is in the invisible side of two boundary lines, that is, in a corner region, one of them is arbitrarily chosen to be the DIS of the vertex. If the first vertex of the group 1 32~ 1 36 is not the first vertex of the polygon, the DIS of the first vextex of an invisible group is the invisible side of the boundary line which the previous intersection point was on.
On~e the DIS of the first vertex has been decided on, each subsequent vertex is examined until a vertex not on the DIS is found.
For example, suppose the DIS is the invisible side of the le~t boundary line, and see Table 2 below. The subsequent vertices are rejected until one is found not to be on the DIS. The edge between the last vertex on the DIS and the first vertex not on the DIS is called the current edge. A
~; modified version of the Nicholl-~ee-Nicholl line clipping ; ~ .
algorithm (see below) is then used to determine whether there are intersection points between the current edge and the window boundary. The computed intersection points are outputted. If there is one intersection point, the next . ~
vertex is in the window. Processing of a visible group is started. If there are two intersection points, processing of a new invisible graup is started, with the DIS being the ,., invisible ~ide of the second boundary line the edge intersects. If there is no intersection point, processing of .
the current invisible group is continued.

TABL~ 2 procodura ClipLo~tS~d~(xle~t,~right,ybottom,ytop:r~al;InputPolygon:polygo~;
~ar OutputPolygo~:polygon; Yar DIS:l~tog~x; v~r 1,~o~in6:~nt~gor);
v~r .
~1,yi,~2,y2:raal .:
IPnu~b~r:int0gor;
~ldes:InvSide~;

. b0gin 1 32 8 1 3 6 IPnu~ber:-O; (~ tha number o~ in~org~ctlon polnt ~hon a~ 0dg~ 1~ cllppod . r~peat i:=i+l;
until (i>InputPolygon.~izo)or(InputPol~gon.~ t);
=InputPolygon.~lzo)theA bogl~
xl:~InputPolygon.~ l];
yl:sInpu~polygon~gt~
~2:~InputPolyeon.~[iJ;
y2:~InputPolygonOyCl~
(~ clip tho edefl u~lng a modi~i~d procodur~ o~ the ~L~ algorithm ~hero IPnumb~r i8 tha nu~bnr o~ interuection point~ the 0dge has and tho ~ldes contain~ tho boundary llno~ tho odgo interaoct3 ~) . lo~tcolumn~xlo~t,ytop,~right,~bottom,sl,yl"c2,y2,IPnumbor,l~ldes) i~ IPnumbor~>O then bogin 1~ 8idosCl]=bottom tho~
oming:=~oming~l -. . e1JO i~ ~id~Cl]=top tha~
~oming:=~oming-l;
output uindo~ cornor~ ~3 printh(sidonCl],~omlng,outputPoly~on~;
.' ~o~lng:=O;
OutputVerte~(OutputPolygon,xl,yl);
DIS:=Yull;
~ i~ IPnumbor=2 th3n bogin .` .. OutputVortnx(OutputPolygoa,~2,y2) tharo ara t~o int~roactlon point~, tb~ DO~ group i~
al~o an invi~ibl~ group. Tho DIS ie tho ~ocond boundary 1 lina the edgo intersects ~) ; DIS:-~id~[2~;
ond;
ond el80 begin (~ computo the homin~ valuo ~di~cussad later) ' DIS:=8id0~0];
DIS=bottom thon ~oming:=~o~ing+l o 1~ DIS-top tho~
: ~o~lng:=~omlng-l ol~ yl<ybottom then ~oming:=~oming+2 018~1 ~oming:=~omi~-2 ; ~nd;
ond;
~nd;
5 Analogous procedures are used for the other DIS.
.; .
2 ( c ) The Last Group .

The last group is processed as an ordinary group except that processing is stopped after the last vertex of the polygon has been processed.

3~ ~o~ ing Inkersection Points There are two places where an intersection point can be ~ound. First, when the last vertex of a visible group has been ~ound. The edge connecting the last vertex of the visible group and the next vertex intersects the window boundary.

, Second, when a vertex has been found not to be in the DIS. There might be no intersection point, one , . .. . . .
intersection point or two intersection points in this case.
If there is no intersection point, the invisible group is .
~ 15 still being processed. If there is one intersection point, :~,` the next group is a visible group. If there are two intersection points, the next group is another invisible group. In any case, the intersection points are computed using a modi~ied Nicholl-Lee-Nicholl line-clipping algorithm.
The Nicholl-Lee-Nicholl line-clipping algorithm is modified simply so that no effor~ is wasted to find information already .
known. For example, once the DIS of the first endpoint is known and it is known that the second endpoint is not in the DIS, this information should not be recomputed. If it has been found that a vertex is not in the DIS of its previous .. ;. .
vertex, and it is known on which invisible side the previous vertex is, once the edge connecting these vertices is clipped, the mentioned information is not computed again. Other modifications are of a minor, admini~trative nature. More details of the modification are described in a later section.

4. Incl~ing ~indow Corners Window corners are included only immediately after an invisible group has been processed. In the following, the first group and the last group will be ignored for the moment.
A register called the homing register is created, which is set to zero when the processing of the first vertex of an invisible group is started. Every time the DIS is ; changed, the homing register is increased by one if the new DIS is the next invisible sid~ counterclockwise to the old .; .
DIS. It is decreased by one if the new DIS is the next invisible side clockwise to the old DIS. If the new DIS is opposite to the old DIS, the homing register is either increased by two or decreased by two. For example, if the old DIS is the invisible side of the right boundary line and the new DIS is the invisible side of the left boundary line, the lask vertex with the old DIS is in the top right corner region, and the first vertex with the new DIS is in the left ; edge region, the homing register is increased by two. On the other hand, if the last vertex with the old DIS is in the right bottom corner region and the first vertex with the new DIS is in the left edge region, the homing register is ;
~5 decreased by two.
After the whole invisible group has been processed, ~ if the value of the homing register is positive, all the ; window corners between the previous intersection point and the , ' , intersection point following the last vertex of the invisible group in the counterclocXwise direction are included. If the homing register is negative, all the window corners between the previous intersection point and the intersection point following the last vertex of the invisible group in the clockwise direction are included. The absolute value of the homing register is at most four, so there is no repeated window corner between any two intersection points. See Fig.
9, in which case (a) shows two examples where the homing register should be increased or decreased by two. Case (b) shows examples where the homing register should be increased or decreased by one.
,~ , . . .
;; The homing register of the first-group is computed i in the same way if the first vertex of the polygon is : .
invisible. The only difference is that the value of the ,,;i homing register and the DIS of the first vertex are stored.
After the last group is processed, the homlng values of the last group and the first group are summed. The DIS of the last vertex of the last group is then compared to the stored DIS. If they are not the same and the stored DIS is the next invisible side counterclockwise to the last DIS, the combined homing value is increased by one. If they are not the same and the stored DIS is the next invisible side clockwise to the last DIS, the combined homing value is decreased by one. Th~
usual procedure is then followed to include the window corners . , between the two intersection points.
If the polygon consists of only one invisible group, ~he homing value of the first group is increased or decreased ; ~ ,, . : :

~ by one i~ the DIS of the last vertex i~ not the same as the ;~ stored DIS, in the same way as described above. I~ the homing value is not zero, all the window corners are included as the whole window is in the interior of the polygo~. Otherwise, the output polygon is empty.

: .
5. In~egration ;, The main procedure of the algorithm is as shown in Table 3 below. The variables needed to administrate the loop lo are first initialized. The region in which the first vertex .
of the polygon lies is then determined. The groups are then processed one by one. Window corners that should be included in the ~irst and last groups are then attended to.

:, . .
... . .
T~B~E _3 . . .

procsduro CllpPolygon(xlo~t,xri~ht,ybottom,ytop:roal InputPolygon:polygon;Yar OutputPolygon:polygon);
v~r ~ l:lntag~r;
: F~r~tIn~lndoY:boolaan; (~ TRUE li tha iir~t vort~r o~ tho poly~on i6 . in th~ ~indo~
;~ DIS: lnto~or;
bagln i:-l; . , ~o~rlg: -, O;
OutputPolygo~. Ai2~: =0;
(~ ch~c~ ln ~hich ~ogion th0 iiY8t Y~rtes i8 ~) DIS:=Null; . : , :
i~ InputPol7gon.x~1]<~ t th~n DIS:=lait ..
. 0180 i~ InputPolygon.x W ~3r~ght than DIS:=right elso i~ InputPolygon.y~1 k ybotto~ th~n DIS:=botto~
ol~o i~ InputPolggon.~l]>ytop th~n DIS:=top;
`:

. . .
.

. .. , . ~
. ~ - -:
.

FlrntInUlndou:=DIS=Null; 1 328 1 36 ~irnt:~DIS o N~ll;
Stor~dDIS:~DIS;
OldDIS:-DIS;
Storodl~omi~l6:=0;
~hllo i<=I~putpolygon~stze do begin ' ca~e DIS o~
~ t:ClipL~tSld~(xl~ right,ybottom,ytop,InputPolygon,OutputPolygon,: DIS,i,~oml~g);
,,; right:Clip~ightS~do~ t,~r~ght,ybottor~, ~ op,~nputPolygon,OlltputPoly~on, D~S,i,~oming);
top:Clip'ropSld~(xlo~t,xri6ht,ybottom,ytop,InputPolygon,OutputPolygon, DIS,l,~omin~); .
~: bottom: ClipBottomSid~(~lo~t,srlght,~bottom,ytop,Inpu~Polygon~
OutputPolygo~,OIS,i,Homi~g);
~ull:Clip~indo~ t,~ight,ybottom,ytop,InputPoly~o~,OutputPolg~on, : DIS,i);.
; ond;
~nd;
: 1~ not Fir~tIn~indo~ th~n bogin i~ DIS~>Stor~dDIS th~ bagi~ .
DIS=boundari~o[Stor~dDIS-l~thon , , ~oming: =~omlng~l ol~
~ oming:=~oming-l;
nnd;
~irs~:zial~;
output ths ~indo~ corn~r~ b~t~e~u th~ las~ intar~ection point oS th~ polygon and tho ~lr~t int0r~ction point o~ th~ polygon ~) prluth(OldDIS,~omi~+Stor~d~omin~,OutputPolygon);
ond;
e~d;
6. Modifications to the Nicholl-Lee-Nicholl Alaorith~
In this section, the modifications done to the Nicholl-hee-Nicholl algorithm to incorporate it in the new polygon clipping algorithm are discussed: first, the modiflcations that save some computations to clip an edge, and then the codes inserted to record information for later use.
(The whole program with the modified version of the Nicholl-,. ..

. .

1 32~ 1 36 Lee-Nicholl algorithm is appended at the end of the main body of this descriptionO) The Nicholl-Lee-Nicholl algorithm referred to in this section is the algorithm presented in the above-cited : 5 paper by Nicholl, Lee, and Nicholl. The names of the . procedures of the algorithm in that paper will be used in this section.
, . ' .
.~, ç
6.(a) Modi~ications to Save_~perations 0 . The Nicholl-Lee-Nicholl algorithm is used to clip an . edge (formed by connecting two consecutive vertices) in two situations. The first situation is when the first of the two ; , . .
vertices is in the window while the second vertex is not. In this situation, the Nicholl-Lee-Nicholl algorithm is used to compute the intersection point where this edge intersects the window. The DIS of the second vertex is also set to be the invisible side of the boundary line the edge intersects.
The second situation is when the first vertex is : invisible and the second vertex is not on the DIS of the first vertex. In this case, the Nicholl-Lee-Nicholl algorit~m is used to clip the line and to compute the intersection points . where the edge intersects the window. The number of :
:~ intersection points can be none, one or two. In the cases wh re non2 or two.intersection points are ~ound, the DIS of ;
the second endpoint of the edge is also set.
Two pieces of information are known when the , Nicholl-Lee-Nicholl.algorithm is invoked: the invisible side . .
~ the first vertex is on and the invisible side the second : .

.

~ 1 3~8 1 36 vertex is not on. Normally, these two pieces of information need two comparisons to obtain. However, the Nicholl-Lee-Nicholl algorithm is modified in a way that these operations ; are not performed.
The Nicholl-Lee~Nicholl algorithm always checks the first vertex to see whether it is ~o the le~t o~ the left boundary line, to the right of the right boundary line, or . . .
; none of the above. This is the first step of the algorithm.
This is not needed in the new polygon clipping algorithm because the invisible side the ~irst vertex is on is already `~ known. ~he Nicholl-Lee-Nicholl algorithm is also modified so that the main procedure, called "clip" where the first step is performed, is æimply omitted. Instead, the procedure called "leftcolumn'' is always used to start clipping the edge. The procedure called "centrecolumn" is omitted. Of course, proper geometric kransformations are needed in some cases.
It is obvious that the Nicholl-~ee Nicholl algorithm is not invoked when the second vertex is on the DIS of the first vertex. In the Nicholl-Lee-Nicholl algorithm, oncs the ~ 20 first step, mentioned above, is done, it proceeds to check if `~ the second vertex is also on the same invisible side. This is not necessary and is omitted. Specifically, the following code are omitted from the beginning of procedure 'lleftcolumn":

if x2 < xleft then display :- false else .

.;
: - ~ ,,;:

. . .

`
A similar piece of code is a~so deleted from the procedure "leftedge":

if x2 < xleft then display := false else i ' 6.~b) Modifi~ations to Record Information Every time the Nicholl-~ee-Nicholl algorithm is 10 invoked, either a new group is encountered (when there are intersection points) or the current DIS of the invisible group being processed must be changed. In both cases, the boundary llnes intersected by the edge clipped and the number of intersection points must be known.
. 15 When there is one intersection point, if the current group is invisible, then the next group mu~t be visible. The number o~.intersection points is instrumental to decide this.
When there are two intersection points, the invisible:side of the.boundary line the second intersection point is on is the initial DIS of the next group, an invisible group. Both the.number of intersection points and the boundary ~; lines.the edge intersects are important.
When.there is no intersection point, the current DXS
must be changed. The way the DIS is updated has beendiscussed : 25 previously. Basically the new DIS is one of the invisible sides the..second vertex is on which is theclosest to the current DIS (in the clockwise or counterclockwise direction).
.. ..
The opposite invisible side of the current DIS is considered to be farther..than the other two invisible sides from the current DIS.
' :
` :

.~ .
.' ~ . ~ .

There are many ways of recording these two pieces of information: the number of intersection points and the boundary lines the intersection poin~s are on. An example o~
the implementations possible shall be given.
A variable called "IPnumber" is used to store the number of intersection points. An array called "sides" is used to store the boundary lines the intersection points are on. In the ca~e where there is no in~ersection point, it stores the closest invisible side. These two variables supercede the variable "display" in the original algorithm.
~ These variables are set whenever an intersection point is computed or the computation to ascertain that there is none is performed. Since the boundary lines the edge intersects must be known before the intersection points can be computed, this information is recorded. The invisible sides the second vertex is on must be found before the conclusion that the~e is no intersection point can be drawn. This information is simply recorded.
The code given in Table 4 below i~ for the insertions o~ codes needed for one of the procedures in the Nicholl-Lee-Nicholl algorithm. The pieces of codes underlined are not in the original algorithm. The lines of codes containing either the variable "IPnumber" or the variable "sides" are used to record the information mentioned.

procedure in~ide ~xleft, ytop, xright, ybottom: real;
var xl,yl,x2,y2: real; v~r IPnumber:integer;lrar side~:InvSide~
begin if x2 < xleft then begil}
~ide~ll]:=left;
p21eit (xleft, ytop, xright, ybottom, x1, yl, x2, y2~);
IPnumber:=1;
end ~ 27 `; ., ~ , : , ' ' e1s~ if x2 > xright the~ beg~rl - ~ide9~ ~rigllt; 1 3 2 8 1 3 6 rotatel80c (xl, yl);
rotatel80c~(~ide~);
rotatel80c (x2, y2);
p21eft (--xright,--ybottom,--xleft,--ytop, xl, yl, x2, y2,~);
~otatel80c (xl, yl);
rotatel80c~(side~);
I rotatel80c (x2, y2);
number:=l;
end else if y2 ~ ytop thell begin ~ides[l]:=top;
x2 := xl ~ t2--xl) * (ytop--yl)/(y2--yl);
y2 := ytop;
IPnumb~,r.--l;
end e1se begin sidesll]:=bott~m;
x2 := xl + (x2--xl~ * (yb~ttom--yl)/(y2 yl);
y2 := ybotts:~m;
IPnumber:=l;
end;
end inside;
The other procedures of the Nicholl-Lee-Nicholl algorithm are modified similarly.
In the procedure above, the procedure "rotatel80cs"
is not in the original algorithm. This procedure is used to perform geometric transformations for the boundary lines recorded in the array "sides". In this case, it rotates the values of the array so that originally left boundary line now becomes the right boundary line. In other words, it performs the same task as the procedure "rotatel80c" but instead of on a point, it is on an array of boundary lines. In fact, there is a procedure to transform the array for each procedure to transform a vertex~
7. Analysis The algorithm of the present invention is analysed in five aspects: the operations to discard an invisible .
vertex, the operations to accept a visible vertex, the .

" 1328136 operations to compute an intersection point, the operations to include a window, and the administrative overhead.

; 7.(a) Invisible vertices In the algorithm of the present invention, one comparison is needed to reject an invisible vertex. Of course, one more comparison is needed in the beginning of an invisible group to start the processing and one more comparison is needed whenever the DIS chang~s.

7.(b) Visible vertices The algorlthm of the present invention uses four comparisons to accept a visible vertex.

7.(c~ Intersection PoL~ts The operations used to clip an edge in the polygon in the algorithm of.the present invention is the same as in the Nicholl-Lee-Nicholl line-clipping algorithm. That is, : about 1 addition, 3 subtractions, 1 multiplication and 1 : division at best for each intersection point and 1 or at mosk ~ 20 two more arithmetic operations at worst. The number of - comparisons needed is 6 at worst.

, 7.(d) . Window.Corners :
In the present invention, about 5 subtractions and 3 multiplications are needed to change the DIS each time.
Including the operations needed in the window corner inclusion algorithm, a few more comparisons and a few more increment .

: , . . . . .: .
... . .. ..

operations tto increa6e a rsgi~tQr by 1) and decrement operations (to decrease-a register by 1 ) must be added.

7.(e) QYçrhead The overheads to admini6trate loops to proce~s the vartices cannot be:avoided.
The overhead~ of the three algorithms are the 6ame for the.administration of loops in the algor~thms.
. The number of procedure calls and assignment statements are significantly greater in thu new algorithm than in the prior art algorithm~. However, ~ince ~t is anticipat~d .that this polygon cllpping algorithm will be implemented in ..
hardware and procedures can be tra~sformed.~nto macros, thi~
.. . .
should not be a signif icant problem.

~
To produce.a new polyline clipping algorithm from the new polygon clippiny algorithm, the following modi~ications are made.
.~.~ , . .
~ . .1. The window inclu~ion ~cheme is deleted.
. . . .
, 20 . 2. The invisible groups are simply diQcarded. Every : i :
- . visible group i~ output separately. The~e visible . -~ . . groups include the first and the last groups i~ ~h~y are visible.
.. ., j , . . -:~ . ,;,.. . . . . ..
I 25 9___S9~ i9~
. .
.. The..new.algorithm is very efficient in processing vi~ible and invisible vertices in terms of the number o~

: .
,; . , ~ :. , .

.
.
. , ~

operations needed. It has about the same number of operations as the other algorithms when computing intersection points.
It has about the same number of operations as the Sutherland-Hodgman algorithm in the window corner inclusion aspect but needs more operations than the Liang-Barsky algorithm. As it does not generate repetitive sequences of window corners, it generates the fewest instances of window corners. The improvements the new algorithm makes in including window corners contributes to this being a good and efficient algorithm for clipping polygons against rectilinear rectangular windows. As a by-product, there is also a new polyline clipping algorithm which also uses the coherence property.
.
It will be appreciated that the above description relates to the preferred embodiment by way of example only~
Variations on the invention will be obvious to those knowledgeable in the field, and such obvious variations are within the scope of the invention as described and claimed, whether or not expressly described.
On the immediately following pages, a Pascal implementation of algorithm, including the modified Nicholl-Lee-Nicholl algorithm, is provided.

~( . , .;

:. .

, .
:``

- ..

:: : -_ .. . .. .. . .. . .
type polygon=record size:integer:
x:array[1..1000] of real:
y:axray~1..1000] of real;
end;
var xleft,xright,ytop,ybottom:real;
InputPolygon, OutputPolygon:polygon;
procedure ClipAPolygon(Inputpolygon:polygon; xleft, xright, ybottom, ytop:real;
var OutputPolygon:polygon);
const left-1;
bottom-2;
right=3;
top~4;
window=20;
Null=20;
type InvSides~array[0..2] of integer;
var i:integer;
boundaries:array[-3~.24] of integer;
BoundaryValueX:array[0..1]of real;
BoundaryValueY:arrayl0..1]of real:
Homing:integer;
DIS:integer:
StoredHoming, StoredDIS:integer;
first:boolean;
OldDIS:integer;

~* Start of the line~clipping routines *) ~* The algorithm used is the NLN algorithm with minor modifications *) ~* Some procedures of that algorithm which are not used are deleted *) ~*___~~__~~~____~~~~_ ) 'i . .
procedure rotate90c ~var x,y:real);
var , t: real;
begin t :~ xt x ~ y;
y :=~ ~t;
end;
procedure rotate90cs~var sides:InvSides);
var i:in~eger;
begin for i:~0 to 2 do sides[i]:=boundaries[sides~i]~1];
end;
procedure rotatel80c (var x,y : real);
begln .~ X et ~ X;
~' y ~ ~y;
~' end;
' procedure rotatel~Ocs(var sides:InvSides);
var i:integer;
begin ~2 . , ;: : . . . .
: ~ - ,.; . :

.. .. .. . . .
for i:~O to 2 do sides~i]:=boundaries~sides~i]-2];
end:
procedure rotate270c (var x,y : real):
var t : real:
begin t : x:
x:-- --y:
y : t;
end;
procedure rotate270cs(var sides:InvSides);
var : i:integer;
begin for i: 30 to 2 do sides~i]:~boundaries~sides[1]-3]:
end:
procedure reflectxminusy ~var x,y : real):
var t : real:
begin t : x:
x: ~ --y:
y : -t;
end:
procedure reflectxminusys(var sides:InvSides);
var i:integer; .
begin for i:~O to 2 do if sides~i] mod 2 - Othen sides~ boundaries[sides~i]+1 else sidesli]:~boundaries[sides[i]-1];
end;
procedure reflectxaxis (var x,y: real);
begin y :~ --y;
end;
procedure reflectxaxiss(var sides:InvSides);
var i:integer;
begin for i:=O to 2 do if sides~i] mod 2 = O then sides[i]:=boundaries~sides[i]~2];
end:
procedure leftbottomregion (xleft, ytop, xright, ybottom: real:
var xl,yl,x2,y2: real: var IPnumber:integer:
relx2, rely2, leftproduct : real: var sides:InvSides);
var bottomproduct, rightproduct : real:
begin if y2 >~ ybottom then begin IPnumber:=1:
sidesll]:=left;
if x2 > xright then begin IPnumber:~2;
~5 3 -, . . -'' ~

~ 1 328 1 36 ...... .
y2 :~ yl + (xright - xl~ * rely2/relx2s x2 : xright;
sides[2]:-right;
end;
yl :; yl + leftproduct/relx2;
xl :~ xleft;
~: end else begin bottomproduct :- (ybottom - yl~ * relx2:
if bottomproduct > leftproduct then begin if yl > ytop then begin sides~O]:~right;
IPnumber:-O;
end else begin sides~O]:=bottom;
IPnumber:=O:
1 end;
end else begin if x2 > xright then begin rightproduct :- ~xright - xl) * rely2;
if bottomproduct > rightproduct then begin x2 :- xl + bottomproduct/rely2;
y2 :- ybottom;
sides[2]: bottom;
end else begin y2 :;;~ yl + rightproduct/relx2;
. x2 : xright;
sideq[2]:-right;
end;
end else begin : x2 :- xl + bottomproduct/rely2;
., y2 :~ ybottom;
:~1 sides~2]:~bottom;
end;
I yl := yl + leftproduct/relx2;
:~i . xl := xleft;
-1 sides~1]:=left:
1 IPnumber-~2;
:~ end end end { leftbottomregion } ;
. .
procedure topleftcorner (xleft, ytop, xright, ybottom: real;
var xl,yl,x2,y2: real; var IPnumber:integer; var sides:InvSides);
var relx2, rely2, topproduct, leftproduct: real;
I begin :( if y2 > ytop then begin sides[O]:~top:
::~ IPnumber:~O;
:~ end ~ else begin :j relx2 := x2 - xl;
rely2 := y2 - yl;
topproduct := tYtoP - yl) * relx2 ;
leftproduct := ~xleft - xl) * rely2;
~j if topproduct > leftproduct then begin . leftbottomregion (xleft, ytop, xright, ybottom, xl, yl, x2, y2, IPnumber, relx2, rely2, leftproduct,sides);
end else begin .

~ ' :
: . .
: ' . ~ ~

.
reflectxminusy ~xl, yl~;
reflectxminusys(sides);
reflectxminusy (x2, y2);
leftbottomregion (-ytop, -xleft, -ybottom, -xright, xl, yl, x2, y2, IPnumber, -rely2, -relx2, topproduct,sides);
reflectxminusy (xl, yl);
reflectxminusys(sides);
reflectxminusy (x2, y2) end end end { topleftcorner } ;
procedure p2bottom ~xleft, ytop, xrighk, ybottom :real;
var xl,yl,x2,y2: real; var IPnumber:integer;var sides:InvSides);
var relx2, rely2, leftproduct, bottomproduct, rightproduct: real;
begin relx2 :- x2 - xl;
rely2 :- y2 - yl;
leftproduct := (xleft xl) * rely2;
bottomproduct := (ybottom - yl) * relx2;
if bottomproduct > leftproduct then begin side 8 [O]:~bottom;
IPnumber:;O;
. end : else begin if x2 <= xright then begin x2 : xl + bottomproduct/rely2;
y2 :- ybottom;
sides[2]:~bottom;
end else begin rightproduct :- (xright - xl) * rely2;
if bottomproduct > rightproduct then begin x2 :~ xl ~ bottomproduct/rely2;
y2 := ybottom;
sides[2]:~bottom;
end else begin i y2 :- yl ~ rightproduct/relx2;
x2 :~ xright;
sides[2]:~right;
end;
` end;
yl :- yl + leftproduct/relx2;
xl D xleft:
IPnumber:=2;
sides[1]:=left;
end end { p2bottom } ;
~. procedure leftedge (xleft, ytop, xright, ybottom : real;
var xl,yl,x2,y2: real; var IPnumber:integer;var sides:InvSides);
var relX2~ rely2: real;
begin if y2 < ybottom then begin p2bottom (xleft, ytop, xright, ybottom, xl, yl, x2, y2, IPnumber,sides), end else if y2 > ytop then begin reflectxaxis (xl, yl);
reflectxaxiss(sides);
reflectxaxis (x2, y2);
p2bottom (xleft, -ybottom, xright, -ytop, xl, yl, x2, y2,IPnumber,sides);
reflectxaxis (xl, yl);
reflectxaxiss(sides);

.
.. ,, , . , ~ .
. -- , .
., , :- .

~ . .
. . : , , ' ,'', . ' . ' . .' -. ~ . .

reflectxaxis (x2, y2) end else begin relx2 :- x2 - xl;
rely2 :~ y2 - yl:
IPnumber:-1;
if x2 > xright then begin : y2 :~ yl + rely2 * (xright - xl)/relx2;
x2 :~ xright;
IPnumber:-2;
sides[2]:~right;
end;
yl : yl + rely2 * (xleft - xl)/relx2;
xl : xleft;
sides~1]:=left;
end end { leftedge ~ ;
procedure leftcolumn (xleft, ytop, xright, ybottom: real:
var xl,yl,x2,y2: real; var IPnumber:integer;var sides:InvSides);
begin if yl > ytop then begin topleftcorner (xleft, ytop, xright, ybottom,xl,yl,x2,y2,IPnumber,sides);
: end else if yl < ybottom then begin reflectxaxis (xl, yl);
reflectxaxiss(sides);
reflectxaxis (x2, y2);
, topleftcorner(xleft,-ybottom, xright, -ytop,xl,yl,x2,y2,IPnumber,sides);
i reflectxaxis (xl, yl);
reflectxaxiss(sides);
reflectxaxis (x2, y2) end el e begin leftedge (xleft, ytop, xright, ybottom,xl,yl,x2,y2,IPnumber,sides);
end:
end { leftcolumn } :
I procedure p21efttop (xleft, ytop, xright, ybottom: real;
3 var xl,yl,x2,y2: real;var sides:InvSides);
`, var relx2, rely2, leftproduct, topproduct: real;
` begin . relx2 := x2 - xl;
: rely2 := y2 - yl;
leftproduct := rely2 * (xleft - xl) topproduct := relx2 * ~ytop - yl);
if topproduct > leftproduct then begin :
x2 c xl + topproduct ~ rely2;
y2 := ytop;
sides[1]:ctop;
: end else begin y2 := yl + leftproduct / relx2; `
x2 := xleft;
sides[1]:=left;
end;
end ~ p21efttop } ;
procedure p21eft (xleft, ytop, xright, ybottom: real;
var xl,yl,x2,y2: real;var sides:InvSides);
~ begin if y2 > ytop then begin p21efttop (xleft, ytop, xright, ybottom, xl, yl, x2, y2,sides) end else if y2 < ybottom then begin .

~ `
. ;'.

`- -- 1 328 1 3~
rotate90c (xl, yl);
rotate90cs(sides);
rotate90c (x2,y2);
p21efttop (ybottom, -xleft, ytop, -xright, xl, yl, x2, y2,sides)-rotate270c (xl, yl);
rotate270cs(sides);
rotate270c (x2,y2) end else begin y2 :~ yl + (y2 - yl) * (xleft - xl)/(x2 - xl);
x2 : xleft:
sides~1]:-left:
end end { p21eft } :
procedure inside (xleft, ytop, xright, ybottom: real:
var xl,yl,x2,y2: real var IPnumber:integer:var sides:InvSides):
begin if x2 < xleft then begin sidesll]:~left;
p21eft (xleft, ytop! xright, ybottom, xl, yl, x2, y2,sides);
IPnumber:-l;
end else if x2 > xright then begin sides[l]:~right;
rotatel80c (xl, yl);
rotatel80cs(sidesi)~
; rotatel80c (x2, y2):
p21eft (-xright, -ybottom, -xleft, -ytop, xl, yl, x2, y2,sides)-`; rotatel80c (xl, yl):
rotatel80cs(sides):
rotatel80c (x2, y2):
IPnumber:~l:
end else if y2 > ytop then begin sides[l]:=top;
x2 :~ xl + (x2 -xl) * ~ytop - yl)/(y2 - yl);
y2 : ytop;
! Ipnumber:=l;
end else begin sides[l]:=bottom;
x2 :~ xl + (xZ - xl) * (ybottom - yl)/(y2 - yl);
` y2 := ybottom;
; IPnumber:~l~
end:
end { inside } ;

(* Start of the codes for polygon clipping only *) _________________~*~
.~
procedure OutputVertex(var Outpolygon:polygon; xl, yl:real);
var size:integer;
~; begin size:=Outpolygon.size+l;
Outpolygon.size:-size;
~ Outpolygon.x[size]:~xl;
i Outpolygon.y[size]:~yl;
end;
procedure in_region(x,y,xleft,xright,ybottom,ytop:real;var DIS:integer);
begin DIS:~Null;
if x<xleft then ~ 3 7 ':, ., . , ., , . ., :

. .: . ., . :
,, ~ .. . .

. .
- : ., DIS:-left else iP x>xright then DIS:~right else lf y<ybottom then DIS: bottom else if y>ytop then DIS:-top;
end;
procedure printhp(DIS:integer;h:integer;var OutputPolygon:polygon);
begin i~ h>0 then begin printhp(boundaries[DIS-l],h-l,OutputPolygon):
OutputVertex(OutputPolygon,BoundaryValueX~(DIS-l) div 2], BoundaryValueY[DIS mod 4 div 2]);
end;
end;
procedure printhn(DIS:integer;h:integer;var OutputPolygon:polygon);
begin if h<0 then begin printhn~boundaries[DIS+l],h+l,OutputPolygon);
OutputVertex~OutputPolygon,BoundaryValueX[~DIS-l) div 2], BoundaryValueY[~DIS mod 4)div 2]);
end;
end;
procedure printh(DIS:integer;h:integer;var OutputPolygon:polygon);
begin if first then begin first:~false;
StoredHoming:=h;
OldDIS:~DIS;
end else begin if h>0 then begin printhp(DIS,h,OutputPolygon);
end else begin DIS:=boundaries[DIS+l];
~! printhntDIS,h,OutputPolygon);
I end;
;! end;
end;
procedure ClipRightSide(xright:real;InputPolygon:polygon:
var OutputPolygon:polygon; var DIS:integer; var i,Homing:integer);
var xl,yl,x2,y2:real;
IPnumber:integer;
sides:InvSides;
begin IPnumber:=0;
repeat i :=i+l;
until(i>InputPolygon.size)or(InputPolygon.x[i]<=xright);
sides[0]:=Null;
sides[l]:=Null;
,~ sides[2]:=Null;
if(i<=InputPolygon.size)then begin xl:~InputPolygon.x[i-l];
yl:=InputPolygon.y[i-l];
x2:=InputPolygon.x[i];
y2:=InputPolygon.y[i];
rotatel80c(xl,yl);
rotatel80cs(sides);

rotatel80c(x2,y2~;
leftcolumn(-xright,-ybottom,-xleft,-ytop,xl,yl,x2,y2,IPnumber,side3);
rotatel80c(xl,yl);
rotatel80cs(sides);
rotatel80c(x2,y2):
if IPnumber<>0 then begin if sides[l]-top then Homing:~Homing+l else lf sides[l]-bottom then Homing:~Homing-l;
printh(sides[l],Homing,OutputPolygon);
Homing:-0:
OutputVertex(OutputPolygon,xl,yl):
DIS:~window if IPnumber=2 then begin OutputVertex(OutputPolygon,x2,y2):
DIS:~sides[2]:
end;
end else begin DIS:=sides[0];
if DIS-top then Homing:sHoming~l : else if DIS=bottom then Homing:~Homing-l `
else if yl>ytop then Homing:=Homing+2 else Homing:~Homing-2;
end:
end:
end:
procedure ClipTopSide(ytop:real:InputPolygon:polygon:
var OutputPolygon:polygon;var DIS:integer var i,Homing:integer) var xl,yl,x2,y2:real:
:: IPnumber:integer:
sides:InvSides:
begin IPnumber:-0;
repeat i :=i~l;
until (i>InputPolygon.size)or(InputPolygon.y[i]<=ytop);
sides~l]:~Null;
. sides[2]: Null:
if(i<-InputPolygon.size)then begin xl:=InputPolygon.x[i-l];
yl: InputPolygon.y[i-l]:
x2:~InputPolygon.x[i];
y2:=InputPolygon.y[i]:
rotate270ctxl,yl);
rotate270cs(sides):
rotate270c(x2,y2); `
leftcolumn(-ytop,xright,-ybottom,xleft,xl,yl,x2,y2,IPnumber,cides);
rotate90c(xl,yl):
rotate90cs(sides):
rotate90c(x2,y2):
if IPnumber<>0 then begin if sides~l]=left then Homing:=Homing~l else if sides[l]=right then Homing:=Homing-l:
: printh(sides[l],Homing,OutputPolygon):
Homing:=0:
OutputVertex(OutputPolygon,xl,yl):

,, , - , DIS:-window;
if IPnumber~2 then begin OutputVertex(OutputPolygon,x2,y2);
DIS:-sides~2];
end;
end else begin DIS: sides[0];
if DIS~left then Homing:=Homing+1 else if DIS~right then Homing:-Homing-1 else if xl<xleft then Homing:-Homing~2 else Homing:~Homing-2;
end;
end;
end;
procedure ClipBottomSide(ybottom:real;InputPolygon:polygon;
var OutputPolygon:polygon; var DIS:integer;var i,Homing:integer);
var xl,yl,x2,y2:real;
IPnumber:integer;
sideq:InvSides;
, begin IPnumber:=0;
repeat i: ;i+l;
until~i>InputPolygon.size)or~InputPolygon.y[i]>-ybottom);
sides~0]:=Null;
sides[1]:=Null;
~ides[2]:-Null;
if(i<~InputPolygon.size)then begin i xl:YInputPolygon.xli-1];
yl:~InputPolygon.y[i-1];
x2:=InputPolygon.x[i];
i y2:~InputPolygon.y[i];
rotate90c(xl,yl);
rotate90cs(sides);
i rotate90c(x2,y2);
leftcolumn(ybottom,-xleft,ytop,-xright,xl,yl,x2,y2,IPnumber,sides);
rotate270c(xl,yl);
rotate270cs(sides);
rotate270c(x2,y2);
if IPnumber<>0 then begin if sides[l]=right then Homing:=Homing-~l else if sides[l]=left then . Homing:-Homing-1:
I printh(sides[l],Homing,OutputPolygon);
: Homing:=0;
OutputVertex~OutputPolygon,xl,yl);
. DIS:=window; -if IPnumber=2 then begin : OutputVertex(OutputPolygon,x2,y2);
.j DIS :=RideS [2];
end;
end else begin DIS:=sides[0];
if DIS=right then Homing:=Homing+1 else if DIS eleft then Homing:~Homing-l 4~

~ 328 1 36 _ .. . _ .. ... .. .. . .
else if xl>xright then Homing:~Homing+2 else Homing:=Homing-2;
end;
end;
end;
procedure ClipWindow~xleft,xright,ybottom,ytop:real;InputPolygon:polygon;
var OutputPolygon:polygon;var DIS:integer;var i:integer);
var xl,yl,x2,y2:real;
IPnumber:integer;
~ides:InvSides;
begin if i~ InputPolygon.size then begin IPnumber:~0;
in_region(InputPolygon.x[i],InputPolygon.y[i], xleft,xright,ybottom,ytop,DIS);
while(i<-InputPolygon.size)and(DIS=window)do begin OutputVertex(OutputPolygon,InputPolygon.x[i],InputPolygon.y[i]t;
i :-i+'l;
in region(InputPolygon.x[i],InputPolygon.y[i], xleft,xright,ybottom,ytop,DIS);
end;
sides[0]:~Null;
sides[l~:eNull;
sides[2]:-Null;
if(i>InputPolygon.size)then begin OutputPolygon.size:=OutputPolygon.size-1;
end else begin xl:-InputPolygon.x[i-1];
yl:-InputPolygon.y[i-1]:
x2:-InputPolygon.x[i];
y2:~InputPolygon.y[i]:
insidetxleft,ytop,xright,ybottom,xl,yl,x2,y2,IPnumber,sides);
OutputVertex(OutputPolygon,x2,y2);
DIS:~sides[1];
end;
end;
end:
procedure Clip~eftSide(xleft:real;InputPolygon:polygon;
var OutputPolygon:polygon; var DIS:integer; var i,Homing:integer);
var xl,yl,x2,y2:real;
IPnumber:integer;
sides-InvSide3;
begin IPnumber:~0: -repeat i :=i+l;
i until (i~InputPolygon.size)or(InputPolygon.x[i]>=xleft);
sides[0]:~Null:
sides[l]:~Null;
sides[2]:=Null;
if(i<=InputPolygon.size)then begin xl:-InputPolygon.x[i-1];
yl:=InputPolygon.y[i-l];
x2:-InputPolygon.x[i];
y2:=InputPolygon.y[i]:
leftcolumn(xleft,ytop,xright,ybottom,xl,yl,x2,y2,IPnumber,sides);
if IPnumber<>0 then begin if sides[1]=bottom then ` Homing:=Homing+1 else if sides[1]=top then 4'1 , .
, .

-- . 1 328 1 36 ... . .
Homing:-80mlng-l:
printh(sldes[l~,~omlng,OutputPolygon):
Homing:~O:
OutputVertex~OutputPolygon,xl,yl);
DIS:~wlndow:
if IPnumber~2 then begin OutputVertex~OutputPolygon,x2,y2)3 DIS:~Qldes[2]:
end:
end else begin DIS:-sideq[O];
if DIS-bottom then Homing:=Homing+l else if DIS=top then Homing:~Homing-l else if yl<ybottom then Homing: 80ming+2 : el~e Homing:=Homing-2 end:
end:
end, procedure ClipPolygon(xleftrxright,ybottom,ytop:real:
InputPolygon:polygon:var OutputPolygon:polygon):
var i:integer;
FirstInWindow:boolean;
~IS:integer;
begin i:~ l Homing: 0:
OutputPolygon.size:=O;
in_region~InputPolygon.x[l],InputPolygon.y[l], xleft,xright,ybottom,ytop,DIS);
Fir~tInWindow:-DIS~Null:
first:-DIS<>Null:
StoredDIS:;DIS-OldDIS:~DIS:
StoredHoming:=O;
while i<=InputPolygon.size do begin case DIS of left: ClipLeftSide~xleft,InputPolygon,OutputPolygon,DIS,i,Homing);
rlght:ClipRightSide(xright,InputPolygon,OutputPolygon,DIS,i,80ming);
. top: ClipTopSide(ytop,InputPolygon,OutputPolygon,DIS,i,Homing)-bottom: ClipBottomSide(ybottom,InputPolygon,OutputPolygon, DIS,i,Ho~ing);
window:ClipWindow(xleft,xright,ybottom,ytop,InputPolygon, OutputPolygon,DIS,i);
end, ; end;
if not FirstInWindow then begin if DIS<>StoredDIS then begin i DIS~boundaries[StoredDIS-l]then 80ming:~Homing+l else 80ming:=Homing-l, end;
first:=false;
printh(OldDIS,Homing+StoredHoming,OutputPolygon);
end;
end;
begin BoundaryValueX[O]:~xleft;
4~

. ~ .
, BoundsryValueXIl]~-xrlght~
BoundaryValueY[0]t~ytops BoundaryValueY[1]:-ybottomJ
boundaries[-3]:-lefts boundaries[-2]:-bottom;
boundaries[-l]:-right;
boundaries[0]:-top:
boundaries[1]:-left;
boundaries[2]:-bottom;
boundaries[3]:~i;right;
boundaries[4]:-top;
boundaries[5]:-left;
boundaries[6]:~bottom;
boundaries[7]:~right;
boundaries[8]:~top;
boundaries[16]:=Null;
boundaries[17]:=Null;
boundaries[18]:-Null;
boundar~es[l9]:~Null;
boundaries[20]:=Null;
boundaries[21]:=Null;
; boundaries[22]:~Null;
boundaries[23]:eNull;
boundaries[24]:~Null;
InputPolygon.size:-InputPolygon.size+1;
InputPolygon.x[InputPolygon.size]:-InputPolygon.x[1];
InputPolygon.y[InputPolygon.size]: InputPolygon.y[1];
ClipPolygon(xleft,xright,ybottom,ytop,InputPolygon,OutputPolygon);
end.

.
..
.. ..

.: :
:: . .... .. -' :
, ! ' ., , ' , : ' , ' ~ ' ~ . ' . ' . ' ' ' ' ,' ',

Claims (5)

THE EMBODIMENTS OF THE INVENTION IN WHICH AN EXCLUSIVE PROPERTY
OR PRIVILEGE IS CLAIMED ARE DEFINED AS FOLLOWS:
1. A method of clipping polygons against windows in which imaginary boundary lines correspond to window borders, extensions of the imaginary boundary lines divide the 2-dimensional plane into regions, the side of the boundary lines on which the window lies defines the visible side, and the other side of the boundary lines defines the invisible side, said method comprising the steps of:
dividing the vertices of the polygon into groups of consecutive vertices with respect to the window;
identifying each group as a visible group or an invisible group; and processing the groups of consecutive vertices together wherein visible groups are processed by comparing each vertex with the window borders and clipping the edge of the polygon between consecutive vertices of adjacent groups using a line clipping algorithm and the invisible groups are processed by initially determining the location of the first vertices in the invisible group and designating that region as the designated invisible side (DIS), comparing the next vertex with the DIS to determine if that vertex is in the DIS and continuing until a vertex is found which is not in the DIS, and clipping the edge of the polygon between consecutive vertices which are in the DIS and not in the DIS respectively to determine whether there are intersection points between the edge and the window boundary.
2. A method of clipping polygons as claimed in claim 1 wherein the clipping algorithm is a modified Nicholl-Lee-Nicholl line clipping algorithm and wherein the Nicholl-Lee-Nicholl algorithm is modified to use information already computed in prior operations.
3. A method of clipping polygons as claimed in claim 1 further comprising the steps of creating a homing register wherein every time a DIS is changed the homing register is increased by one where the new DIS is the next invisible side counterclockwise to the old DIS, is decreased by one where the new DIS is the next invisible side clockwise and is either increased or decreased by two where the new DIS is opposite to the old DIS and once the entire invisible group is processed if the homing register is positive all the window points between the previous intersection point and the intersection point following the last vertex of the invisible group in the counterclockwise direction are included and if the homing register is negative all the window points between the previous intersection point and the intersection point following the last vertex of the invisible group in the clockwise direction are included.
4. A method of clipping polygons as claimed in claim 2 further comprising the steps of creating a homing register wherein every time a DIS is changed the homing register is increased by one where the new DIS is the next invisible side counterclockwise to the old DIS, is decreased by one where the new DIS is the next invisible side clockwise and is either increased or decreased by two where the new DIS is opposite to the old DIS and once the entire invisible group is processed if the homing register is positive all the window points between the previous intersection point and the intersection point following the last vertex of the invisible group in the counterclockwise direction are included and if the homing register is negative all the window points between the previous intersection point and the intersection point following the last vertex of the invisible group in the clockwise direction are included.
5. A method of clipping polygons as claimed in any one of claims 1, 2, 3, or 4, wherein the polygons are polylines.
CA000572974A 1988-07-25 1988-07-25 Polygon and polyline clipping for computer graphic displays Expired - Fee Related CA1328136C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CA000572974A CA1328136C (en) 1988-07-25 1988-07-25 Polygon and polyline clipping for computer graphic displays

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CA000572974A CA1328136C (en) 1988-07-25 1988-07-25 Polygon and polyline clipping for computer graphic displays

Publications (1)

Publication Number Publication Date
CA1328136C true CA1328136C (en) 1994-03-29

Family

ID=4138443

Family Applications (1)

Application Number Title Priority Date Filing Date
CA000572974A Expired - Fee Related CA1328136C (en) 1988-07-25 1988-07-25 Polygon and polyline clipping for computer graphic displays

Country Status (1)

Country Link
CA (1) CA1328136C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112837328A (en) * 2021-02-23 2021-05-25 中国石油大学(华东) A rectangular window clipping and drawing method for two-dimensional polygon primitives

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112837328A (en) * 2021-02-23 2021-05-25 中国石油大学(华东) A rectangular window clipping and drawing method for two-dimensional polygon primitives
US11798206B2 (en) 2021-02-23 2023-10-24 China University Of Petroleum (East China) Method for clipping two-dimensional (2D) polygon against rectangular view window

Similar Documents

Publication Publication Date Title
Pocchiola et al. Topologically sweeping visibility complexes via pseudotriangulations
AU742444B2 (en) System and method for modification of the visual characteristics of digital 3D objects
Gigus et al. Efficiently computing and representing aspect graphs of polyhedral objects
Fournier et al. Triangulating simple polygons and equivalent problems
Kay et al. Ray tracing complex scenes
Overmars et al. New upper bounds in Klee’s measure problem
US5519840A (en) Method for implementing approximate data structures using operations on machine words
Kant Drawing planar graphs using the lmc-ordering
US5630039A (en) Tessellating complex in polygons in modeling coordinates
US20030016221A1 (en) Processing graphic objects for fast rasterised rendering
EP0210554A2 (en) A method of windowing image data in a computer system
Becker et al. Spatial priority search: an access technique for scaleless maps
GB2259432A (en) Three dimensional graphics processing
Overmars Dynamization of order decomposable set problems
Karlsson et al. Scanline algorithms on a grid
US20020138537A1 (en) Method for solving a large sparse triangular system of linear equations
CA1328136C (en) Polygon and polyline clipping for computer graphic displays
Manin Notes on the arithmetic of Fano threefolds
Vassilakopoulos et al. Overlapping quadtrees for the representation of similar images
Fischer et al. Optimal tree layout (preliminary version)
Barequet et al. Translating a convex polygon to contain a maximum number of points
EP1074912A1 (en) Geometry pipeline for computer graphics
Smid Maintaining the minimal distance of a point set in polylogarithmic time
Andersson et al. Binary search trees of almost optimal height
Karlsson et al. Proximity on a grid: Preliminary version

Legal Events

Date Code Title Description
MKLA Lapsed
MKLA Lapsed

Effective date: 19970401