All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Public Member Functions | Friends | List of all members
ignition::math::Line2< T > Class Template Reference

A two dimensional line segment. More...

#include <ignition/math/Line2.hh>

Public Member Functions

 Line2 (const math::Vector2< T > &_ptA, const math::Vector2< T > &_ptB)
 Constructor. More...
 
 Line2 (double _x1, double _y1, double _x2, double _y2)
 Constructor. More...
 
bool Collinear (const math::Vector2< T > &_pt, double _epsilon=1e-6) const
 Check if the given point is collinear with this line. More...
 
bool Collinear (const math::Line2< T > &_line, double _epsilon=1e-6) const
 Check if the given line is collinear with this line. More...
 
double CrossProduct (const Line2< T > &_line) const
 Return the cross product of this line and the given line. More...
 
double CrossProduct (const Vector2< T > &_pt) const
 Return the cross product of this line and the given point. More...
 
bool Intersect (const Line2< T > &_line, double _epsilon=1e-6) const
 Check if this line intersects the given line segment. More...
 
bool Intersect (const Line2< T > &_line, math::Vector2< T > &_pt, double _epsilon=1e-6) const
 Check if this line intersects the given line segment. More...
 
Length () const
 Get the length of the line. More...
 
bool OnSegment (const math::Vector2< T > &_pt, double _epsilon=1e-6) const
 Return whether the given point is on this line segment. More...
 
bool operator!= (const Line2< T > &_line) const
 Inequality operator. More...
 
bool operator== (const Line2< T > &_line) const
 Equality operator. More...
 
math::Vector2< T > operator[] (size_t _index) const
 Get the start or end point. More...
 
bool Parallel (const math::Line2< T > &_line, double _epsilon=1e-6) const
 Check if the given line is parallel with this line. More...
 
void Set (const math::Vector2< T > &_ptA, const math::Vector2< T > &_ptB)
 Set the start and end point of the line segment. More...
 
void Set (double _x1, double _y1, double _x2, double _y2)
 Set the start and end point of the line segment. More...
 
double Slope () const
 Get the slope of the line. More...
 
bool Within (const math::Vector2< T > &_pt, double _epsilon=1e-6) const
 Check if the given point is between the start and end points of the line segment. More...
 

Friends

std::ostream & operator<< (std::ostream &_out, const Line2< T > &_line)
 Stream extraction operator. More...
 

Detailed Description

template<typename T>
class ignition::math::Line2< T >

A two dimensional line segment.

The line is defined by a start and end point.

Constructor & Destructor Documentation

template<typename T>
ignition::math::Line2< T >::Line2 ( const math::Vector2< T > &  _ptA,
const math::Vector2< T > &  _ptB 
)
inline

Constructor.

Parameters
[in]_ptAStart point of the line segment
[in]_ptBEnd point of the line segment

References ignition::math::Line2< T >::Set().

template<typename T>
ignition::math::Line2< T >::Line2 ( double  _x1,
double  _y1,
double  _x2,
double  _y2 
)
inline

Constructor.

Parameters
[in]_x1X coordinate of the start point.
[in]_y1Y coordinate of the start point.
[in]_x2X coordinate of the end point.
[in]_y2Y coordinate of the end point.

References ignition::math::Line2< T >::Set().

Member Function Documentation

template<typename T>
bool ignition::math::Line2< T >::Collinear ( const math::Vector2< T > &  _pt,
double  _epsilon = 1e-6 
) const
inline

Check if the given point is collinear with this line.

Parameters
[in]_ptThe point to check.
[in]_epsilonThe error bounds within which the collinear check will return true.
Returns
Return true if the point is collinear with this line, false otherwise.

References ignition::math::Line2< T >::CrossProduct(), and ignition::math::equal().

Referenced by ignition::math::Line2< T >::OnSegment().

template<typename T>
bool ignition::math::Line2< T >::Collinear ( const math::Line2< T > &  _line,
double  _epsilon = 1e-6 
) const
inline

Check if the given line is collinear with this line.

This is the AND of Parallel and Intersect.

Parameters
[in]_lineThe line to check.
[in]_epsilonThe error bounds within which the collinear check will return true.
Returns
Return true if the line is collinear with this line, false otherwise.

References ignition::math::Line2< T >::Intersect(), and ignition::math::Line2< T >::Parallel().

template<typename T>
double ignition::math::Line2< T >::CrossProduct ( const Line2< T > &  _line) const
inline

Return the cross product of this line and the given line.

Give 'a' as this line and 'b' as given line, the equation is: (a.start.x - a.end.x) * (b.start.y - b.end.y) - (a.start.y - a.end.y) * (b.start.x - b.end.x)

Parameters
[in]_lineLine for the cross product computation.
Returns
Return the cross product of this line and the given line.

Referenced by ignition::math::Line2< T >::Collinear(), ignition::math::Line2< T >::Intersect(), and ignition::math::Line2< T >::Parallel().

template<typename T>
double ignition::math::Line2< T >::CrossProduct ( const Vector2< T > &  _pt) const
inline

Return the cross product of this line and the given point.

