#include <primitives.h>
template<typename T>
Line2d_ class
Represents a line/segment in 2d Euclidean space.
Contents
Public types
Constructors, destructors, conversion operators
Public functions
-
auto Reversed() const -> Line2d_
- Returns a line with flipped direction vector.
-
auto LeftToRight() const -> Line2d_
- Returns a new line, where from/to are sorted by ascending x-coordinates (left-to-right). If the line was vertical, the points will be sorted by ascending y-coordinates.
-
auto From() const -> const vec_
type& - For a segment, this returns the start point. For a line, it's simply one of the given points to construct the line in the first place.
-
void SetFrom(const vec_
type& from) - Sets the first reference point (starting point of a line segment; or any point on a line).
-
auto To() const -> const vec_
type& - For a segment, this returns the end point. For a line, it's simply one of the given points to construct the line in the first place.
-
void SetTo(const vec_
type& to) - Sets the second reference point (end point of a line segment; or any point on a line).
- auto Length() const -> double
- Returns the length from the start to the end point. As such, it's only meaningful for a line segment.
-
auto Direction() const -> vec_
type - Returns the non-normalized direction vector from the start point to the end point.
-
auto UnitDirection() const -> vec_
type - Returns the unit direction vector from the start point to the end point.
-
auto MidPoint() const -> vec_
type - Returns the point halfway between from and to.
- auto IsValid() const -> bool
- Returns true if the line object is valid, i.e. start and end points are not the same.
-
auto AngleRad(const vec_
type& v) const -> double - Returns the angle between the line and the given directional vector. The angle will be between 0 and Pi.
-
auto AngleDeg(const vec_
type& v) const -> double - Returns the angle between the line and the given directional vector. The angle will be between 0 and 180 degrees.
-
auto AngleRad(const Line2d_
& other) const -> double - Returns the angle between the direction vectors of the lines.
-
auto AngleDeg(const Line2d_
& other) const -> double - Returns the angle between the direction vectors of the lines.
-
auto HomogeneousForm() const -> vec3_
type - Returns the line in homogeneous coordinates.
-
auto PointAtOffset(double offset_factor) const -> vec_
type - Returns a point between the start and end point.
-
auto ClosestPointOnLine(const vec_
type& point) const -> vec_ type - Returns the closest point on the line, i.e. the projection of the given point onto this line.
-
auto ClosestPointOnSegment(const vec_
type& point) const -> vec_ type - Returns the point on this line segment(!) which is closest to the given point.
-
auto DistancePointToLine(const vec_
type& point) const -> double - Returns the minimum distance between the point and this line.
-
auto DistancePointToSegment(const vec_
type& point) const -> double - Returns the minimum distance between the point and this segment.
-
auto IsCollinear(const Line2d_
& other) const -> bool - Returns true if the two lines are collinear.
-
auto IsParallel(const Line2d_
& other) const -> bool - Returns true if the two lines are parallel.
-
auto IsPointLeftOfLine(const vec_
type& point, bool* is_on_line = nullptr) const -> bool - Returns true if the point is left of this line as specified by pt_from_ --> pt_to_.
-
auto IntersectionLineLine(const Line2d_
& other, vec_ type* intersection_point = nullptr) const -> bool - Returns true if this line intersects the other line and optionally sets the
intersection_point
. -
auto IntersectionLineLineSegment(const Line2d_
& segment, vec_ type* intersection_point = nullptr) const -> bool - Returns true if this line(!) intersects the other line segment(!) and optionally sets the
intersection_point
. -
auto IntersectionLineSegmentLineSegment(const Line2d_
& segment, vec_ type* intersection_point = nullptr) const -> bool - Returns true if this line segment(!) intersects the other line segment(!) and optionally sets the
intersection_point
. -
auto IntersectionLineCircle(const Circle_
<T>& circle, vec_ type* intersection1 = nullptr, vec_ type* intersection2 = nullptr) const -> int - Returns the number of intersections (0, 1, or 2) of this line and the circle. Optionally sets the intersection points.
-
auto IntersectionLineSegmentCircle(const Circle_
<T>& circle, vec_ type* intersection1 = nullptr, vec_ type* intersection2 = nullptr) const -> int - Returns the number of intersections (0, 1, or 2) of this line segment(!) and the circle. Optionally sets the intersection points.
-
auto ClipLineByRectangle(const vec_
type& top_left, const vec_ type& size) const -> Line2d_ <T> - Clips this line(!) such that only the part within the rectangle remains, check via
IsValid()
afterwards. -
auto ClipLineSegmentByRectangle(const vec_
type& top_left, const vec_ type& size) const -> Line2d_ <T> - Clips this line segment(!) such that only the part within the rectangle remains, check via
IsValid()
afterwards. -
auto TiltRad(double angle_rad) const -> Line2d_
<T> -
auto TiltDeg(double angle_deg) const -> Line2d_
<T> - Tilts the line/segment, i.e. rotates the end point around the start point.
Friends
-
auto operator<<(std::ostream& stream,
const Line2d_
& line) -> std::ostream& - Overloaded output stream operator.
Function documentation
template<typename T>
vec3_ type werkzeugkiste:: geometry:: Line2d_<T>:: HomogeneousForm() const
Returns the line in homogeneous coordinates.
Returns | A 3-element vector representing the line in P^2, i.e. the projective 2-space. |
---|
For more details on lines in projective space, refer to Bob Fisher's CVonline <http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_
__, or Stan Birchfield's notes <http:/
__.
template<typename T>
vec_ type werkzeugkiste:: geometry:: Line2d_<T>:: PointAtOffset(double offset_factor) const
Returns a point between the start and end point.
Parameters | |
---|---|
offset_factor | Factor of the distance between start and end point. |
Returns | The point which is offset * Direction() units away from the line's starting point, i.e. offset == 0 is the starting point, offset == 1 is the end point. |
template<typename T>
bool werkzeugkiste:: geometry:: Line2d_<T>:: IsParallel(const Line2d_ & other) const
Returns true if the two lines are parallel.
Parameters | |
---|---|
other | The second line. |
template<typename T>
bool werkzeugkiste:: geometry:: Line2d_<T>:: IsPointLeftOfLine(const vec_ type& point,
bool* is_on_line = nullptr) const
Returns true if the point is left of this line as specified by pt_from_ --> pt_to_.
If you need to distinguish left-of vs. exactly on the line, pass a valid pointer is_on_line
.