Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
line.H File Reference

2D infinite line representation using slope-intercept form. More...

#include <cmath>
#include <utility>
#include <string>
#include <sstream>
#include <ah-errors.H>
Include dependency graph for line.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::LineEq
 2D infinite line in slope-intercept form. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 

Variables

constexpr double Aleph::LINE_EPSILON = 1e-10
 Default epsilon for floating-point comparisons.
 

Detailed Description

2D infinite line representation using slope-intercept form.

This file provides the LineEq class for representing infinite lines in 2D space using the slope-intercept form: y = y0 + m*x

Line Equation Form

The line is stored as:

  • y0: y-intercept (where line crosses y-axis)
  • m: slope (rise over run)

This gives the equation: y = y0 + m*x

Features

  • Construction from slope and intercept
  • Construction from a point and slope
  • Construction from two points
  • Line evaluation at any x-coordinate
  • Intersection computation between lines
  • Parallel line detection
  • Comparison operations with epsilon tolerance

Usage Example

#include <line.H>
// Line through origin with slope 2
LineEq line1(0.0, 2.0); // y = 2x
// Line through two points
LineEq line2(Point(0, 0), Point(1, 1)); // y = x
// Evaluate line at x = 5
double y = line1(5.0); // y = 10
// Find intersection
auto [x, y] = line1.intersection(line2);
// Check if parallel
if (line1.is_parallel_to(line2))
std::cout << "Lines are parallel\n";
Rectangular point in the plane.
Definition point.H:156
2D infinite line representation using slope-intercept form.
static mpfr_t y
Definition mpfr_mul_d.c:3

Limitations

This representation cannot handle vertical lines (infinite slope). For vertical lines, consider using parametric or implicit form.

See also
segment.H Finite line segments
point.H Point representation
Author
Leandro Rabindranath León

Definition in file line.H.