Boolean Operations on Conic Polygons - Springer Link

2 downloads 0 Views 852KB Size Report
Yong-Xi Gong1 (龚咏喜), Yu Liu1,∗ (刘 瑜), Lun Wu1 (邬 伦), and Yu-Bo Xie2 (谢玉波). 1Institute of Remote ... tant role in computational geometry for its good ge-.
Gong YX, Liu Y, Wu L et al. Boolean operations on conic polygons. JOURNAL OF COMPUTER SCIENCE AND TECHNOLOGY 24(3): 568–577 May 2009

Boolean Operations on Conic Polygons Yong-Xi Gong1 (龚咏喜), Yu Liu1,∗ (刘 瑜), Lun Wu1 (邬 伦), and Yu-Bo Xie2 (谢玉波) 1

Institute of Remote Sensing and Geographic Information Systems, Peking University, Beijing 100871, China

2

State Key Laboratory of Information Engineer in Surveying, Mapping and Remote Sensing, Wuhan University Wuhan 430079, China

E-mail: yongxi [email protected]; {liuyu, lwu}@urban.pku.edu.cn; [email protected] Received March 17, 2008; revised January 6, 2009. Abstract An algorithm for Boolean operations on conic polygons is proposed. Conic polygons are polygons consisting of conic segments or bounded conics with directions. Preliminaries of Boolean operations on general polygons are presented. In our algorithm, the intersection points and the topological relationships between two conic polygons are computed. Boundaries are obtained by tracking path and selecting uncrossed boundaries following rule tables to build resulting conic polygons. We define a set of rules for the intersection, union, and subtraction operations on conic polygons. The algorithm considers degeneration cases such as homology, complement, interior, and exterior. The algorithm is also evaluated and implemented. Keywords

1

Boolean operation, conic polygon, topological relationship

Introduction

Computing Boolean operations between polygons is one of the most useful routines applied in different applications[1,2] . Extensive efforts have resulted in very efficient algorithms for Boolean operations on polygons, such as the Sutherland-Hodgman algorithm[3] , the Weiler algorithm[4] , the Bentley-Ottmann algorithm[5] , and the Liang-Barsky algorithm[6] . However, most are limited to certain types of polygons. For example, the Liang-Barsky algorithm requires orthogonal polygons, the Sutherland-Hodgman algorithm and the Weiler algorithm are more suitable for convex polygons, and the Bentley-Ottmann algorithm depends on three properties of line segments for its correctness. In 1990s, several general clipping algorithms for polygons were developed. Maillot extended the Sutherland-Hodgman method to a simpler and more efficient algorithm for polygons clipping[7] . Vatti proposed a generic solution to polygon clipping that are capable of clipping concave, self-intersecting polygon with holes[8] , and Murta improved this method and implemented it with source codes[9] . Greiner and Hormann reported a clipping algorithm for arbitrary closed polygons, specifically where the clip and subject polygons

may self-intersect[10] . Rivero and Feito presented an algorithm to calculate intersection, union, and difference on general planar polygons (manifold and nonmanifold, with and without holes) based on the concept of simplicial chain[11] . This algorithm was further improved by Peng et al. in a simpler, more robust and efficient way[2] . Cai and Zhang introduced the intersection validation testing to fasten the Boolean operation on polygons[12] . Recently, Liu et al. presented a solution to clip polygons based on the entry/exit intersection point property[13] . These algorithms can deal with concave and self-intersecting polygons with holes. Geometries consisting of curves are widely applied in solid modeling, CAD, molecular biology and so on[14] . As a fundamental curve, conic plays an important role in computational geometry for its good geometric properties and flexible control parameters[15] , but little effort has been made on Boolean operations on conic polygons. To our knowledge, most works on Boolean operations on conic polygons were about CGAL① and ECG② . Emiris et al. reported an open curved kernel to offer an exact and efficient curve computation package for CGAL[16] . Berberich et al. provided a computational basis for conic arcs and it was stated that the method they proposed would lead to a

Regular Paper Supported by the National High Technology Development and Research 863 Program of China under Grant Nos. 2007AA12Z216 and 2007AA120502 and the National Natural Science Foundation of China under Grant Nos. 40701134, 40771171, and 40629001. ∗ Corresponding Author ① See homepage of CGAL at http://www.cgal.org ② See homepage of EGC at http://www-sop.inria.fr/prisme/ECG/

Yong-Xi Gong et al.: Boolean Operations on Conic Polygons

