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

2D Line (CGAL_Line_2)

Definition

An object l of the data type CGAL_Line_2 is a directed straight line in the two-dimensional Euclidean plane E2. It is defined by the set of points with Cartesian coordinates (x,y) that satisfy the equation

l : ax + by + c = 0

The line splits E2 in a positive and a negative side.[^1] A point p with Cartesian coordinates (px, py) is on the positive side of l, iff a px + b py + c > 0, it is on the negative side of l, iff a px + b py + c < 0.

#include <CGAL/Line_2.h>

Creation

CGAL_Line_2<R> l ( R::RT a, R::RT b, R::RT c);
introduces a line l with the line equation in Cartesian coordinates ax +by +c = 0.

CGAL_Line_2<R> l ( CGAL_Point_2<R> p, CGAL_Point_2<R> q);
introduces a line l passing through the points p and q. Line l is directed from p to q.

CGAL_Line_2<R> l ( CGAL_Point_2<R> p, CGAL_Direction_2<R> d);
introduces a line l passing through point p with direction d.

CGAL_Line_2<R> l ( CGAL_Segment_2<R> s);
introduces a line l supporting the segment s, oriented from source to target.

CGAL_Line_2<R> l ( CGAL_Ray_2<R> r);
introduces a line l supporting the ray r, with same orientation.

Operations

bool l == h Test for equality: two lines are equal, iff they have a non empty intersection and the same direction.
bool l != h Test for inequality.
R::RT l.a () returns the first coefficient of L.
R::RT l.b () returns the second coefficient of L.
R::RT l.c () returns the third coefficient of L.
CGAL_Point_2<R> l.point ( int i) returns an arbitrary point on l. It holds point(i) == point(j), iff i==j. Furthermore, l is directed from point(i) to point(j), for all i < j.
CGAL_Point_2<R> l.projection ( CGAL_Point_2<R> p)
returns the orthogonal projection of p onto l.
R::FT l.x_at_y ( R::FT y)
returns the x-coordinate of the point at l with given y-coordinate.
Precondition: l is not horizontal.
R::FT l.y_at_x ( R::FT x)
returns the y-coordinate of the point at l with given x-coordinate.
Precondition: l is not vertical.

Predicates

bool l.is_degenerate () line l is degenerate, if the coefficients a and b of the line equation are zero.
bool l.is_horizontal ()
bool l.is_vertical ()
CGAL_Oriented_side l.oriented_side ( CGAL_Point_2<R> p)
returns CGAL_ON_ORIENTED_BOUNDARY, CGAL_ON_NEGATIVE_SIDE, or the constant CGAL_ON_POSITIVE_SIDE, depending on the position of p relative to the oriented line l.

For convenience we provide the following boolean functions:

bool l.has_on ( CGAL_Point_2<R> p)
bool l.has_on_boundary ( CGAL_Point_2<R> p)
returns has_on().
bool l.has_on_positive_side ( CGAL_Point_2<R> p)
bool l.has_on_negative_side ( CGAL_Point_2<R> p)

Miscellaneous

CGAL_Direction_2<R>
l.direction () returns the direction of l.
CGAL_Line_2<R> l.opposite () returns the line with opposite direction.
CGAL_Line_2<R> l.perpendicular ( CGAL_Point_2<R> p)
returns the line perpendicular to l and passing through p, where the direction is the direction of l rotated counterclockwise by 90 degrees.
CGAL_Line_2<R> l.transform ( CGAL_Aff_transformation_2<R> t)
returns the line obtained by applying t on a point on l and the direction of l.

Implementation

Lines are implemented as a line equation. Construction from points or a point and a direction, might lead to loss of precision if the number type is not exact.

Example

Let us first define two Cartesian two-dimensional points in the Euclidean plane E2. Their dimension and the fact that they are Cartesian is expressed by the suffix _2 and the representation type CGAL_Cartesian.


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

To define a line l we write:


  CGAL_Line_2< CGAL_Cartesian<double> > l(p,q);


Footnotes

  1. See Chapter [ref:Utilities] for the definition of CGAL_Oriented_side.

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