iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::Line< T > Class Template Reference

#include <nrt/Core/Geometry/Line.H>

template<class T>
class nrt::Line< T >

A 2D line segment.

Examples:
tests/test-Geometry.C, and tests/test-UKF.C.

Definition at line 48 of file Line.H.

Public Member Functions

 Line ()
 Default constructor - creates a Line with both ends at (0,0)
 
 Line (Point2D< T > const &p1, Point2D< T > const &p2)
 Construct a Line from the two given points.
 
 Line (T x1, T y1, T x2, T y2)
 Construct a Line from the given x and y coordinates.
 
 Line (Point2D< T > const &center, double const ori, double const len)
 Construct a Line from a center, ori and len.
 
 Line (Line< T > const &other)=default
 Copy constructor.
 
 Line (Line< T > &&other)=default
 Move constructor.
 
template<class U >
 Line (Line< U > const &other)
 Copy-conversion constructor.
 
Line< T > & operator= (Line< T > const &other)=default
 Assignment.
 
Line< T > & operator= (Line< T > &&other)=default
 Move assignment.
 
Point2D< T > p1 () const
 Get the first endpoint.
 
Point2D< T > p2 () const
 Get the second endpoint.
 
Point2D< T > center () const
 Get the center of the line.
 
double length () const
 Get the Euclidian length of this Line segment.
 
double manhattanLength () const
 Get the Manhattan length of this Line segment.
 
double angle () const
 Get the angle of this line (from p1 to p2) in radians. More...
 
template<typename promo >
std::shared_ptr< Point2D
< typename promote< T, promo >
::type > > 
intersect (nrt::Line< T > const &other)
 Find the intersection of this line segment with another. More...
 
template<typename promo >
std::shared_ptr< Point2D
< typename promote< T, promo >
::type > > 
intersectInfinite (nrt::Line< T > const &other)
 Find the intersection between the infinite lines define by this segment and another segment. More...
 
double perpendicularDistanceTo (Point2D< T > const &point) const
 Get the perpendicular distance from this line segment to a point. More...
 
template<typename promo >
std::shared_ptr< nrt::Point2D
< typename nrt::promote< T,
promo >::type > > 
intersect (nrt::Line< T > const &other)
 
template<typename promo >
std::shared_ptr< nrt::Point2D
< typename nrt::promote< T,
promo >::type > > 
intersectInfinite (nrt::Line< T > const &other)
 

Protected Member Functions

template<class Archive >
void serialize (Archive &ar)
 

Friends

class cereal::access
 

Related Functions

(Note that these are not member functions.)

template<class T >
std::ostream & operator<< (std::ostream &out, nrt::Line< T > const &line)
 Human-readable output to a stream: outputs {P1,P2}. More...
 
template<class T >
Line< T > scale (Line< T > const &src, double const factor)
 Return a scaled version of the source object. More...
 
template<class T >
Line< T > rotate (Line< T > const &src, double const angle)
 Return a rotated version of the source object, about its center by a given angle in radians. More...
 
template<class T >
Line< T > rotateAbout (Line< T > const &src, Point2D< T > const &p, double const angle)
 Return a rotated version of the source object, about the given point and by a given angle in radians. More...
 
template<class T >
bool operator== (Line< T > const &lhs, Line< T > const &rhs)
 Operator overload for Line<T> == Line<T> More...
 
template<class T >
bool operator!= (Line< T > const &lhs, Line< T > const &rhs)
 Operator overload for Line<T> != Line<T> More...
 
template<class T >
Line< T > operator+ (Line< T > const &lhs, Point2D< T > const &rhs)
 Operator overload for Line<T> + Point2D<T> More...
 
template<class T >
Line< T > operator+ (Point2D< T > const &lhs, Line< T > const &rhs)
 Operator overload for Point2D<T> + Line<T> More...
 
template<class T >
Line< T > operator- (Line< T > const &lhs, Point2D< T > const &rhs)
 Operator overload for Line<T> - Point2D<T> More...
 