realization of regularized Boolean operations on conic polygons[14] . This work was a part of ECG. The above literature focused mainly on the arrangements of algebraic curves[17] , and the Boolean operations on conic polygons were mentioned but few details had been discussed. Because the algorithms they proposed extended the Bentley-Ottmann algorithm from line segments to curve segments, curve segments were broken into several x-monotone ones to keep consistent with the preliminaries of the Bentley-Ottmann algorithm. Degenerations were dealt with to ensure its robustness. However, if two general x-monotone algebraic curve segments intersect at the endpoints without any other endpoints between X1 and X2 as shown in Fig.1(a), it is unable to determine algorithmically which curve is above the other one between X1 and X2 . A temporary vertical line X 0 must be inserted between X1 and X2 to consistent with preliminaries of the Bentley-Ottmann algorithm (Fig.1(b)).

569

by (1) ay 2 + bxy + cx2 + dy + ex + f = 0.

(1)

Four types of non-degenerate conic curves can be defined according to the sign of ∆ where ∆ = b2 − 4ac (Table 1). Table 1. Relationships Between ∆ and the Curve Type ∆ 0

Circle Ellipse Parabola Hyperbola

A line is a degeneration of conic with a, b and c being 0. Therefore we take a line as a special case of conics. We divided a hyperbola into two curves for the convenience of computation.

Fig.1. Bentley-Ottmann algorithm extended to algebraic curve segments.

In this paper, we propose an algorithm for Boolean operations on conic polygons using topological relationships between two conic polygons without self intersection. Topological relationships between boundaries of conic polygons are calculated and resulting conic polygons are constructed by tracking path and selecting uncrossed boundaries following rule tables. Three Boolean operations, including intersection, union, and subtraction, are implemented with different rules. The proposed algorithm can deal with degenerations such as uncrossed boundaries. These cases were not considered previously. The algorithm, additionally, does not require x-monotone conic segments. The rest of this paper is organized as follows. In the following section, several concepts of conics and conic polygons are introduced and the preliminaries of Boolean operations for general polygons are presented. The algorithm to clip conic polygons is proposed step by step in Section 3. Evaluation and experiment are given in Section 4, and Section 5 concludes the paper. 2

Concepts and Preliminaries

2.1

Conics and Conic Polygons

Conics are second degree curves in the plane defined

Fig.2. Directions of conic segments. (a) Direction of a line segment. (b) Direction of a circle segment. (c) Direction of an ellipse. (d) Direction of a parabola segment. (e) Direction of a hyperbola segment.

A conic segment is a part of a conic with a start point and an end point. For a conic segment S and the conic curve C containing S, C is the underlying conic of S. We define the direction of the line segment being positive in this paper (Fig.2(a)). In order to determine the direction of a conic segment, we define a mark point of the non-degenerated conic as follows: the mark point of a circle segment is its center point (Fig.2(b)); the mark point of an ellipse is one of its focus (Fig.2(c)); that of a parabola is its focuses (Fig.2(d)); the mark point of a

570

hyperbola is the focus on the same side of the directrix with the segment (Fig.2(e)). The direction of a conic segment is positive if the segment is counterclockwise around the mark point, otherwise it is negative (Fig.2). Berberich et al. stated a conic polygon as anything that can be obtained from linear or conic halfspaces by regularized Boolean operations from the Boolean operations point of view[14] . We define conic polygon from the general polygon point of view. General polygon is any regions enclosed by boundaries with directions and the regions on the left hand of boundaries are the interior of the general polygon and that on the right hand of boundaries are the exterior of the general polygon. A conic polygon is a special case of general polygon with close paths consisting of conic segments (Fig.3(a)), or bounded conics (Fig.3(b)), as boundaries. Bounded conics, including circle and ellipse, are conics that have a finite domain on the plane. Paths or bounded conics in the counterclockwise direction are positive and those in the clockwise direction are negative. A conic polygon with holes can be represented as shown in Fig.3(c). Our definition of conic polygons is consistent with that of Berberich et al.[14]

Fig.3. Conic polygons enclosed by boundaries with direction. (a) Conic polygon with a path in the positive direction as boundary. (b) Conic polygon with a circle in the positive direction as boundary. (c) Conic polygon with a path in the positive direction as outer boundary and a path in the negative direction as hole.

A polygon consisting of line segments is a degeneration of a conic polygon and is called a traditional polygon. Non-degenerated conic polygons are different from traditional polygons as follows. 1) A boundary of a traditional polygon consists of at least three line segments (Fig.4(a)), while a boundary of a conic polygon may be a bounded conic (Fig.4(b)), two (Fig.4(c)), or more (Fig.4(d)) segments.

