next up previous contents index
Next: Rational Rays ( rat_ray Up: Basic Data Types for Previous: Rational Points ( rat_point

     
Rational Segments ( rat_segment )

Definition

An instance s of the data type rat$ \_$segment is a directed straight line segment in the two-dimensional plane, i.e., a line segment [p, q] connecting two rational points p and q (cf. Rational Points). p is called the source or start point and q is called the target or end point of s. A segment is called trivial if its source is equal to its target.

#include < LEDA/rat _segment.h >

Creation

rat_segment s introduces a variable s of type rat_segment. s is initialized to the empty segment.
rat_segment s(rat_point p, rat_point q)
    introduces a variable s of type rat_segment. s is initialized to the segment [p, q].
rat_segment s(rat_point p, rat_vector v)
    introduces a variable s of type rat_segment. s is initialized to the segment [p, p + v].
Precondition: v.dim() = 2.
rat_segment s(rational x1, rational y1, rational x2, rational y2)
    introduces a variable s of type rat_segment. s is initialized to the segment [(x1, y1),(x2, y2)].
rat_segment s(integer x1, integer y1, integer w1, integer x2, integer y2, integer w2)
    introduces a variable s of type rat_segment. s is initialized to the segment [(x1, y1, w1),(x2, y2, w2)].
rat_segment s(integer x1, integer y1, integer x2, integer y2)
    introduces a variable s of type rat_segment. s is initialized to the segment [(x1, y1),(x2, y2)].
rat_segment s(segment s, int prec = rat_point::default_precision)
    introduces a variable s of type rat_segment. s is initialized to the segment obtained by approximating the two defining points of s.

Operations

segment s.to_segment() returns a floating point approximation of s.
rat_point s.start() returns the source point of s.
rat_point s.end() returns the target point of s.
rat_segment  s.reversal() returns the segment (target(),source()).
rational s.xcoord1() returns the x-coordinate of the source point of s.
rational s.xcoord2() returns the x-coordinate of the target point of s.
rational s.ycoord1() returns the y-coordinate of the source point of s.
rational s.ycoord2() returns the y-coordinate of the target point of s.
double  s.xcoord1D() returns a double precision approximation of s.xcoord1().
double  s.xcoord2D() returns a double precision approximation of s.xcoord2().
double  s.ycoord1D() returns a double precision approximation of s.ycoord1().
double  s.ycoord2D() returns a double precision approximation of s.ycoord2().
integer s.X1() returns the first homogeneous coordinate of the source point of s.
integer s.X2() returns the first homogeneous coordinate of the target point of s.
integer s.Y1() returns the second homogeneous coordinate of the source point of s.
integer s.Y2() returns the second homogeneous coordinate of the target point of s.
integer s.W1() returns the third homogeneous coordinate of the source point of s.
integer s.W2() returns the third homogeneous coordinate of the target point of s.
double  s.XD1() returns a floating point approximation of s.X1().
double  s.XD2() returns a floating point approximation of s.X2().
double  s.YD1() returns a floating point approximation of s.Y1().
double  s.YD2() returns a floating point approximation of s.Y2().
double  s.WD1() returns a floating point approximation of s.W1().
double  s.WD2() returns a floating point approximation of s.W2().
integer s.dx() returns the normalized x-difference X2*W1 - X1*W2 of s.
integer s.dy() returns the normalized y-difference Y2*W1 - Y1*W2 of s.
double  s.dxD() returns a floating point approximation of s.dx().
double  s.dyD() returns a floating point approximation of s.dy().
bool s.is_trivial() returns true if s is trivial.
bool s.is_vertical() returns true if s is vertical.
Precondition: s is non-trivial.
bool s.is_horizontal() returns true if s is horizontal.
Precondition: s is non-trivial.
int  s.cmp_slope(rat_segment s1)
    compares the slopes of s and s1.
Precondition: s and s1 are non-trivial.
bool s.contains(rat_point p) decides whether s contains p.
bool s.intersection(rat_segment t)
    decides whether s and t intersect.
bool s.intersection(rat_segment t, rat_point& p)
    decides whether s and t intersect. If so, some point of intersection is assigned to p.
bool s.intersection(rat_segment t, rat_segment& inter)
    decides whether s and t intersect. If so, the segment formed by the points of intersection is assigned to inter.
bool s.intersection_of_lines(rat_segment t, rat_point& p)
    decides if the lines supporting s and t intersect in a single point. If so, the point of intersection is assigned to p.
Precondition: s and t are nontrivial.
rat_segment  s.translate(rational dx, rational dy)
    returns s translated by vector (dx, dy).
rat_segment  s.translate(integer dx, integer dy, integer dw)
    returns s translated by vector (dx/dw, dy/dw).
rat_segment  s.translate(rat_vector v) returns s + v, i.e., s translated by vector v.
Precondition: v.dim() = 2.
rat_segment s + rat_vector v returns s translated by vector v.
rat_segment s - rat_vector v returns s translated by vector - v.
rat_segment  s.rotate90(rat_point q) returns s rotated by an angle of 90 degrees about point q.
rat_segment  s.rotate90() returns s.rotate90(s.source()).
rat_segment  s.reflect(rat_point p, rat_point q)
    returns s reflected across the straight line passing through p and q.
rat_segment  s.reflect(rat_point p) returns s reflected across point p.
rat_segment  s.reverse() returns s reversed.
rat_segment  s.perpendicular(rat_point p)
    returns the segment perpendicular to s with source p and target on line(s).
Precondition: s is nontrivial.
rational s.sqr_length() returns the square of the length of s.
rational s.sqr_dist(rat_point p) returns the squared Euclidean distance between p and s.
rational s.sqr_dist() returns the squared distance between s and the origin.
rat_vector s.to_vector() returns the vector s.target() - s.source().
int s == t returns true if s and t are equal as oriented segments
int  equal_as_sets(rat_segment s, rat_segment t)
    returns true if s and t are equal as unoriented segments
ostream& ostream& O << s writes [s.source() === s.target()] to output stream O.
istream& istream& I >> rat_segment& s
    reads {[} p {===} q {]} from input stream I.

Non-Member Functions

int  orientation(rat_segment s, rat_point p)
    computes orientation(a, b, p), where a! = b and a and b appear in this order on segment s.
int  cmp_slopes(rat_segment s1, rat_segment s2)
    returns compare(slope(s1), slope(s2)).
int  cmp_segments_at_xcoord(rat_segment s1, rat_segment s2, rat_point p)
    compares points l1 < intersection > v and l2 < intersection > v where li is the line underlying segment si and v is the vertical straight line passing through point p.


next up previous contents index
Next: Rational Rays ( rat_ray Up: Basic Data Types for Previous: Rational Points ( rat_point
LEDA research project
1999-04-23