Navigation: Up, Table of Contents, Bibliography, Index, Title Page

Preliminaries

Our object of study is the d-dimensional affine Euclidean space. Here we are mainly concerned with cases d=2 and d=3. Objects in that space are sets of points. A common way to represent the points is the use of Cartesian coordinates, which assumes a reference frame (an origin and d orthogonal axes). In that framework, a point is represented by a d-tuple (c0,c1,...,cd-1), and so are vectors in the underlying linear space. Each point is represented uniquely by such Cartesian coordinates. Another way to represent points is by homogeneous coordinates. In that framework, a point is represented by a (d+1)-tuple (h0,h1,...,hd). Via the formulae ci=hi/hd, the corresponding point with Cartesian coordinates (c0,c1,...,cd-1) can be computed. Note that homogeneous coordinates are not unique. For lambda != 0, the tuples (h0,h1 ,...,hd) and (lambda h0,lambda h1,...,lambda hd) represent the same point. For a point with Cartesian coordinates (c0,c1,...,cd-1) a possible homogeneous representation is (c0,c1,...,cd-1,1). Homogeneous coordinates in fact allow to represent objects in a more general space, the projective space Pd. In CGAL, we do not compute in projective geometry. Rather, we use homogeneous coordinates to avoid division operations, since the additional coordinate can serve as a common denominator.

Choosing a Representation Class

If you start with integral Cartesian coordinates, many geometric computations will involve integral numerical values only. Especially, this is true for geometric computations that evaluate only predicates, which are tantamount to determinant computations. Examples are triangulation of point sets and convex hull computation. In this case, the Cartesian representation is probably the first choice, even with a ring type. You might use limited precision integer types like int or long, use double to present your integers (they have more bits in their mantissa than an int and overflow nicely), or an arbitrary precision integer type like the wrapper Gmpz for the GMP integers or leda_integer. Note, that unless you use an arbitrary precision integer type, incorrect results might arise due to overflow.

If new points are to be constructed, for example the intersection point of two lines, computation of Cartesian coordinates usually involves divisions, so you need to use a field type with Cartesian representation or have to switch to homogeneous representation. double is a possible, but imprecise field type. You can also put any ring type into Quotient to get a field type and put it into Cartesian, but you better put the ring type into Homogeneous. leda_rational and leda_real are valid field types, too.

If it is crucial for you that the computation is reliable, the right choice are probably number types that guarantee exact computation. The number type leda_real guarantees that all decisions and hence all branchings in a computation are correct. They also allow you to compute approximations to whatever precision you need. Furthermore computation with leda_real is faster than computation with arbitrary precision arithmetic. So if you would like to avoid surprises caused by imprecise computation, this is a good choice. In fact, it is a good choice with both representations, since divisions slow down the computation of the reals and hence it might pay-off to avoid them.

Still other people will prefer the built-in type double, because they need speed and can live with approximate results, or even algorithms that, from time to time, crash or compute incorrect results due to accumulated rounding errors.

Naming conventions

The use of representation classes not only avoids problems, it also makes all CGAL classes very uniform. They always consist of:

  1. The capitalized base name of the geometric object, such as Point, Segment, Triangle.

  2. An underscore followed by the dimension of the object, for example _2, _3 or _d.

  3. A representation class as parameter, which itself is parameterized with a number type, such as Cartesian<double> or Homogeneous<leda_integer>.


Next chapter: Kernel Utilities
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The GALIA project. Jan 18, 2000.