Fig.4. Boundary of traditional polygon consists of at least three line segments, while that of conic polygon may be a bounded conic, or consist of two or more conic segments.

J. Comput. Sci. & Technol., May 2009, Vol.24, No.3

2) Two line segments of traditional polygons have one intersection point at most if the two line segments do not overlap (Fig.5(a)), but there are up to four intersection points between conic segments of conic polygons (Fig.5(b)).

Fig.5. Intersection points of traditional polygons and conic polygons.

For a conic segment S and its underlying conic C, we define the direction of C as that of S in Boolean operations, and two preliminaries are required. 1) LeftOrRight Test of Mutual Position of a Point p (not lying on C) and a Conic C For a line C with direction, the LeftOrRight test returns left if p is on the left side of C. When C is a non-degenerate conic, the LeftOrRight test return left, if: a) C is in the positive direction, and the line segment between the mark point of C and p does not intersect with C, or b) C is in the negative direction and the line segment between the mark point of C and p intersect with C. Otherwise the LeftOrRight test returns right. LeftOrRight test can determine whether the point is on the left side or right side of a conic. 2) Direction Test of a Boundary The points with maximum y value of all segments on the boundary are computed and compared to get the point p at (x, y) with maximum y value of the boundary firstly. If there are several points with maximum y value, only one is taken (Fig.6(a)).

Fig.6. Directions of boundaries.

If p is a vertex of two segments, take the one moving towards p as IC , take the segment pp 0 as OC , and take the segment moving away from p as a test curve TC , where p0 is a point with coordinate (x, y + ) and y + means an arbitrary number greater than y. If TC is on the left side of IC and OC , the path is in the counterclockwise direction (Fig.6(b)); otherwise the path is in the clockwise direction (Fig.6(a)). How to determine whether a test curve TC is on the left side of IC and

Yong-Xi Gong et al.: Boolean Operations on Conic Polygons

OC is presented in Subsection 3.2. If p is on a conic segment other than endpoints or p is on a bounded conic, the boundary is counterclockwise with the conic segment or conic in a positive direction (Fig.6(c)), or clockwise with the conic segment or conic in a negative direction (Fig.6(d)). The interior and the exterior of a conic polygon can be determined according to the direction of a boundary. 2.2

Preliminaries

A number of preliminaries can be concluded for Boolean operations on general polygons and they can be applied to conic polygons with concrete implementations of topological relationships computation. Topological relationships between two general polygons are the invariable properties under continuous deformations. In the Boolean operations on general polygons, the relative direction between two polygons, including local topological relationship and the global topological relationship, is used. The local topological relationship is the relationship near the intersection point between two polygons. The global topological relationship is the relationship of an uncrossed boundary to a polygon. Let M be a boundary and p be a point on M . Let S be a curve segment with p as an endpoint. We denote the curve segment moving towards p as IM and the curve segment moving away from p as OM . If S and OM overlap each other near the point p, S is in front of M near p (Fig.7(b)). If S and IM overlap each other near the point p, S is back of M near p (Fig.7(d)). When S overlaps neither IM nor OM , we take a circle with p as center to judge whether S is on the left side or right side of M , and two properties should be satisfied: 1) the circle has only one intersection point with each of OM , S and IM , denoting as q1 , q2 and q3 ; 2) OM , S and IM do not intersect with each other inside or on the circle.

Fig.7. Local topological relationships of a curve segment S to a boundary M when one endpoint of S is on M . (a) S is L (left) to M . (b) S is F (front) to M . (c) S is R (right) to M . (d) S is B (back) to M .

Now walk along the circle from q1 in the

571

