template<class T>
Rodin::Geometry::Euclidean::Line2D class

Represents a two-dimensional line in general form. A line $ L $ is defined as the set of all points $ (x, y) $ which satisfy the equation:

\[ ax + by - c = 0 \]

Constructors, destructors, conversion operators

Line2D(T a, T b, T c) constexpr
Line2D(const Point2D<T>& p, const Point2D<T>& q) constexpr

Public functions

auto operator()(T x) const -> std::optional<T> constexpr
auto operator()(const Point2D<T>& p) const -> T constexpr
auto a() const -> T constexpr
auto b() const -> T constexpr
auto c() const -> T constexpr
auto slope() const -> std::optional<T> constexpr
auto intersect(const Line2D<T>& other) const -> std::optional<Point2D<T>> constexpr
auto intersect(const Circle<T>& other) const -> std::variant<std::nullopt_t, Point2D<T>, std::pair<Point2D<T>, Point2D<T>>> constexpr
auto connect(const Circle<T>& other) const -> std::optional<LineSegment2D<T>> constexpr
auto distance(const Line2D<T>& other) const -> T constexpr

Function documentation

template<class T>
Rodin::Geometry::Euclidean::Line2D<T>::Line2D(T a, T b, T c) constexpr

Parameters
in The $ a $ coefficient in the equation
in The $ b $ coefficient in the equation
in The $ c $ coefficient in the equation

Constructs a line from its coefficients.

template<class T>
Rodin::Geometry::Euclidean::Line2D<T>::Line2D(const Point2D<T>& p, const Point2D<T>& q) constexpr

Parameters
in First point
in Second point

Constructs a line from two different points.

template<class T>
std::optional<T> Rodin::Geometry::Euclidean::Line2D<T>::operator()(T x) const constexpr

Parameters
in Number to evaluate
Returns Result of evaluation

Evaluates a number $ x $ using the slope-intercept form of the line:

\[ f(x) = mx + k \]

where $ m $ is the slope, and $ k $ is the y-intercept.

template<class T>
T Rodin::Geometry::Euclidean::Line2D<T>::operator()(const Point2D<T>& p) const constexpr

Parameters
in Point to evaluate
Returns Result of evaluation

Evaluates a point $ (x, y) $ by the following function:

\[ f(x, y) = ax + by - c \]

Example

This method can be used to test whether the specified point lies on the upper or lower half spaces defined by the line. For example,

if (line(p) > 0)
{
 // Point lies in the upper half space
}
else
{
 // Point lies in the lower half space
}

template<class T>
T Rodin::Geometry::Euclidean::Line2D<T>::a() const constexpr

Returns The $ a $ coefficient of the line.

template<class T>
T Rodin::Geometry::Euclidean::Line2D<T>::b() const constexpr

Returns The $ b $ coefficient of the line.

template<class T>
T Rodin::Geometry::Euclidean::Line2D<T>::c() const constexpr

Returns The $ c $ coefficient of the line.

template<class T>
std::optional<T> Rodin::Geometry::Euclidean::Line2D<T>::slope() const constexpr

Returns
std::nullopt If the line is vertical.
T The slope of the line.

Computes the slope of the line.

template<class T>
std::optional<Point2D<T>> Rodin::Geometry::Euclidean::Line2D<T>::intersect(const Line2D<T>& other) const constexpr

Parameters
other in Line considered
Returns
std::nullopt If the lines do not intersect
None If the lines intersect

Computes the intersection point with another line.

If the two lines are given by

\begin{eqnarray*} a_1 x + b_1 y - c_1 &= 0\\ a_2 x + b_2 y - c_2 &= 0 \end{eqnarray*}

then the intersection point (if any) is given by:

\[ (x, y) = \left( \dfrac{c_1 b_2 - b_1 c_2}{a_1 b_2 - a_2 b_1}, \dfrac{a_1 c_2 - a_2 c_1}{a_1 b_2 - a_2 b_1} \right) \]

template<class T>
std::variant<std::nullopt_t, Point2D<T>, std::pair<Point2D<T>, Point2D<T>>> Rodin::Geometry::Euclidean::Line2D<T>::intersect(const Circle<T>& other) const constexpr

Parameters
other in Circle considered
Returns
std::nullopt If no intersection points are found
None If one intersection point is found
std::pair If two intersection points are found
Point2D> If two intersection points are found

Returns the intersection point(s) between the line and the specified circle.

template<class T>
std::optional<LineSegment2D<T>> Rodin::Geometry::Euclidean::Line2D<T>::connect(const Circle<T>& other) const constexpr

Parameters
other in Line to connect.
Returns
std::nullopt If the line touches the circle.
None If there exists a unique line segment between the two.

Computes the line segment where the start and end points are the points closest to each other in the line and circle, respectively.

template<class T>
T Rodin::Geometry::Euclidean::Line2D<T>::distance(const Line2D<T>& other) const constexpr

Parameters
other in Parallel line
Returns The distance between lines.

Computes the distance between parallel lines.