CGAL 5.1 - 2D and 3D Linear Geometry Kernel
CGAL::Line_2< Kernel > Class Template Reference

#include <CGAL/Line_2.h>

Definition

template<typename Kernel>
class CGAL::Line_2< Kernel >

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

\[ l:\; a\, x +b\, y +c = 0. \]

The line splits \( \E^2\) in a positive and a negative side. 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\). The positive side is to the left of l.

Example

Let us first define two Cartesian two-dimensional points in the Euclidean plane \( \E^2\). Their dimension and the fact that they are Cartesian is expressed by the suffix _2 and the representation type Cartesian.

Point_2< Cartesian<double> > p(1.0,1.0), q(4.0,7.0);

To define a line l we write:

Line_2< Cartesian<double> > l(p,q);
Is Model Of:
Kernel::Line_2

Creation

 Line_2 (const Kernel::RT &a, const Kernel::RT &b, const Kernel::RT &c)
 introduces a line l with the line equation in Cartesian coordinates \( ax +by +c = 0\). More...
 
 Line_2 (const Point_2< Kernel > &p, const Point_2< Kernel > &q)
 introduces a line l passing through the points p and q. More...
 
 Line_2 (const Point_2< Kernel > &p, const Direction_2< Kernel > &d)
 introduces a line l passing through point p with direction d. More...
 
 Line_2 (const Point_2< Kernel > &p, const Vector_2< Kernel > &v)
 introduces a line l passing through point p and oriented by v. More...
 
 Line_2 (const Segment_2< Kernel > &s)
 introduces a line l supporting the segment s, oriented from source to target. More...
 
 Line_2 (const Ray_2< Kernel > &r)
 introduces a line l supporting the ray r, with same orientation. More...
 

Operations

bool operator== (const Line_2< Kernel > &h) const
 Test for equality: two lines are equal, iff they have a non empty intersection and the same direction. More...
 
bool operator!= (const Line_2< Kernel > &h) const
 Test for inequality. More...
 
Kernel::RT a () const
 returns the first coefficient of l. More...
 
Kernel::RT b () const
 returns the second coefficient of l. More...
 
Kernel::RT c () const
 returns the third coefficient of l. More...
 
Point_2< Kernelpoint (const Kernel::FT i) const
 returns an arbitrary point on l. More...
 
Point_2< Kernelprojection (const Point_2< Kernel > &p) const
 returns the orthogonal projection of p onto l. More...
 
Kernel::FT x_at_y (const Kernel::FT &y) const
 returns the \( x\)-coordinate of the point at l with given \( y\)-coordinate. More...
 
Kernel::FT y_at_x (const Kernel::FT &x) const
 returns the \( y\)-coordinate of the point at l with given \( x\)-coordinate. More...
 

Predicates

bool is_degenerate () const
 line l is degenerate, if the coefficients a and b of the line equation are zero. More...
 
bool is_horizontal () const
 
bool is_vertical () const
 
Oriented_side oriented_side (const Point_2< Kernel > &p) const
 returns ON_ORIENTED_BOUNDARY, ON_NEGATIVE_SIDE, or the constant ON_POSITIVE_SIDE, depending on the position of p relative to the oriented line l. More...
 

Convenience Boolean Functions

bool has_on (const Point_2< Kernel > &p) const
 
bool has_on_positive_side (const Point_2< Kernel > &p) const
 
bool has_on_negative_side (const Point_2< Kernel > &p) const
 

Miscellaneous

Vector_2< Kernelto_vector () const
 returns a vector having the direction of l. More...
 
Direction_2< Kerneldirection () const
 returns the direction of l. More...
 
Line_2< Kernelopposite () const
 returns the line with opposite direction. More...
 
Line_2< Kernelperpendicular (const Point_2< Kernel > &p) const
 returns the line perpendicular to l and passing through p, where the direction is the direction of l rotated counterclockwise by 90 degrees. More...
 
Line_2< Kerneltransform (const Aff_transformation_2< Kernel > &t) const
 returns the line obtained by applying t on a point on l and the direction of l. More...
 

Constructor & Destructor Documentation

◆ Line_2() [1/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Kernel::RT a,
const Kernel::RT b,
const Kernel::RT c 
)

introduces a line l with the line equation in Cartesian coordinates \( ax +by +c = 0\).

◆ Line_2() [2/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Point_2< Kernel > &  p,
const Point_2< Kernel > &  q 
)