counterclockwise direction and get the order of q1 , q2 and q3 : if q2 is between q1 and q3 , S is on the left side of M near p (Fig.7(a)); if q2 is not between q1 and q3 , S is on the right side of M near p (Fig.7(c)). Thus, there are four topological relationships of a curve segment to a boundary near an intersection point: L (left), F (front), R (right), and B (back). Supposing that boundaries M and N intersect at a point p, and IN and ON are segments moving towards and moving away from p on N , respectively. We can deduce 16 local topological relationships between N and M at p: LL, LF, LR, LB, FL, FF, FR, FB, RL, RF, RR, RB, BL, BF, BR, BB, where the first letter denotes the topological relationship of IN to M and the second one is that of ON to M . In the 16 local topological relationships, BB and FF are invalid for a general polygon, and thus only 14 local topological relationships remain. Local topological relationships of M to N can be calculated in the same way. Among the 14 local topological relationships, LL, RR, FB and BF do not change the left/right relationship between M and N at the intersection point. Global topological relationships would be one of the followings. Homology : if two boundaries overlap each other and have same directions, they are homologies of each other. Complement : if two boundaries overlap each other and their directions are reverse, they are complements of each other. Interior : a boundary M is interior to a general polygon P when M lies entirely in the interior region of P , or M have only LL local topological relationship to boundaries of P . Exterior : a boundary M is exterior to a general polygon P when M lies entirely in the exterior region of P , or M have only RR local topological relationship to boundaries of P . Based on the topological relationships, we can introduce preliminaries of three Boolean operations on general polygons: intersection, union, and subtraction. The resulting polygons of intersection operation on polygons P and Q cover the interior region of both P and Q; the resulting polygons of union operation on P and Q cover the interior region of either P or Q; the resulting polygon of subtraction operation on P to Q cover interior region of P but exterior region of Q. In the workflow of Boolean operations on general polygons shown in Fig.8, the Boolean operations on conic polygons can be implemented with steps in dash line box, and the steps in solid line boxes can be applied in Boolean operations on general polygons without any modification.

572

J. Comput. Sci. & Technol., May 2009, Vol.24, No.3

Fig.8. Workflow of Boolean operations on general polygons.

3

Algorithms

3.1



Intersection Point Between Conic Polygons

0 0

   1    0   0  0    1   0

The intersection points between conics are roots of the quadratic equation system (2): (

a1 y 2 + b1 xy + c1 x2 + d1 y + e1 x + f1 = 0, 2

2

a2 y + b2 xy + c2 x + d2 y + e2 x + f2 = 0.

(2)

A quadratic equation system can be converted into quartics or cubics of y [18] as (3): 4

3

2

Ay + By + Cy + Dy + E = 0

(3)

where A = (c1 a2 )2 + (c1 b2 )(a1 b2 ), B = 2(c1 d2 )(c1 a2 ) − (c1 b2 )(b1 d2 ) + (c1 b2 )(a1 e2 ) + (c1 e2 )(a1 b2 ), C = (c1 d2 )2 + 2(c1 a2 )(c1 f2 ) − (c1 b2 )(b1 f2 ) − (c1 b2 )(e1 d2 ) − (c1 e2 )(b1 d2 )

0 1 0 0 0 1

F  A  E 0 −  A , C 0 −  A  B 1 − A F  − B  E − . B  C − B 0



(4)

(5)

Roots of (3) are substituted into equation system (2) to obtain intersection points between two conics. The intersection points between two conic segments are not all of the intersection points between their underlying conics, and those intersection points not on conic segments must be filtered. Let S be a conic segment with start point s and end point e. To avoid computing the intersection points at the endpoints multiple times, an interval [s, e) is defined as the domain of a conic segment. Only those intersection points p ∈ [s, e)

+ (c1 e2 )(a1 e2 ), D = 2(c1 d2 )(c1 f2 ) − (c1 b2 )(e1 f2 ) − (c1 e2 )(b1 f2 ) − (c1 e2 )(e1 d2 ), E = (c1 f2 )2 − (c1 e2 )(e1 f2 ).

Fig.9. Intersection points of two conic segments S and S 0 . (a) p is an intersection point between S and S 0 . (b) p is not an intersec-

Since the roots of a polynomial coincide with the eigenvalues of its companion matrix[19] , we can find the root of (3) using any eigenvalue algorithm.

tion point between S and S 0 , but an intersection point between

The companion matrix of (3) is (4) when A 6= 0, or (5) when A = 0 and B 6= 0. If A = B = 0, (3) can be solved easily.

ment next to S. (d) p is not an intersection point between S and

S 0 and the segment next to S. (c) p is not an intersection point between S and S 0 , but an intersection point of S 0 and the segS 0 , but an intersection point between segments next to S and S 0 respectively.

Yong-Xi Gong et al.: Boolean Operations on Conic Polygons

are the valid intersection points between two conic segments. Some examples are shown in Fig.9. 3.2

Local Topological Relationships

Let TC , IC and OC be conic segments with the same endpoint p, where IC moves towards p and OC moves away from p (Fig.10(a)). Underlying conics of IC and OC may be different ones or the same. The local topological relationship of TC to IC and OC can be obtained in the following way (assuming that TC overlaps with neither IC nor OC ). 1) Supposing that the unit tangent vectors of IC , OC and TC at p are I 0C , O 0C and T 0C , respectively. The direction of I 0C is changed to its reverse direction, as well as the direction of T 0C when it moves towards p. If angle of T 0C is in the open interval from angle of O 0C to that of I 0C in the counterclockwise direction, as the shaded region shown in Fig.10(a), TC is on the left side of IC and OC ; otherwise, TC is on the right hand of IC and OC with T 0C equaling neither I 0C nor O 0C (Fig.10(a)). 2) If the unit vector T 0C equals I 0C or O 0C , it is complex to determine the local topological relationships of TC to IC and OC . Supposing that T 0C equals I 0C , TC and IC are on the same side of the normal of TC at point p. A test point q on TC is taken in the following way: any point other than p is taken as q while there is only one intersection point p between TC and the underlying conic of IC (Fig.11(a)), otherwise any point between p0