template<class T >
Line< T > operator- (Point2D< T > const &lhs, Line< T > const &rhs)
 Operator overload for Point2D<T> - Line<T> More...
 
template<class T >
Line< T > operator* (Line< T > const &lhs, double const rhs)
 Operator overload for Line<T> * double. More...
 
template<class T >
Line< T > operator* (double const lhs, Line< T > const &rhs)
 Operator overload for double * Line<T> More...
 
template<class T >
Line< T > operator/ (Line< T > const &lhs, double const rhs)
 Operator overload for Line<T> / double. More...
 
template<class T >
Line< T > & operator*= (Line< T > &lhs, double const rhs)
 Operator overload for Line<T> *= double. More...
 
template<class T >
Line< T > & operator/= (Line< T > &lhs, double const rhs)
 Operator overload for Line<T> /= double. More...
 
template<class T >
Line< T > & operator+= (Line< T > &lhs, Point2D< T > const &rhs)
 Operator overload for Line<T> += Point2D<T> More...
 
template<class T >
Line< T > & operator-= (Line< T > &lhs, Point2D< T > const &rhs)
 Operator overload for Line<T> -= Point2D<T> More...
 

Member Function Documentation

template<class T >
double nrt::Line< T >::angle ( ) const
inline

Get the angle of this line (from p1 to p2) in radians.

Note
Remember, because an Image has its origin in the top-left, a line drawn from the center of the screen to the...
  • Left has an angle of 0 radians
  • Top has an angle of pi/2 radians
  • Right has an angle of pi radians
  • Bottom has an angle of -pi/2 radians

Definition at line 97 of file LineImpl.H.

template<class T>
template<typename promo >
std::shared_ptr<Point2D<typename promote<T, promo>::type> > nrt::Line< T >::intersect ( nrt::Line< T > const &  other)

Find the intersection of this line segment with another.

If there is no intersection then the resulting shared pointer will be empty. Returning a shared pointer here leads to natural syntax like:

std::shared_ptr<Point2D<int>> intersection = line1.intersect<void>(line2);
// shared_ptr evaluates to bool and returns false if it is empty
if (intersection)
{
Point2D<int> theIntersectionPoint = *intersection;
// ...
}
Parameters
otherthe other line
Template Parameters
promodefines how the coordinates get promoted over type T internally during our computations. If T is a floating point type, then promo = void is fine, unless you need more precision (e.g., promo is double if T is float). If T is an integer type, you should typically choose float or double for promo, like this:
std::shared_ptr<nrt::Point2D<int> > ii = l1.intersect<void>(l2); // not very precise, may have rounding issues
std::shared_ptr<nrt::Point2D<double> > ii2 = l1.intersect<double>(l2); // very precise
if (ii2)
{
nrt::Point2D<int> ci(*ii2); // convert coordinates back to integer if needed - truncating
nrt::Point2D<int> ci2(ii2->round()); // convert coordinates back to integer if needed - rounding
...
}
template<class T>
template<typename promo >
std::shared_ptr<Point2D<typename promote<T, promo>::type> > nrt::Line< T >::intersectInfinite ( nrt::Line< T > const &  other)

Find the intersection between the infinite lines define by this segment and another segment.

If there is no intersection then the resulting shared pointer will be empty. Returning a shared pointer here leads to natural syntax like:

std::shared_ptr<Point2D<int>> intersection = line1.intersectInfinite<void>(line2);
// shared_ptr evaluates to bool and returns false if it is empty
if (intersection)
{
Point2D<int> theIntersectionPoint = *intersection;
// ...
}
Parameters
otherthe other line
Template Parameters
promodefines how the coordinates get promoted over type T internally during our computations. If T is a floating point type, then promo = void is fine, unless you need more precision (e.g., promo is double if T is float). If T is an integer type, you should typically choose float or double for promo, like this:
std::shared_ptr<nrt::Point2D<int> > ii = l1.intersect<void>(l2); // not very precise, may have rounding issues
std::shared_ptr<nrt::Point2D<double> > ii2 = l1.intersect<double>(l2); // very precise
if (ii2)
{
nrt::Point2D<int> ci(*ii2); // convert coordinates back to integer if needed - truncating
nrt::Point2D<int> ci2(ii2->round()); // convert coordinates back to integer if needed - rounding
...
}

