next up previous contents
Next: Straight Rational Lines (rat_line) Up: Basic Data Types for Previous: Rational Segments (rat_segment)

   
Rational Rays (rat_ray)

Definition

An instance r of the data type rat_ray is a directed straight ray defined by two points with rational coordinates in the two-dimensional plane.

Creation

rat_ray r(rat_point p, rat_point q);
    introduces a variable r of type rat_ray. r is initialized to the ray starting at point p and passing through point q.
Precondition: p != q.
rat_ray r(rat_segment s); introduces a variable r of type rat_ray. r is initialized to the (rat_ray(s.source(),s.target()).
Precondition: s is nontrivial.

rat_ray

r; introduces a variable r of type rat_ray.

   

Operations

ray r.to_ray() returns a floating point approximation of r.
rat_point r.source() returns the source of r.
rat_point r.point1() returns the source of r.
rat_point r.point2() returns a point on r different from r.source().
bool r.is_vertical() returns true iff r is vertical.
bool r.is_horizontal() returns true iff r is horizontal.
bool r.intersection(rat_ray s, rat_point& inter)
    returns true if r and s intersect. If so, a point of intersection is returned in inter.
bool r.intersection(rat_segment s, rat_point& inter)
    returns true if r and s intersect. If so, a point of intersection is returned in inter.
rat_ray r.translate(rational dx, rational dy)
    returns r translated by vector (dx,dy).
rat_ray r.translate(integer dx, integer dy, integer dw)
    returns r translated by vector (dx/dw,dy/dw).
rat_ray r.translate(rat_vector v) returns r+v, i.e., r translated by vector v.
Precondition: v.dim() = 2.
rat_ray r + rat_vector v returns r translated by vector v.
rat_ray r - rat_vector v returns r translated by vector -v.
rat_ray r.rotate90(rat_point q) returns r rotated about q by an angle of 90 degrees.
rat_ray r.reflect(rat_point p, rat_point q)
    returns r reflected across the straight line passing through p and q.
Precondition: p != q.
rat_ray r.reflect(rat_point p) returns r reflected across point p.
rat_ray r.reverse() returns r reversed.
bool r.contains(rat_point p) decides whether r contains p.
bool r.contains(rat_segment s) decides whether r contains s.

Non-Member Functions

int orientation(rat_ray r, rat_point p)
    computes orientation(a, b, p), where a != b and a and b appear in this order on ray r.
int cmp_slopes(rat_ray r1, rat_ray r2)
    returns compare(slope(r_1), slope(r_2)).


next up previous contents
Next: Straight Rational Lines (rat_line) Up: Basic Data Types for Previous: Rational Segments (rat_segment)
LEDA research project
1998-10-02