Fig.10. Local topological relationships of TC to IC and OC near point p.

573

and p is selected as q where p0 is the intersection point nearest to p (Fig.11(b)). If q is left of IC , TC is on the left side of IC ; if q is right of IC , TC is on the right side of IC . The case that T 0C equals O 0C can be dealt with in the same way. Now we can determine the local topological relationship of TC to IC and OC : a) if T 0C equals only one of I 0C or O 0C , say I 0C , and TC is on the left side of IC , then TC is on the left side of IC and OC (Fig.10(b)); otherwise TC is on the right side of IC and OC . b) I 0C = O 0C = T 0C , and TC is on the right side of either IC or OC , then TC is on the right side of IC and OC (Fig.10(c)); otherwise, TC is on the left side of IC and OC . Finally, when TC overlaps with IC or OC , the relationship of TC to IC and OC is B or F . 3.3

Tracking Path

For an intersection point between two conic polygons P and Q, let IP and OP be conic segments of P moving towards and moving away from p respectively, IQ and OQ be conic segments of Q moving towards and moving away from p. Strategies for selecting a conic segment to track along at an intersection point for different Boolean operations are different. Intersection of P and Q (P ∩ Q): if OP is on the left side of IQ and OQ , OP is tracked along (Fig.12(a)), or if OQ is on the left side of IP and OP , OQ is tracked along (Fig.12(b)); if the local topological relationship of OQ to IP and OP is F , either OP or OQ is tracked along for they are the same conic segment near point p (Fig.12(c)). If at any intersection point OQ is right to but IQ is not left to IP and OP , the point is filtered before tracking path for intersection operation because there has no region interior to both P and Q (Fig.12(d)). Union of P and Q(P ∪ Q): if OP is right to IQ and OQ , OP is tracked along (Fig.12(b)); otherwise OQ is tracked along (Figs. 12(a), 12(c), and 12(d)).

Fig.12. Tracking path.

Fig.11. Point q on TC is taken to determine the local topological relationship of TC to IC when they are tangent at point p.

Subtraction of Q from P (P − Q): if OP is left to IQ and OQ , IQ is tracked along (Fig.12(a)); otherwise we track along OP (Figs. 12(b) and 12(d)). If at any

574

J. Comput. Sci. & Technol., May 2009, Vol.24, No.3

intersection point the local topological relationship of Q to P is BF, RF or BR, the point must be filtered before tracking path because there has no region interior to P but exterior to Q (Fig.12(c)). Rules to track path for intersection, union and subtraction are summarized in Table 2. Table 2. Rules for Tracking Paths Operations

Local Topological Relationship

Intersection (P ∩ Q)

OQ is L to IP and OP OP is L to IQ and OQ OQ is F to IP and OP

Union (P ∪ Q)

OQ is R to IP and OP OQ is not R to IP and OP

OQ OP

Subtraction (P − Q)

OP is L to IQ and OQ OP is not L to IQ and OQ

IQ OP

The procedure of tracking path of intersection operation, union operation, and subtraction operation are as follows. Table 3. Information of Tracking Path Between P and Q

Intersection Points

Local Topological Relationship (P to Q/Q to P )

P ∩Q

P ∪Q

P −Q

p1 p2 p3 p4

RL/LR LR/RL RL/LR LR/RL

P+ Q+ P+ Q+

Q+ P+ Q+ P+

Q− P+ Q− P+

Track Along OQ OP OP or OQ