Referenced by nrt::RotatedRectangle< T >::minEnclosingRectangle().

template<class T >
double nrt::Line< T >::perpendicularDistanceTo ( Point2D< T > const &  point) const
inline

Get the perpendicular distance from this line segment to a point.

If the projection of point does not land between the two end points of this line segment, it will be given an infinite distance from the point.

Parameters
pointThe point to check the distance to
Returns
The perpendicular distance to the point, assuming the point projects onto the line segment. If this is not the case, the distance will be infinite

Definition at line 238 of file LineImpl.H.

References nrt::Point< T, 2 >::distanceTo().

Friends And Related Function Documentation

template<class T >
std::ostream & operator<< ( std::ostream &  out,
nrt::Line< T > const &  line 
)
related

Human-readable output to a stream: outputs {P1,P2}.

template<class T >
Line< T > scale ( Line< T > const &  src,
double const  factor 
)
related

Return a scaled version of the source object.

Note
This does not have the same effect as the multiplication or division operators, which scale everything, while here we only scale the object size without scaling its center coordinates.
template<class T >
Line< T > rotate ( Line< T > const &  src,
double const  angle 
)
related

Return a rotated version of the source object, about its center by a given angle in radians.

template<class T >
Line< T > rotateAbout ( Line< T > const &  src,
Point2D< T > const &  p,
double const  angle 
)
related

Return a rotated version of the source object, about the given point and by a given angle in radians.

template<class T >
bool operator== ( Line< T > const &  lhs,
Line< T > const &  rhs 
)
related

Operator overload for Line<T> == Line<T>

template<class T >
bool operator!= ( Line< T > const &  lhs,
Line< T > const &  rhs 
)
related

Operator overload for Line<T> != Line<T>

template<class T >
Line< T > operator+ ( Line< T > const &  lhs,
Point2D< T > const &  rhs 
)
related

Operator overload for Line<T> + Point2D<T>

template<class T >
Line< T > operator+ ( Point2D< T > const &  lhs,
Line< T > const &  rhs 
)
related

Operator overload for Point2D<T> + Line<T>

template<class T >
Line< T > operator- ( Line< T > const &  lhs,
Point2D< T > const &  rhs 
)
related

Operator overload for Line<T> - Point2D<T>

template<class T >
Line< T > operator- ( Point2D< T > const &  lhs,
Line< T > const &  rhs 
)
related

Operator overload for Point2D<T> - Line<T>

template<class T >
Line< T > operator* ( Line< T > const &  lhs,
double const  rhs 
)
related

Operator overload for Line<T> * double.

template<class T >
Line< T > operator* ( double const  lhs,
Line< T > const &  rhs 
)
related

Operator overload for double * Line<T>

template<class T >
Line< T > operator/ ( Line< T > const &  lhs,
double const  rhs 
)
related

Operator overload for Line<T> / double.

template<class T >
Line< T > & operator*= ( Line< T > &  lhs,
double const  rhs 
)
related

Operator overload for Line<T> *= double.

template<class T >
Line< T > & operator/= ( Line< T > &  lhs,
double const  rhs 
)
related

Operator overload for Line<T> /= double.

template<class T >
Line< T > & operator+= ( Line< T > &  lhs,
Point2D< T > const &  rhs 
)
related

Operator overload for Line<T> += Point2D<T>

template<class T >
Line< T > & operator-= ( Line< T > &  lhs,
Point2D< T > const &  rhs 
)
related

Operator overload for Line<T> -= Point2D<T>


The documentation for this class was generated from the following files: