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

2D Point (CGAL_Point_2)

Definition

An object of the class CGAL_Point_2 is a point in the two-dimensional Euclidean plane E2.

Remember that R::RT and R::FT denote a ring type and a field type. For the representation class CGAL_Cartesian<T> the two types are the same. For the representation class CGAL_Homogeneous<T> the ring type R::RT is equal to T, and the field type R::FT is equal to CGAL_Quotient<T>.

#include <CGAL/Point_2.h>

Creation

CGAL_Point_2<R> p ( CGAL_Origin CGAL_ORIGIN);
introduces a variable p with Cartesian coordinates (0,0).

CGAL_Point_2<R> p ( R::RT hx, R::RT hy, R::RT hw = R::RT(1));
introduces a point p initialized to (hx/hw,hy/hw). If the third argument is not explicitly given, it defaults to R::RT(1).
Precondition: hw is not R::RT(0)

Operations

bool p == q Test for equality. Two points are equal, iff their x and y coordinates are equal. The point can be compared with CGAL_ORIGIN.
bool p != q Test for inequality. The point can be compared with CGAL_ORIGIN.

There are two sets of coordinate access functions, namely to the homogeneous and to the Cartesian coordinates. They can be used independently from the chosen representation type R.

R::RT p.hx () returns the homogeneous x coordinate.
R::RT p.hy () returns the homogeneous y coordinate.
R::RT p.hw () returns the homogenizing coordinate.

Here come the Cartesian access functions. Note that you do not loose information with the homogeneous representation, because then the field type is a quotient.

R::FT p.x () returns the Cartesian x coordinate, that is hx/hw.
R::FT p.y () returns the Cartesian y coordinate, that is hy/hw.

The following operations are for convenience and for making this point class compatible with code for higher dimensional points. Again they come in a Cartesian and homogeneous flavor.

R::RT p.homogeneous ( int i)
returns the i'th homogeneous coordinate of p, starting with 0.
Precondition: 0<=i <=2.
R::FT p.cartesian ( int i)
returns the i'th Cartesian coordinate of p, starting with 0.
Precondition: 0<=i <=1.
R::FT p [ int i] returns cartesian(i).
Precondition: 0<=i <=1.
int p.dimension () returns the dimension (the constant 2).

Miscellaneous

CGAL_Bbox_2 p.bbox () returns a bounding box containing p. Note that bounding boxes are not parameterized with whatsoever.
CGAL_Point_2<R> p.transform ( CGAL_Aff_transformation_2<R> t)
returns the point obtained by applying t on p.

Operations

The following operations can be applied on points:

CGAL_Vector_2<R> p - q returns the difference vector between q and p. You can substitute CGAL_ORIGIN for either p or q ,but not for both.
CGAL_Point_2<R> p + CGAL_Vector_2<R> v
returns the point obtained by translating p by the vector v.
CGAL_Point_2<R> p - CGAL_Vector_2<R> v
returns the point obtained by translating p by the vector - v.

See Also

2D Geometric Predicates, reference arrow.

Example

The following declaration creates two points with Cartesian double coordinates.


  CGAL_Point_2< CGAL_Cartesian<double> > p, q(1.0, 2.0);

The variable p is uninitialized and should first be used on the left hand side of an assignment.


  p = q;

  cout << p.x() << "  " << p.y() << endl; 


Next: Class declaration of CGAL_Vector_2<R>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Wed, January 20, 1999.