Let CP be a collection of intersection points between polygons P and Q. Let Cˇ be a collection of boundaries. Each boundary maintains a list of its intersection points which are sorted according to its direction. Now we can track path to build boundaries of resulting polygons following Algorithm 1. Algorithm 1. Tracking Path Input: conic polygons P and Q, a collection CP containing intersection points between P and Q with local topological relationships. ˇ containing the resulting boundaries Output: a collection C of Boolean operations. ˇ be an empty collection 1) let C 2) repeat until CP is empty 2.1) select any point p in CP 2.2) p0 ← p ˇ be an empty path 2.3) let A 2.4) repeat 2.4.1) track along the path from point p0 following Table 2, and arrive at the next intersection point p00 ∈ CP ˇ 2.4.2) add the path from p0 to p00 to A 2.4.3) remove p0 from CP ˇ into C ˇ and exit the loop 2.4.4) if p00 equals p, add A 0 00 2.4.5) p ← p ˇ 3) return C

1) Intersection Operation (P ∩ Q) We take p1 as a start point and the procedure is P+

Q+

Q+

P+

Q+

P+

Q−

P+

P+

Q+

p1 − → p2 − → p3 − → p4 − → p1 . Now the path is closed to construct a boundary, and CP is empty to end the procedure (Fig.13(b)). 2) Union Operation (P ∪ Q) We take p1 as a start and the procedure is p1 − → p2 − → p1 , and a boundary is constructed. For CP has intersection points p3 and p4 , we take p3 as a start: p3 − → p4 − → p3 , and the second boundary is constructed. Then we get two boundaries of the union operation (Fig.13(c)). 3) Subtraction Operation (P − Q) We take p1 as a start and the procedure is Q−

P+

p1 − → p4 − → p3 − → p2 − → p1 . Now the path is closed to construct a boundary, and CP is empty to end the procedure (Fig.13(d)).

Fig.13. Examples of tracking path for intersection, union and subtraction operations, and the space with diagonal cross line in (b), (c) and (d) are results. (a) Polygons P and Q. (b) P ∩ Q. (c) P ∪ Q. (d) P − Q.

When CP is empty, boundaries in Cˇ can be used to build resulting conic polygons. As shown in Fig.13(a), polygons P and Q have 4 intersection points, and the local topological relationships near the points are listed in Table 3. We use P + /Q+ to denote tracking along P/Q in the direction of P/Q near the intersection points, and P − /Q− to denote tracking along P/Q in the reversed direction of P/Q near the intersection points.

3.4

Global Topological Relationships

Two boundaries consisting of conic segments with only BFs/FBs local topological relationships are homology/complement. If a boundary N does not intersect with another conic polygon P and any point on N is in the interior/exterior of P , or N has only LLs/RRs local

Yong-Xi Gong et al.: Boolean Operations on Conic Polygons

575 Table 4. Rules for Selecting Uncrossed Boundaries

topological relationships to boundaries of P , the boundary N is interior/exterior to P .

Operation

Global Topological Relationships

Boundary Selected

M and N are homology

Either M or N is selected Intersection M and N are complement Neither M nor N is (P ∩ Q) selected M/N is interior to Q/P M/N is selected M and N are homology Union (P ∪ Q)

Either M or N is selected M and N are complement Neither M nor N is selected M/N is interior to Q/P M/N is discarded M/N is exterior to Q/P M/N is selected

M and N are homology

Neither M nor N is selected M and N are complement M is selected Subtraction M is interior to Q M is discarded (P − Q) M is exterior to Q M is selected N is interior to P N with reversed direction is selected N is exterior to P N is discarded

Fig.14. Global topological relationship of a boundary to a conic polygon.

In Fig.14, a conic polygon P consists of boundaries P1 , P2 , and P3 , and a conic polygon Q consists of boundaries Q1 , and Q2 . Q1 is interior to P , and P2 is exterior to Q. Although there are 4 intersection points between P and Q, P3 is interior to Q because the local topological relationships of P3 to Q are LLs at all intersection points between P3 and Q. Q2 is exterior to P because the local topological relationships of Q2 to P are RRs at all intersection points between Q2 and P . For a boundary N without any intersection points with a conic polygon P , any point p on N is taken to count the winding number of p to P , and in this way we can determine whether N is interior or exterior to P [10] . 3.5

Selecting Uncrossed Boundaries

Let P and Q be two conic polygons, and M be a boundary of P . When M is homology or complement to a boundary of Q, or M is entirely in the interior or exterior of Q, M is an uncrossed boundary. Path tracking does not deal with uncrossed boundaries. Supposing M and N from conic polygons P and Q respectively are uncrossed boundaries, rules to determine which uncrossed boundaries remain as parts of resulting polygons are listed in Table 4. For example, in Fig.14, Q1 and P3 are selected into resulting conic polygons in intersection operation on Q and P (Fig.15(a)); P1 , P2 , and Q2 are selected in union operation on Q and P (Fig.15(b)); Q1 with reversed direction, P1 , and P2 are selected in subtraction of P to Q (Fig.15(c)). 3.6

