next up previous contents
Next: Polygons (polygon) Up: Basic Data Types for Previous: Straight Rays (ray)

   
Straight Lines (line)

Definition

An instance l of the data type line is a directed straight line in the two-dimensional plane. The angle between a right oriented horizontal line and l is called the direction of l.

Creation

line l(point p, point q); introduces a variable l of type line. l is initialized to the line passing through points p and q directed form p to q.

line

l(segment s); introduces a variable l of type line. l is initialized to the line supporting segment s.

line

l(ray r); introduces a variable l of type line. l is initialized to the line supporting ray r.

line

l(point p, vector v); introduces a variable l of type line. l is initialized to the line passing through points p and p+v.

line

l(point p, double alpha); introduces a variable l of type line. l is initialized to the line passing through point p with direction alpha.

line

l; introduces a variable l of type line. l is initialized to the line passing through the origin with direction 0.

   

Operations

point l.point1() returns a point on l.
point l.point2() returns a second point on l.
segment l.seg() returns a segment on l.
double l.direction() returns the direction of l.
double l.angle(line g) returns the angle between l and g, i.e., g.direction() - l.direction().
double l.angle() returns l.direction().
bool l.is_vertical() returns true iff l is vertical.
bool l.is_horizontal() returns true iff l is horizontal.
double l.sqr_dist(point q) returns the square of the distance between l and q.
double l.distance(point q) returns the distance between l and q.
double l.slope() returns the slope of l.
Precondition: l is not vertical.
double l.y_proj(double x) returns p.ycoord(), where p in l with p.xcoord() = x.
Precondition: l is not vertical.
double l.x_proj(double y) returns p.xcoord(), where p in l with p.ycoord() = y.
Precondition: l is not horizontal.
double l.y_abs() returns the y-abscissa of l (l.y_proj(0)).
Precondition: l is not vertical.
bool l.intersection(line g, point& p)
    if l and g intersect in a single point this point is assigned to p and the result is true, otherwise the result is false.
bool l.intersection(segment s, point& inter)
    if l and s intersect in a single point this point is assigned to p and the result is true, otherwise the result is false.
line l.translate_by_angle(double a, double d)
    returns l translated in direction a by distance d.
line l.translate(double dx, double dy)
    returns l translated by vector (dx,dy).
line l.translate(vector v) returns l translated by vector v.
Precondition: v.dim() = 2.
line l + vector v returns l translated by vector v.
line l - vector v returns l translated by vector -v.
line l.rotate(point q, double a)
    returns l rotated about point q by angle a.
line l.rotate(double a) returns l.rotate(point(0,0), a).
line l.rotate90(point q) returns l rotated about q by angle of 90 degrees.
line l.reflect(point p, point q)
    returns l reflected across the straight line passing through p and q.
line l.reverse() returns l reversed.
segment l.perpendicular(point p) returns the segment perpendicular to l with source p. and target on l.

Non-Member Functions

int orientation(line l, point p)
    computes orientation(a, b, p), where a != b and a and b appear in this order on line l.
int cmp_slopes(line l1, line l2)
    returns compare(slope(l_1), slope(l_2)).


next up previous contents
Next: Polygons (polygon) Up: Basic Data Types for Previous: Straight Rays (ray)
LEDA research project
1998-10-02