|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
2D infinite line in slope-intercept form. More...
#include <line.H>
Public Member Functions | |
| constexpr | LineEq () noexcept=default |
| Default constructor creates line y = x. | |
| LineEq (const Geom_Number &__y0, const Geom_Number &__m) noexcept | |
| Construct line from y-intercept and slope. | |
| LineEq (const Geom_Number &x1, const Geom_Number &y1, const Geom_Number &__m) noexcept | |
| Construct line through a point with given slope. | |
| LineEq (const Geom_Number &x1, const Geom_Number &y1, const Geom_Number &x2, const Geom_Number &y2) | |
| Construct a line through two points. | |
| LineEq (const Point &p, const Geom_Number &__m) noexcept | |
| Construct a line through a Point with a given slope. | |
| LineEq (const Point &p1, const Point &p2) | |
| Construct line through two Points. | |
| Geom_Number | operator() (const Geom_Number &x) const noexcept |
| Evaluate line at given x-coordinate. | |
| const Geom_Number & | slope () const noexcept |
| Get the slope of the line. | |
| const Geom_Number & | y_intercept () const noexcept |
| Get the y-intercept of the line. | |
| bool | is_horizontal (const Geom_Number &epsilon=LINE_EPSILON) const noexcept |
| Check if the line is horizontal (slope = 0). | |
| bool | is_parallel_to (const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const noexcept |
| Check if this line is parallel to another. | |
| bool | is_perpendicular_to (const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const noexcept |
| Check if this line is perpendicular to another. | |
| Geom_Number | x_at (const Geom_Number &y) const |
| Compute x-coordinate for a given y-coordinate. | |
| std::pair< Geom_Number, Geom_Number > | intersection (const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const |
| Compute the intersection point with another line. | |
| LineEq | perpendicular_through (const Geom_Number &px, const Geom_Number &py) const |
| Compute perpendicular line through a point. | |
| Geom_Number | distance_to (const Geom_Number &px, const Geom_Number &py) const noexcept |
| Compute distance from a point to this line. | |
| bool | contains_point (const Geom_Number &px, const Geom_Number &py, const Geom_Number &epsilon=LINE_EPSILON) const noexcept |
| Check if a point lies on this line. | |
| Geom_Number | distance_to (const Point &p) const noexcept |
| Compute distance from a Point to this line. | |
| LineEq | perpendicular_through (const Point &p) const |
| Compute a perpendicular line through a Point. | |
| bool | contains_point (const Point &p, const Geom_Number &epsilon=LINE_EPSILON) const noexcept |
| Check if a Point lies on this line. | |
| Point | intersection_point (const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const |
| Compute the intersection Point with another line. | |
| bool | operator== (const LineEq &l) const noexcept |
| Test equality of two lines. | |
| bool | operator!= (const LineEq &l) const noexcept |
| Test inequality of two lines. | |
| bool | approx_equal (const LineEq &l, const Geom_Number &epsilon) const noexcept |
| Test approximate equality of two lines. | |
| std::string | to_string () const |
| Convert line to a string representation. | |
Public Attributes | |
| Geom_Number | y0 {0} |
| Y-intercept (where line crosses y-axis) | |
| Geom_Number | m {1} |
| Slope (dy/dx) | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const LineEq &l) |
| Output stream operator. | |
2D infinite line in slope-intercept form.
Represents an infinite line using the equation y = y0 + m*x where:
|
constexprdefaultnoexcept |
Default constructor creates line y = x.
The default line passes through origin with slope 1.
|
inlinenoexcept |
Construct line from y-intercept and slope.
Creates line: y = y0 + m*x
| __y0 | Y-intercept (value of y when x = 0) |
| __m | Slope of the line |
|
inlinenoexcept |
Construct line through a point with given slope.
Computes y-intercept from point and slope using: y0 = y1 - m*x1
| x1 | X-coordinate of point on the line |
| y1 | Y-coordinate of point on the line |
| __m | Slope of the line |
|
inline |
Construct a line through two points.
Computes slope and y-intercept from the two points. The slope is: m = (y2 - y1) / (x2 - x1)
| x1 | X-coordinate of first point |
| y1 | Y-coordinate of first point |
| x2 | X-coordinate of second point |
| y2 | Y-coordinate of second point |
| domain_error | if x1 == x2 (vertical line, undefined slope) |
Definition at line 192 of file line.H.
References ah_domain_error_if, m, y0, and y1().
|
inlinenoexcept |
Construct line through two Points.
| p1 | First point |
| p2 | Second point |
| domain_error | if points have the same x-coordinate (vertical line) |
|
inlinenoexcept |
Test approximate equality of two lines.
Lines are approximately equal if their slope and y-intercept are within an epsilon tolerance.
| l | Line to compare with |
| epsilon | Tolerance for comparison |
Definition at line 497 of file line.H.
References abs(), Aleph::and, l, m, and y0.
|
inlinenoexcept |
Check if a point lies on this line.
| px | X-coordinate of point |
| py | Y-coordinate of point |
| epsilon | Tolerance for comparison (default: exact equality) |
Definition at line 399 of file line.H.
References abs(), and Aleph::divide_and_conquer_partition_dp().
Referenced by contains_point(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Check if a Point lies on this line.
| p | The point to test |
| epsilon | Tolerance for comparison (default: exact equality) |
Definition at line 435 of file line.H.
References contains_point().
|
inlinenoexcept |
Compute distance from a point to this line.
Uses the formula: d = |y_point - (y0 + m*x_point)| / sqrt(1 + m^2)
| px | X-coordinate of point |
| py | Y-coordinate of point |
Definition at line 383 of file line.H.
References abs(), Aleph::diff(), Aleph::divide_and_conquer_partition_dp(), m, sqrt(), and y0.
Referenced by distance_to(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Compute distance from a Point to this line.
| p | The point |
Definition at line 411 of file line.H.
References distance_to().
|
inline |
Compute the intersection point with another line.
Solves the system of equations to find where lines cross:
Solution: x = (y0_1 - y0_2) / (m_2 - m_1)
| l | The other line |
| epsilon | Tolerance for parallel line detection |
| domain_error | if lines are parallel (no unique intersection) |
Definition at line 343 of file line.H.
References ah_domain_error_if, is_parallel_to(), l, m, and y0.
Referenced by intersection_point(), and TEST_F().
|
inline |
Compute the intersection Point with another line.
| l | The other line |
| epsilon | Tolerance for parallel line detection |
| domain_error | if lines are parallel (no unique intersection) |
Definition at line 456 of file line.H.
References intersection(), l, and y.
|
inlinenoexcept |
|
inlinenoexcept |
Check if this line is parallel to another.
Two lines are parallel if they have the same slope.
| l | The other line |
| epsilon | Tolerance for comparison (default: exact equality) |
Definition at line 285 of file line.H.
Referenced by intersection().
|
inlinenoexcept |
Test inequality of two lines.
| l | Line to compare with |
Definition at line 482 of file line.H.
References Aleph::divide_and_conquer_partition_dp(), and l.
|
inlinenoexcept |
Evaluate line at given x-coordinate.
Computes y = y0 + m*x
| x | X-coordinate to evaluate |
|
inline |
Compute perpendicular line through a point.
Returns the line perpendicular to this one that passes through the given point. The perpendicular slope is -1/m.
| px | X-coordinate of point |
| py | Y-coordinate of point |
| domain_error | if this line is horizontal (perpendicular would be vertical) |
Definition at line 365 of file line.H.
References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), is_horizontal(), and m.
Referenced by perpendicular_through(), TEST_F(), and TEST_F().
Compute a perpendicular line through a Point.
| p | Point on the perpendicular line |
| domain_error | if this line is horizontal (perpendicular would be vertical) |
Definition at line 423 of file line.H.
References Aleph::Point::get_x(), Aleph::Point::get_y(), and perpendicular_through().
|
inlinenoexcept |
|
inline |
|
inline |
Compute x-coordinate for a given y-coordinate.
Solves x = (y - y0) / m
| y | Y-coordinate |
| domain_error | if line is horizontal (undefined x) |
Definition at line 315 of file line.H.
References ah_domain_error_if, is_horizontal(), m, y, and y0.
|
inlinenoexcept |
| Geom_Number Aleph::LineEq::m {1} |
Slope (dy/dx)
Definition at line 128 of file line.H.
Referenced by LineEq(), approx_equal(), distance_to(), intersection(), is_horizontal(), is_parallel_to(), is_perpendicular_to(), operator()(), operator==(), perpendicular_through(), slope(), TEST_F(), TEST_F(), TEST_F(), to_string(), and x_at().
| Geom_Number Aleph::LineEq::y0 {0} |
Y-intercept (where line crosses y-axis)
Definition at line 127 of file line.H.
Referenced by LineEq(), approx_equal(), distance_to(), intersection(), operator()(), operator==(), TEST_F(), TEST_F(), TEST_F(), to_string(), x_at(), and y_intercept().