Definition
An instance s of the data type real_segment is a directed straight line
segment in the two-dimensional plane, i.e., a straight line segment [p, q]
connecting two points
p, q
R2. p is called the source or
start point and q is called the target or end point of s. The
length of s is the Euclidean distance between p and q. If p = q,
s is called empty. We use line(s) to denote a straight line
containing s.
#include < LEDA/geo/real_segment.h >
Types
| real_segment::coord_type | the coordinate type (real). |
| real_segment::point_type | the point type (real_point). |
Creation
| real_segment | s(const real_point& p, const real_point& q) | |
| introduces a variable s of type real_segment. s is initialized to the segment [p, q]. | ||
| real_segment | s(const real_point& p, const real_vector& v) | |
| introduces a variable s of type real_segment. s is
initialized to the segment [p, p + v].
Precondition v.dim() = 2. |
||
| real_segment | s(real x1, real y1, real x2, real y2) | |
| introduces a variable s of type real_segment. s is initialized to the segment [(x1, y1),(x2, y2)]. | ||
| real_segment | s | introduces a variable s of type real_segment. s is initialized to the empty segment. |
| real_segment | s(const segment& s1, int prec = 0) | |
| introduces a variable s of type real_segment initialized to the segment s1. (The second argument is for compatibility with rat_segment.) | ||
| real_segment | s(const rat_segment& s1) | introduces a variable s of type real_segment initialized to the segment s1. |
Operations
| real_point | s.start() | returns the source point of segment s. |
| real_point | s.end() | returns the target point of segment s. |
| real | s.xcoord1() | returns the x-coordinate of s.source(). |
| real | s.xcoord2() | returns the x-coordinate of s.target(). |
| real | s.ycoord1() | returns the y-coordinate of s.source(). |
| real | s.ycoord2() | returns the y-coordinate of s.target(). |
| real | s.dx() | returns the xcoord2 - xcoord1. |
| real | s.dy() | returns the ycoord2 - ycoord1. |
| real | s.slope() | returns the slope of s.
Precondition s is not vertical. |
| real | s.sqr_length() | returns the square of the length of s. |
| real | s.length() | returns the length of s. |
| real_vector | s.to_vector() | returns the vector s.target() - s.source(). |
| bool | s.is_trivial() | returns true if s is trivial. |
| bool | s.is_vertical() | returns true iff s is vertical. |
| bool | s.is_horizontal() | returns true iff s is horizontal. |
| int | s.orientation(const real_point& p) | |
| computes orientation( s.source(), s.target(), p) (see below). | ||
| real | s.x_proj(real y) | returns p.xcoord(), where
p Precondition s is not horizontal. |
| real | s.y_proj(real x) | returns p.ycoord(), where
p Precondition s is not vertical. |
| real | s.y_abs() | returns the y-abscissa of line(s), i.e., s.y_proj(0).
Precondition s is not vertical. |
| bool | s.contains(const real_point& p) | |
| decides whether s contains p. | ||
| bool | s.intersection(const real_segment& t) | |
| decides whether s and t intersect in one point. | ||
| bool | s.intersection(const real_segment& t, real_point& p) | |
| if s and t intersect in a single point this point is assigned to p and the result is true, otherwise the result is false. | ||
| bool | s.intersection_of_lines(const real_segment& t, real_point& p) | |
| if line(s) and line(t) intersect in a single point this point is assigned to p and the result is true, otherwise the result is false. | ||
| real_segment | s.translate(real dx, real dy) | |
| returns s translated by vector (dx, dy). | ||
| real_segment | s.translate(const real_vector& v) | |
| returns s + v, i.e., s translated by vector v.
Precondition v.dim() = 2. |
||
| real_segment | s + const real_vector& v | returns s translated by vector v. |
| real_segment | s - const real_vector& v | returns s translated by vector - v. |
| real_segment | s.perpendicular(const real_point& p) | |
| returns the segment perpendicular to s with source p and target on line(s). | ||
| real | s.distance(const real_point& p) | |
| returns the Euclidean distance between p and s. | ||
| real | s.sqr_dist(const real_point& p) | |
| returns the squared Euclidean distance between p and s. | ||
| real | s.distance() | returns the Euclidean distance between (0, 0) and s. |
| real_segment | s.rotate90(const real_point& q, int i=1) | |
| returns s rotated about q by an angle of i x 90 degrees. If i > 0 the rotation is counter-clockwise otherwise it is clockwise. | ||
| real_segment | s.rotate90(int i=1) | returns s.rotate90(s.source(),i). |
| real_segment | s.reflect(const real_point& p, const real_point& q) | |
| returns s reflected across the straight line passing through p and q. | ||
| real_segment | s.reflect(const real_point& p) | |
| returns s reflected across point p. | ||
| real_segment | s.reverse() | returns s reversed. |
Non-Member Functions
| int | orientation(const real_segment& s, const real_point& p) | |
| computes orientation( s.source(), s.target(), p). | ||
| int | cmp_slopes(const real_segment& s1, const real_segment& s2) | |
| returns compare(slope(s1), slope(s2)). | ||
| int | cmp_segments_at_xcoord(const real_segment& s1, const real_segment& s2, const real_point& p) | |
| compares points
l1 |
||
| bool | parallel(const real_segment& s1, const real_segment& s2) | |
| returns true if s1 and s2 are parallel and false otherwise. | ||