Combining Boundaries

Resulting conic polygons can be built by combining

Fig.15. Examples of selecting uncrossed boundaries. (a) P ∩ Q. (b) P ∪ Q. (c) P − Q.

boundaries from tracking path and selecting uncrossed boundaries. The boundaries not being surrounded by other boundaries are selected and other boundaries are allocated to these boundaries to construct resulting conic polygons. 4 4.1

Evaluation, Implementation, and Experiment Time Complexity Analysis

There is no way to avoid computing the intersection points between two conic polygons. In any clipping algorithm supporting arbitrary polygons, the time consumed depends on the number of intersection points between two polygons, and the time complexity is O(n × m), with n and m being the edge numbers of the polygons[10] . The calculation of intersection points between two conic polygons would consume much more time than that of traditional polygons. What is more, computation of local topological

576

J. Comput. Sci. & Technol., May 2009, Vol.24, No.3

relationships and tracking path depend on the number of intersection points. Hence, the time complexity of Boolean operations mainly depends on the number of the intersection points between conic polygons. In the worst case, two conic segments have 4 intersection points. Therefore the number of intersection points between two conics with m and n conic segments is 4×m×n. Thus, the complexity of Boolean operations on conic polygons is O(m × n). 4.2

Implementation and Experiment

We implement the algorithm in C# dealing with intersection, union, and subtraction operations on conic polygons, and test it on thousands of conic polygons with correct results. Matrix-based method[19] is adopted to compute roots of quadric. The hardware adopted in our experiments is an AMD Athlon XP 2200 with 512MB memory, running on Windows 2003 with .Net framework 2.0. In our experiments, 5357 Boolean operations are performed in about 4117ms with about 0.77ms per conic Boolean operations on average. Among those Boolean operations, 3752 are intersection operations, 825 are union operations and 780 are subtraction operations. In the Boolean operations, 25 739 equation systems are solved, taking 1445ms in total. The time to compute intersection points between conic polygons occupy about 35% of the running time (Fig.16). To compute local topological relationship and to track path take about 21% and 28% of the running time respectively. It takes about 132ms to determine 5030 global topological relationships, with about 0.026ms per global topological relationship.

Fig.16. Percentages of the time cost in each step.

From the experiment, we can see that the amount of global topological relationships is much fewer than that of local topological relationships in general cases. The

time to solve conic equation systems, to compute the local topological relationship, and to track path take most of the running time. 5

Conclusions and Future Work

An algorithm for Boolean operations on conic polygons is proposed. Conic polygons consisting of conic segments or bounded conics with direction are introduced. In our algorithm, three Boolean operations are presented: intersection, union and subtraction. The algorithm is based on topological relationships between two conic polygons and it works in six steps: 1) solve conic equation systems to get the intersection points between conic polygons; 2) obtain the local topological relationships between two conic polygons at the intersection points; 3) track path for those boundaries with the intersection points following rule table to build boundaries; 4) calculate the global topological relationships of uncrossed boundaries to a conic polygon; 5) determine which uncrossed boundaries are selected as parts of the resulting conic polygons by rule table; 6) combine boundaries from tracking path and selecting uncrossed boundaries to construct resulting polygons. Degenerations in Boolean operations are also considered in our algorithm. The time complexity of the algorithm is O(m × n) between two conic polygons with m and n conic segments respectively. We implement the algorithm with C#. The proposed algorithm can be applied in Boolean operations on general polygons if the following properties are maintained: 1) intersection points between two general polygons can be obtained algorithmically; 2) local topological relationships at the intersection points and global topological relationship can be calculated algorithmically. The algorithm is not fast enough for heavycomputation applications such as multiplicative weighted Voronoi diagram for points, polylines, and polygons. As the computation of intersections is the most time-consuming operation, one of the future work is to find out a more efficient method to calculate the intersection points of conic curves. Additionally, as many commodity PCs have been equipped by multicore CPU, another improvement is to divide a Boolean operation on conic polygons into several independent tasks in order to develop parallel algorithm of Boolean operations on conic polygons.

Yong-Xi Gong et al.: Boolean Operations on Conic Polygons

