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

2D Segment (CGAL_Segment_2)

Definition

An object s of the data type CGAL_Segment_2 is a directed straight line segment in the two-dimensional Euclidean plane E2, i.e. a straight line segment [p,q] connecting two points p,q in R2. The segment is topologically closed, i.e. the end points belong to it. Point p is called the source and q is called the target of s. The length of s is the Euclidean distance between p and q. Note that there is only a function to compute the square of the length, because otherwise we had to perform a square root operation which is not defined for all number types, is expensive, and may be inexact.

#include <CGAL/Segment_2.h>

Creation

CGAL_Segment_2<R> s ( CGAL_Point_2<R> p, CGAL_Point_2<R> q);
introduces a segment s with source p and target q. The segment is directed from the source towards the target.

Operations

bool s == q Test for equality: Two segments are equal, iff their sources and targets are equal.
bool s != q Test for inequality.
CGAL_Point_2<R> s.source () returns the source of s.
CGAL_Point_2<R> s.target () returns the target of s.
CGAL_Point_2<R> s.min () returns the point of s with lexicographically smallest coordinate.
CGAL_Point_2<R> s.max () returns the point of s with lexicographically largest coordinate.
CGAL_Point_2<R> s.vertex ( int i) returns source or target of s: vertex(0) returns the source of s, vertex(1) returns the target of s. The parameter i is taken modulo 2, which gives easy access to the other vertex.
CGAL_Point_2<R> s.point ( int i) returns vertex(i).
CGAL_Point_2<R> s [ int i] returns vertex(i).
R::FT s.squared_length ()
returns the squared length of s.
CGAL_Direction_2<R>
s.direction () returns the direction from source to target of s.
CGAL_Segment_2<R> s.opposite () returns a segment with source and target point interchanged.
CGAL_Line_2<R> s.supporting_line ()
returns the line l passing through s. Line l has the same orientation as segment s.

Predicates

bool s.is_degenerate () segment s is degenerate, if source and target are equal.
bool s.is_horizontal ()
bool s.is_vertical ()
bool s.has_on ( CGAL_Point_2<R> p)
A point is on s, iff it is equal to the source or target of s, or if it is in the interior of s.
bool s.collinear_has_on ( CGAL_Point_2<R> p)
checks if point p is on segment s. This function is faster than function has_on().
Precondition: p is on the supporting line of s.

Miscellaneous

CGAL_Bbox_2 s.bbox () returns a bounding box containing s.
CGAL_Segment_2<R> s.transform ( CGAL_Aff_transformation_2<R> t)
returns the segment obtained by applying t on the source and the target of s.


Return to chapter: 2D Line, Ray and Segment
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Wed, January 20, 1999.