Given 'a' and 'b' as the start and end points, the equation is:

Parameters
[in]_ptPoint for the cross product computation.
Returns
Return the cross product of this line and the given point.

References ignition::math::Vector2< T >::X(), and ignition::math::Vector2< T >::Y().

template<typename T>
bool ignition::math::Line2< T >::Intersect ( const Line2< T > &  _line,
double  _epsilon = 1e-6 
) const
inline

Check if this line intersects the given line segment.

Parameters
[in]_lineThe line to check for intersection.
[in]_epsilonThe error bounds within which the intersection check will return true.
Returns
True if an intersection was found.

Referenced by ignition::math::Line2< T >::Collinear(), and ignition::math::Triangle< T >::Intersects().

template<typename T>
bool ignition::math::Line2< T >::Intersect ( const Line2< T > &  _line,
math::Vector2< T > &  _pt,
double  _epsilon = 1e-6 
) const
inline

Check if this line intersects the given line segment.

The point of intersection is returned in the _result parameter.

Parameters
[in]_lineThe line to check for intersection.
[out]_ptThe point of intersection. This value is only valid if the return value is true.
[in]_epsilonThe error bounds within which the intersection check will return true.
Returns
True if an intersection was found.

References ignition::math::Line2< T >::CrossProduct(), ignition::math::equal(), ignition::math::max(), ignition::math::min(), ignition::math::Line2< T >::Within(), ignition::math::Vector2< T >::X(), and ignition::math::Vector2< T >::Y().

template<typename T>
T ignition::math::Line2< T >::Length ( ) const
inline

Get the length of the line.

Returns
The length of the line.
template<typename T>
bool ignition::math::Line2< T >::OnSegment ( const math::Vector2< T > &  _pt,
double  _epsilon = 1e-6 
) const
inline

Return whether the given point is on this line segment.

Parameters
[in]_ptPoint to check.
[in]_epsilonThe error bounds within which the OnSegment check will return true.
Returns
True if the point is on the segement.

References ignition::math::Line2< T >::Collinear(), and ignition::math::Line2< T >::Within().

template<typename T>
bool ignition::math::Line2< T >::operator!= ( const Line2< T > &  _line) const
inline

Inequality operator.

Parameters
[in]_lineLine to compare for inequality.
Returns
True if the given line is not to this line
template<typename T>
bool ignition::math::Line2< T >::operator== ( const Line2< T > &  _line) const
inline

Equality operator.

Parameters
[in]_lineLine to compare for equality.
Returns
True if the given line is equal to this line
template<typename T>
math::Vector2<T> ignition::math::Line2< T >::operator[] ( size_t  _index) const
inline

Get the start or end point.

Parameters
[in]_index0 = start point, 1 = end point.
Exceptions
IndexExceptionif _index is > 1.
template<typename T>
bool ignition::math::Line2< T >::Parallel ( const math::Line2< T > &  _line,
double  _epsilon = 1e-6 
) const
inline

Check if the given line is parallel with this line.

Parameters
[in]_lineThe line to check.
[in]_epsilonThe error bounds within which the parallel check will return true.
Returns
Return true if the line is parallel with this line, false otherwise. Return true if either line is a point (line with zero length).

References ignition::math::Line2< T >::CrossProduct(), and ignition::math::equal().

Referenced by ignition::math::Line2< T >::Collinear().

template<typename T>
void ignition::math::Line2< T >::Set ( const math::Vector2< T > &  _ptA,
const math::Vector2< T > &  _ptB 
)
inline

Set the start and end point of the line segment.

Parameters
[in]_ptAStart point of the line segment
[in]_ptBEnd point of the line segment

Referenced by ignition::math::Line2< T >::Line2().

template<typename T>
void ignition::math::Line2< T >::Set ( double  _x1,
double  _y1,
double  _x2,
double  _y2 
)
inline

Set the start and end point of the line segment.

Parameters
[in]_x1X coordinate of the start point.
[in]_y1Y coordinate of the start point.
[in]_x2X coordinate of the end point.
[in]_y2Y coordinate of the end point.
template<typename T>
double ignition::math::Line2< T >::Slope ( ) const
inline

Get the slope of the line.

Returns
The slope of the line, NAN_D if the line is vertical.

References ignition::math::equal(), and ignition::math::NAN_D.

template<typename T>
bool ignition::math::Line2< T >::Within ( const math::Vector2< T > &  _pt,
double  _epsilon = 1e-6 
) const
inline

Check if the given point is between the start and end points of the line segment.

This does not imply that the point is on the segment.

Parameters
[in]_ptPoint to check.
[in]_epsilonThe error bounds within which the within check will return true.
Returns
True if the point is on the segement.

References ignition::math::max(), ignition::math::min(), ignition::math::Vector2< T >::X(), and ignition::math::Vector2< T >::Y().

Referenced by ignition::math::Line2< T >::Intersect(), and ignition::math::Line2< T >::OnSegment().

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  _out,
const Line2< T > &  _line 
)
friend

Stream extraction operator.

Parameters
[in]_outoutput stream
[in]_ptLine2 to output
Returns
The stream
Exceptions
N/A.

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