Acknowledgement We thank the anonymous referees for their valuable comments that have helped to improve the manuscript. References [1] O’Rourke J. Computational Geometry in C. 2nd Edition, New York: Cambridge University Press, 1998, pp.252–268. [2] Peng Y, Yong J H, Dong W M, Zhang H, Sun J G. A new algorithm for Boolean operations on general polygons. Computers & Graphics, 2005, 29(1): 57–70. [3] Sutherland I E, Hodgman G W. Reentrant polygon clipping. Communications of the ACM, 1974, 17(1): 32–42. [4] Weiler K, Atherton P. Hidden surface removal using polygon area sorting. ACM SIGGRAPH Computer Graphics, 1977, 11(2): 214–222. [5] Bentley J L, Ottmann T A. Algorithms for reporting and counting geometric intersections. IEEE Transactions on Computers, 1979, C-28(9): 643–647. [6] Liang Y D, Barsky B A. An analysis and algorithm for polygon clipping. Communications of the ACM, 1983, 26(11): 868–877. [7] Maillot P G. A new, fast method for 2D polygon clipping: Analysis and software implementation. ACM Transactions on Graphics, 1992, 11(3): 276–290. [8] Vatti B R. A generic solution to polygon clipping. Communications of the ACM, 1992, 35(7): 56–63. [9] Murta A. GPC: General polygon clipper library. December 20, 2007, http://www.cs.man.ac.uk/∼toby/alan/software/. [10] Greiner G, Hormann K. Efficient clipping of arbitrary polygons. ACM Transactions on Graphics, 1998, 17(2): 71–83. [11] Rivero M, Feito F R. Boolean operations on general planar polygons. Computers & Graphics, 2000, 24(6): 881–896. [12] Cai S J, Zhang F Y. A fast algorithm for polygon operations. Journal of Computer Science and Technology, 1991, 6(1): 91– 96. [13] Liu Y K, Wang X Q, Bao S Z, Matej G, Borut Z. An algorithm for polygon clipping, and for determining polygon intersections and unions. Computers & Geosciences, 2007, 33(5): 589–598. [14] Berberich E, Eigenwillig A, Hemmer M, Hert Susan, Mehlhorn K, Sch¨ omer E. A computational basis for conic arcs and Boolean operations on conic polygons. In Proc. the 10th European Symposium on Algorithms, Rome, Italy, Sept. 17– 21, 2002, pp.321–327. [15] Liu Y, Chen F L. Algebraic conditions for classifying the positional relationships between two conics and their applications. Journal of Computer Science and Technology, 2004, 19(5): 665–673. [16] Emiris I Z, Kakargias A, Pion S M. Teillaud M, Tsigaridas E P. Towards an open curved kernel. In Proc. the 20th Annual Symposium on Computational Geometry, Brooklyn, New York, USA, June 5–7, 2004, pp.438–446. [17] Wein R. High-level filtering for arrangements of conic arcs. In Proc. the 10th European Symposium on Algorithms, Rome, Italy, Sept. 17–21, 2002, pp.884–896. [18] Denis A. A discussion of the cases when two quadratic equations involving two variables can be solved by the method of quadratics. The American Mathematical Monthly, 1903, 10(8/9): 192–199.

577 [19] Edelman A, Murakami H. Polynomial roots from companion matrix eigenvalues. Mathematics of Computation, 1995, 64(210): 763–776.

Yong-Xi Gong received the B.Sc. degree in geography from Hubei University in 1997, and the M.Sc. degree in cartography and geographic information systems from Wuhan University in 2003. Currently, he is a Ph.D. candidate majored in geographic information systems at the Institute of Remote Sensing and Geographic Information Systems, Peking University. His research interests include qualitative spatial reasoning, computer graphics and image processing. Yu Liu received the B.Sc., M.Sc., and Ph.D. degrees in human geography, geographic information systems, and software engineering from Peking University in 1994, 1997, and 2003, respectively. He is an associate professor of Peking University. His research includes GI-sciences and GIsoftware. Lun Wu is a professor of the Institute of Remote Sensing and Geographic Information Systems, Peking University. His research interests include geographic information systems and remote sensing. He has authored more than 100 refereed research articles.

Yu-Bo Xie received the M.Sc. degree in cartography and geographic information systems from Wuhan University in 2003. Currently, he is a Ph.D. candidate majored in photogrammetry and remote sensing at the State Key Laboratory of Information Engineer in Surveying, Mapping and Remote Sensing, Wuhan University. From July 2003, he is an engineer in image processing and geographic information systems at the North China Institute of Computing Technology. His research interests are geographic information systems and intelligent image processing.