Arrangement-Traits Classes
5.4 Traits Classes for Algebraic Curves
5.4.2 A Traits Class for Conic Arcs
It is also possible to constructx-monotone curves, which represent x-monotone circular arcs or line segments, using similar constructors (full circles are notx-monotone).
5.4.2 A Traits Class for Conic Arcs
A conic curve is an algebraic curve of degree2. Namely, it is the locus of all points (x, y) satisfying the equation κ : rx2+ sy2+ txy + ux + vy + w = 0, where the six coefficients r, s, t, u, v, w
completely characterize the curve. The sign of the expressionΔκ= 4rs − t2 determines the type of the curve.
• If Δκ > 0, the curve is an ellipse. A circle is a special case of an ellipse where r = s and t = 0.
• If Δκ= 0, the curve is a parabola—an unbounded conic curve with a single connected branch.
Whenr = s = t = 0 we have a line, which can be considered as a degenerate parabola.
• If Δκ < 0, the curve is a hyperbola. That is, it comprises two disconnected unbounded branches.
The Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits> class template is capable of handling only bounded arcs of conic curves, referred to as conic arcs. A conic arca may be either (i) a full ellipse, or (ii) defined by the tuple κ, ps, pt, o, where κ is a conic curve and psand pt are two points on κ (namely, κ(ps) = κ(pt) = 0) that define the source and target of the arc, respectively. The arc is formed by traversing κ from the source to the target in the orientation specified by o, which is typically CGAL::CLOCKWISE or CGAL::COUNTERCLOCKWISE, but may also be CGAL::COLLINEAR in the case of degenerate conic-curves, namely, lines or pairs of lines.
We always assume that the conic coefficientsr, s, t, u, v, w are rational. The coordinates of points of intersection between two conic curves with rational coefficients are in general algebraic numbers of degree 4. Namely, they are roots of algebraic polynomials of degree 4. In addition, conic arcs may not necessarily bex-monotone, and must be split at points where the tangent to the arc is vertical. In the general case such points typically have coordinates that are algebraic numbers of degree2. Note that as arrangement vertices induced by intersection points and points with vertical tangents are likely to have algebraic coordinates, we also allow the original endpoints of the input arcsps andptto have algebraic coordinates.
The Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits> class template is designed for efficient handling of arrangements of bounded conic arcs. The template has three parameters, defined as follows:
• The RatKernel template parameter must be substituted with a geometric kernel whose field type is an exact rational type. It is used to define basic geometric entities (e.g., a line segment or a circle) with rational coefficients. Typically, we use one of the standard Cgal kernels instantiated with the number type NtTraits::Rational (see below).
• The AlgKernel template parameter must be substituted with a geometric kernel whose field type represents an exact algebraic number. It is used to define points with algebraic coordinates. Typically, we use one of the standard Cgal kernels instantiated with the number type NtTraits::Algebraic (see below).
• The NtTraits template parameter must be substituted with a type that encapsulates all the numerical operations needed for performing the geometric computation carried out by the geometric traits-class. It defines the Integer, Rational, and Algebraic number types, and supports several operations on these types, such as conversion between number types, solving quadratic equations, and extraction of real roots of polynomials with integral coeffi-cients. The use of the CORE_algebraic_number_traits class, which is included in the 2D Arrangements package, is highly recommended. The traits class-template relies on the multi-precision number types implemented in the Core library and performs exact computations on the number types it defines.
The instantiation of the conic traits class-template is slightly more complicated than the instan-tiation of the traits classes you have encountered so far. This instaninstan-tiation is exemplified in the header file arr_conics.h. Note how we first define the rational and algebraic kernels using the number types given by the Core number type traits-class, then use them to define the conic traits class-template. Also note the types defined by the rational kernels, which we need for conveniently constructing conic arcs.
#include <CGAL/ Cartesian . h>
#include <CGAL/CORE_algebraic_number_traits . h>
#include <CGAL/Arr_conic_traits_2 . h>
#include <CGAL/Arrangement_2 . h>
typedef CGAL: : CORE_algebraic_number_traits Nt_traits ;
typedef Nt_traits : : Rational Rational ;
typedef CGAL: : Cartesian<Rational> Rat_kernel ;
typedef Rat_kernel : : Point_2 Rat_point ;
typedef Rat_kernel : : Segment_2 Rat_segment ;
typedef Rat_kernel : : Circle_2 Rat_circle ;
typedef Nt_traits : : Algebraic Algebraic ;
typedef CGAL: : Cartesian<Algebraic> Alg_kernel ; typedef CGAL: : Arr_conic_traits_2<Rat_kernel , Alg_kernel , Nt_traits>
Tr a its ;
typedef Tr a its : : Point_2 Point ;
typedef Tr a its : : Curve_2 Conic_arc ;
typedef Tr a its : : X_monotone_curve_2 X_monotone_conic_arc;
typedef CGAL: : Arrangement_2<Traits> Arrangement ;
The Arr_conic_traits_2 models theArrangementTraits_2 and ArrangementLandmarkTraits_
2 concepts.16 Its Point_2 type is derived from AlgKernel::Point_2, while the Curve_2 type is used to represent a bounded, not necessarily x-monotone, conic arc. The X_monotone_curve_2 type is derived from Curve_2, but its constructors are used only by the traits class. Users should therefore construct only Curve_2 objects and insert them into the arrangement using the insert() function.
16It also models the refined concept ArrangementDirectionalXMonotoneTraits_ 2 defined in Chapter 8.
Conic arcs are constructible from full ellipses or by specifying a supporting curve, two end-points, and an orientation. However, several constructors of Curve_2 are available to allow for some special cases, such as line segments or circular arcs. The Curve_2 and the derived X_
monotone_curve_2 classes also support basic access functions such as source(), target(), and orientation().
C1
C2
C4
C5
C6
C7
C3
Example: The example below demonstrates the usage of the various constructors for conic arcs. The resulting arrangement is depicted in the figure to the right. Especially noteworthy are the constructor of a circular arc that accepts three points, the constructor of a conic arc that accepts five points, and the con-structor that allows specifying approximate endpoints, where the exact endpoints are given explicitly as intersections of the supporting conic with two other conic curves. The approxi-mate endpoints are used to select the specific exact endpoints out of all intersection points of the pair of curves (the support-ing conic curve and the auxiliary conic curve). Also note that as the preconditions required by some of these constructors are rather complicated (see the Reference Manual for the details), a
precondition violation does not cause the program to terminate—instead, an invalid arc is created.
We can verify the validity of an arc a by using the a.is_valid() method. Naturally, inserting invalid arcs into an arrangement is not allowed, so the validity of an arc should be checked once it is constructed.
// F i l e : ex_conic_arcs . cpp
#include " arr_conics . h"
#include " arr_print . h"
int main ( ) {
Arrangement a r r ;
// I n s e r t a h y p e r b o l i c arc (C1) , supported by the hyperbola y = 1/x // ( or : xy − 1 = 0) with the endpoints (1/4, 4) and (2 , 1/2).
// The arc i s cou nterclockwise oriented .
i n s e r t ( arr , Conic_arc ( 0 , 0 , 1 , 0 , 0 , −1, CGAL: :COUNTERCLOCKWISE,
Point ( Rational ( 1 , 4 ) , 4 ) , Point ( 2 , Rational ( 1 , 2 ) ) ) ) ; // I n s e r t a f u l l e l l i p s e (C2) , which i s ( x/4)^2 + ( y/2)^2 = 0 r o t a t e d by // phi = 36.87 degrees ( such t h a t sin ( phi ) = 0 . 6 , cos ( phi ) = 0 . 8 ) , // y i e l d i n g : 58x^2 + 72y^2 − 48xy − 360 = 0.
i n s e r t ( arr , Conic_arc (5 8 , 72 , −48, 0 , 0 , −360));
// I n s e r t the segment (C3) (1 , 1) −− (0 , −3).
i n s e r t ( arr , Conic_arc (Rat_segment( Rat_point ( 1 , 1 ) , Rat_point ( 0 , −3))));
// I n s e r t a c i r c u l a r arc (C4) supported by the c i r c l e x^2 + y^2 = 5^2, // with (−3, 4) and (4 , 3) as i t s endpoints . We want the arc to be // clockwise−oriented , so i t passes through (0 , 5) as well .
Conic_arc c4 ( Rat_point(−3, 4) , Rat_point(0 , 5) , Rat_point(4 , 3));
CGAL_assertion( c4 . is_va lid ( ) ) ; i n s e r t ( arr , c4 ) ;
// I n s e r t a f u l l u n it c i r c l e (C5) t h a t i s centered at (0 , 4 ) .
i n s e r t ( arr , Conic_arc ( Rat_circle ( Rat_point ( 0 , 4 ) , 1 ) ) ) ;
// I n s e r t a p a r a b o l i c arc (C6) supported by the parabola y =−x^2
// with endpoints (−sqrt (3),−3) (~(−1.73,−3)) and ( sqrt (2),−2) (~(1.41,−2)).
// Since the x−coordinates of the endpoints cannot be acccurately represented , // we s p e c i f y them as the i n t e r s e c t i o n s o f the parabola with the l i n e s // y =−3 and y = −2, respectively . The arc is clockwise−oriented . Conic_arc c6 =
Conic_arc ( 1 , 0 , 0 , 0 , 1 , 0 , // The parabola . CGAL: :CLOCKWISE,
Point (−1.73, −3), // Approximation o f the source . 0 , 0 , 0 , 0 , 1 , 3 , // The l i n e : y = −3.
Point ( 1 . 4 1 , −2), // Approximation o f the t a r g e t . 0 , 0 , 0 , 0 , 1 , 2 ) ; // The l i n e : y = −2.
CGAL_assertion( c6 . is_va lid ( ) ) ; i n s e r t ( arr , c6 ) ;
// I n s e r t the r i g h t h a l f o f the c i r c l e centered at (4 , 2.5) whose radiu s // i s 1/2 ( t h e r e f o r e i t s squared radiu s i s 1/4) (C7 ) .
Rat_circle c i r c 7 ( Rat_point( 4 , Rational ( 5 , 2 ) ) , Rational ( 1 , 4 ) ) ;
i n s e r t ( arr , Conic_arc ( c i r c 7 , CGAL: :CLOCKWISE, Point ( 4 , 3 ) , Point ( 4 , 2 ) ) ) ; print_arrangement_size ( a r r ) ;
return 0 ; }