introduces a line l passing through the points p and q.

Line l is directed from p to q.

◆ Line_2() [3/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Point_2< Kernel > &  p,
const Direction_2< Kernel > &  d 
)

introduces a line l passing through point p with direction d.

◆ Line_2() [4/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Point_2< Kernel > &  p,
const Vector_2< Kernel > &  v 
)

introduces a line l passing through point p and oriented by v.

◆ Line_2() [5/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Segment_2< Kernel > &  s)

introduces a line l supporting the segment s, oriented from source to target.

◆ Line_2() [6/6]

template<typename Kernel >
CGAL::Line_2< Kernel >::Line_2 ( const Ray_2< Kernel > &  r)

introduces a line l supporting the ray r, with same orientation.

Member Function Documentation

◆ a()

template<typename Kernel >
Kernel::RT CGAL::Line_2< Kernel >::a ( ) const

returns the first coefficient of l.

◆ b()

template<typename Kernel >
Kernel::RT CGAL::Line_2< Kernel >::b ( ) const

returns the second coefficient of l.

◆ c()

template<typename Kernel >
Kernel::RT CGAL::Line_2< Kernel >::c ( ) const

returns the third coefficient of l.

◆ direction()

template<typename Kernel >
Direction_2<Kernel> CGAL::Line_2< Kernel >::direction ( ) const

returns the direction of l.

◆ has_on()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::has_on ( const Point_2< Kernel > &  p) const

◆ has_on_negative_side()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::has_on_negative_side ( const Point_2< Kernel > &  p) const

◆ has_on_positive_side()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::has_on_positive_side ( const Point_2< Kernel > &  p) const

◆ is_degenerate()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::is_degenerate ( ) const

line l is degenerate, if the coefficients a and b of the line equation are zero.

◆ is_horizontal()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::is_horizontal ( ) const

◆ is_vertical()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::is_vertical ( ) const

◆ operator!=()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::operator!= ( const Line_2< Kernel > &  h) const

Test for inequality.

◆ operator==()

template<typename Kernel >
bool CGAL::Line_2< Kernel >::operator== ( const Line_2< Kernel > &  h) const

Test for equality: two lines are equal, iff they have a non empty intersection and the same direction.

◆ opposite()

template<typename Kernel >
Line_2<Kernel> CGAL::Line_2< Kernel >::opposite ( ) const

returns the line with opposite direction.

◆ oriented_side()

template<typename Kernel >
Oriented_side CGAL::Line_2< Kernel >::oriented_side ( const Point_2< Kernel > &  p) const

returns ON_ORIENTED_BOUNDARY, ON_NEGATIVE_SIDE, or the constant ON_POSITIVE_SIDE, depending on the position of p relative to the oriented line l.

◆ perpendicular()

template<typename Kernel >
Line_2<Kernel> CGAL::Line_2< Kernel >::perpendicular ( const Point_2< Kernel > &  p) const

returns the line perpendicular to l and passing through p, where the direction is the direction of l rotated counterclockwise by 90 degrees.

◆ point()

template<typename Kernel >
Point_2<Kernel> CGAL::Line_2< Kernel >::point ( const Kernel::FT  i) const

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.

◆ projection()

template<typename Kernel >
Point_2<Kernel> CGAL::Line_2< Kernel >::projection ( const Point_2< Kernel > &  p) const

returns the orthogonal projection of p onto l.

◆ to_vector()

template<typename Kernel >
Vector_2<Kernel> CGAL::Line_2< Kernel >::to_vector ( ) const

returns a vector having the direction of l.

◆ transform()

template<typename Kernel >
Line_2<Kernel> CGAL::Line_2< Kernel >::transform ( const Aff_transformation_2< Kernel > &  t) const

returns the line obtained by applying t on a point on l and the direction of l.

◆ x_at_y()

template<typename Kernel >
Kernel::FT CGAL::Line_2< Kernel >::x_at_y ( const Kernel::FT y) const

returns the \( x\)-coordinate of the point at l with given \( y\)-coordinate.

Precondition
l is not horizontal.

◆ y_at_x()

template<typename Kernel >
Kernel::FT CGAL::Line_2< Kernel >::y_at_x ( const Kernel::FT x) const

returns the \( y\)-coordinate of the point at l with given \( x\)-coordinate.

Precondition
l is not vertical.