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

CGAL::Point_2<R>

Definition

An object of the class Point_2<R> is a point in the two-dimensional Euclidean plane 2.

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

Creation

Point_2<R> p ( Origin ORIGIN);
introduces a variable p with Cartesian coordinates (0,0).


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 R::RT(0)

Operations

bool p.operator== ( q)
Test for equality. Two points are equal, iff their x and y coordinates are equal. The point can be compared with ORIGIN.

bool p.operator!= ( q)
Test for inequality. The point can be compared with 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.operator[] ( int i)
returns cartesian(i).
Precondition: 0 i 1.

int p.dimension () returns the dimension (the constant 2).

Bbox_2 p.bbox () returns a bounding box containing p. Note that bounding boxes are not parameterized with whatsoever.

Point_2<R> p.transform ( Aff_transformation_2<R> t)
returns the point obtained by applying t on p.

Operators

The following operations can be applied on points:

Vector_2<R> operator- ( p, q)
returns the difference vector between q and p. You can substitute ORIGIN for either p or q, but not for both.

Point_2<R> operator+ ( p, Vector_2<R> v)
returns the point obtained by translating p by the vector v.

Point_2<R> operator- ( p, Vector_2<R> v)
returns the point obtained by translating p by the vector -v.

Example

The following declaration creates two points with Cartesian double coordinates.


  Point_2< 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;

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

See Also

Kernel::Point_2


Next: Ray_2<R>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
www.cgal.org. Aug 13, 2001.