template<class T>
Line2D class
Represents a two-dimensional line in general form. A line is defined as the set of all points which satisfy the equation:
Constructors, destructors, conversion operators
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 | |
---|---|
a in | The coefficient in the equation |
b in | The coefficient in the equation |
c in | The coefficient in the equation |
Constructs a line from its coefficients.
template<class T>
std::optional<T> Rodin:: Geometry:: Euclidean:: Line2D<T>:: operator()(T x) const constexpr
Parameters | |
---|---|
x in | Number to evaluate |
Returns | Result of evaluation |
Evaluates a number using the slope-intercept form of the line:
where is the slope, and is the y-intercept.
template<class T>
T Rodin:: Geometry:: Euclidean:: Line2D<T>:: operator()(const Point2D<T>& p) const constexpr
Parameters | |
---|---|
p in | Point to evaluate |
Returns | Result of evaluation |
Evaluates a point by the following function:
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 coefficient of the line. |
---|
template<class T>
T Rodin:: Geometry:: Euclidean:: Line2D<T>:: b() const constexpr
Returns | The coefficient of the line. |
---|
template<class T>
T Rodin:: Geometry:: Euclidean:: Line2D<T>:: c() const constexpr
Returns | The 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
then the intersection point (if any) is given by:
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::pairIf 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.