LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::tline< T > Class Template Reference
[Geometry Data Structures]

Type for computations with lines. More...

#include <ltiLine.h>

Inheritance diagram for lti::tline< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 tline ()
 tline (const tpoint< T > &theStart, const tpoint< T > &theEnd)
template<class U >
 tline (const tline< U > &other)
template<class U >
tline< T > & castFrom (const tline< U > &other)
void set (const tpoint< T > &theStart, const tpoint< T > &theEnd)
void setStart (const tpoint< T > &theStart)
void setEnd (const tpoint< T > &theEnd)
void invert ()
const tpoint< T > & getStart () const
const tpoint< T > & getEnd () const
tline< T > & copy (const tline< T > &other)
tline< T > & operator= (const tline< T > &other)
bool operator== (const tline< T > &other) const
bool operator!= (const tline< T > &other) const
Distance computation



distanceTo (const tpoint< T > &c) const
distanceSqr (const tpoint< T > &c) const
distanceSqr (const tpoint< T > &c, tpoint< T > &p) const
distanceToXPol (const tpoint< T > &c) const
distanceSqrXPol (const tpoint< T > &c) const
distanceSqrXPol (const tpoint< T > &c, tpoint< T > &p) const
sqrLength () const
Intersections



bool doesIntersect (const tline< T > &other) const
bool isParallel (const tline< T > &other) const
bool isColinear (const tline< T > &other) const
bool intersect (const trectangle< T > &rect)
bool intersect (const tline< T > &other, const trectangle< T > &rect)
template<class U >
bool getIntersectionPoint (const tline< T > &other, tpoint< U > &p, bool &colinear) const
bool getCommonLine (const tline< T > &other)
bool getCommonLine (const tline< T > &first, const tline< T > &second)
bool doesPointIntersectXPol (const tline< T > &other) const
template<class U >
bool getIntersectionPointXPol (const tline< T > &other, tpoint< U > &p, bool &onThisLine, bool &onOtherLine, bool &colinear) const
template<class U >
bool getIntersectionPointXPol (const tline< T > &other, tpoint< U > &p) const
bool intersectXPol (const trectangle< T > &rect)
bool intersectXPol (const tline< T > &other, const trectangle< T > &rect)
Scaling and Translation operations



template<class U >
tline< T > & scale (const U c)
template<class U >
tline< T > operator* (const U c) const
template<class U >
tline< T > & operator*= (const U c)
template<class U >
tline< T > & divide (const U c)
template<class U >
tline< T > operator/ (const U c) const
template<class U >
tline< T > & operator/= (const U c)
tline< T > & translate (const tpoint< T > &p)
tline< T > & translate (const tline< T > &other, const tpoint< T > &p)
tline< T > & getOrthogonal (double offset)
tline< T > & getOrthogonal (const tline< T > &other, double offset)

Protected Attributes

tpoint< T > start
tpoint< T > end

Detailed Description

template<class T>
class lti::tline< T >

Type for computations with lines.

A line (or more generally a tline<T>) is represented by a start point and an end point.

The type T correspond to the coordinate type used in both points.

This class stores only the two points, and provides some functionality using them. Other operations can be achieved more efficiently if more information about the line, like its slope, is also stored. This is done by some derived classes.


Constructor & Destructor Documentation

template<class T>
lti::tline< T >::tline (  )  [explicit]

default constructor.

Both points are left uninitialized (this can save some time)

template<class T>
lti::tline< T >::tline ( const tpoint< T > &  theStart,
const tpoint< T > &  theEnd 
)

constructor with both points

template<class T>
template<class U >
lti::tline< T >::tline ( const tline< U > &  other  )  [inline]

copy constructor


Member Function Documentation

template<class T>
template<class U >
tline<T>& lti::tline< T >::castFrom ( const tline< U > &  other  )  [inline]

cast operator

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
tline<T>& lti::tline< T >::copy ( const tline< T > &  other  )  [inline]

copy operator

Reimplemented in lti::tfastLine< T >.

Referenced by lti::tline< T >::operator=().

template<class T>
T lti::tline< T >::distanceSqr ( const tpoint< T > &  c,
tpoint< T > &  p 
) const

Calculate minimal square of euclidian distance to the point c.

This method is faster than distanceTo (because it does not calculate the square root).

Parameters:
c point to which the minimal distance is searched.
p point in the line segment with the minimal distance to c.
Returns:
the square of the minimal distance to c
template<class T>
T lti::tline< T >::distanceSqr ( const tpoint< T > &  c  )  const [inline]

Calculate minimal square of euclidian distance to the point c.

This method is faster than distanceTo (because it does not calculate the square root).

Parameters:
c point to which the minimal distance is searched.
Returns:
the square of the minimal distance to c
template<class T>
T lti::tline< T >::distanceSqrXPol ( const tpoint< T > &  c,
tpoint< T > &  p 
) const

Calculate square of distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Parameters:
c point to which the minimal distance is searched.
p point in the extrapolated line segment with the minimal distance to c.

This method is faster than distanceToXPol (because it does not calculate the square root).

See also:
sqrDistanceTo()

Reimplemented in lti::tfastLine< T >.

template<class T>
T lti::tline< T >::distanceSqrXPol ( const tpoint< T > &  c  )  const [inline]

Calculate square of distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Parameters:
c point to which the minimal distance is searched.
Returns:
the square of the minimal distance to c
See also:
sqrDistanceTo()

This method is faster than distanceToXPol (because it does not calculate the square root).

Reimplemented in lti::tfastLine< T >.

template<class T>
T lti::tline< T >::distanceTo ( const tpoint< T > &  c  )  const [inline]

calculate minimal euclidian distance of the line segment to the point c.

This method is slower than the sqrDistanceTo, which avoids the computation of a (in many cases not required) square root.

See also:
sqrDistanceTo() distanceToXPol()
template<class T>
T lti::tline< T >::distanceToXPol ( const tpoint< T > &  c  )  const [inline]

Calculate distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Returns:
the minimal distance to c

Reimplemented in lti::tfastLine< T >.

template<class T>
template<class U >
tline<T>& lti::tline< T >::divide ( const U  c  )  [inline]

divide both points by the given c factor

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

Referenced by lti::tline< T >::operator/=().

template<class T>
bool lti::tline< T >::doesIntersect ( const tline< T > &  other  )  const

Check if this line segment intersects the other given one.

Parameters:
other the other line segment to which an intersection is going to be checked.
Returns:
true if both line segments intersect.
template<class T>
bool lti::tline< T >::doesPointIntersectXPol ( const tline< T > &  other  )  const

Check if this infinitely extrapolated line intersects the other given infinite line at a single finite point.

Parameters:
other the other line segment to which an intersection is going to be checked.
Returns:
true if both inifinite lines intersect at a single finite point.

This method can be overloaded in derived classes and other information to accellerate the computations.

template<class T>
bool lti::tline< T >::getCommonLine ( const tline< T > &  first,
const tline< T > &  second 
) [inline]

Compute the common line segment between the given line segments.

This intersection is only going to be computed if both lines are colinear.

Parameters:
first first line segment.
second second line segment.
Returns:
true if a common line segment exists. It returns false otherwise. If both line segments are parallel and colinear, this method returns true and determines the line segment even if it is inifinitely small, i.e. a point.

The common line segment will be left in this instance.

This method can be overloaded in derived classes and other information to accellerate the computations.

template<class T>
bool lti::tline< T >::getCommonLine ( const tline< T > &  other  ) 

Compute the common line segment between this line segment and the other given one and leave the result here.

This intersection is only going to be computed if both lines are colinear.

Parameters:
other the other line segment to which the intersection is going to be computed.
Returns:
true if an common line segment exists. It returns false otherwise. If both line segments are parallel and colinear, this method returns true and determines the line segment even if it is inifinitely small, i.e. a point.

This method can be overloaded in derived classes and other information to accellerate the computations.

template<class T>
const tpoint<T>& lti::tline< T >::getEnd (  )  const [inline]

return a read only reference to the end point

Referenced by lti::draw< rgbPixel >::line().

template<class T>
template<class U >
bool lti::tline< T >::getIntersectionPoint ( const tline< T > &  other,
tpoint< U > &  p,
bool &  colinear 
) const [inline]

Compute the intersection point of this line segment with the other given one.

Parameters:
other the other line segment to which the intersection point is going to be computed.
p if there is an intersection between both line segments the intersection point will be written here.
colinear this parameter is set to true in case both line segments are parallel and co-linear.
Returns:
true if an unique intersection point exists. It returns false otherwise. If both line segments are parallel and colinear, this method returns true and determines the intersection if the intersection is inifinitely small.

This method can be overloaded in derived classes and other information to accellerate the computations.

References lti::abs(), lti::condRoundCastTo(), lti::tline< T >::end, lti::tline< T >::start, lti::tpoint< T >::x, and lti::tpoint< T >::y.

template<class T>
template<class U >
bool lti::tline< T >::getIntersectionPointXPol ( const tline< T > &  other,
tpoint< U > &  p 
) const [inline]

Compute the intersection point of this infinitely extrapolated line with the other given infinite line.

Parameters:
other the other line segment to which the intersection point is going to be computed.
p if there is an intersection between both line segments or between their respective infinite line extrapolations, the intersection point will be written here.
Returns:
true if an unique intersection point exists. It returns false otherwise.

This method can be overloaded in derived classes and other information to accellerate the computations.

References lti::condRoundCastTo(), lti::tline< T >::end, lti::tline< T >::start, lti::tpoint< T >::x, and lti::tpoint< T >::y.

template<class T>
template<class U >
bool lti::tline< T >::getIntersectionPointXPol ( const tline< T > &  other,
tpoint< U > &  p,
bool &  onThisLine,
bool &  onOtherLine,
bool &  colinear 
) const [inline]

Compute the intersection point of this infinitely extrapolated line with the other given infinite line.

Parameters:
other the other line segment to which the intersection point is going to be computed.
p if there is an intersection between both line segments or between their respective infinite line extrapolations, the intersection point will be written here.
onThisLine if the intersection occurs at a point on the line segment, this parameter will be set to true. Otherwise false.
onOtherLine if the intersection occurs at a point on the other line segment, this parameter will be set to true.
colinear this parameter is set to true in case both line segments are parallel and co-linear.
Returns:
true if an unique intersection point exists. It returns false otherwise. If both line segments are parallel and colinear, this method returns false.

This method can be overloaded in derived classes and other information to accellerate the computations.

References lti::abs(), lti::condRoundCastTo(), lti::tline< T >::end, lti::tline< T >::start, lti::tpoint< T >::x, and lti::tpoint< T >::y.

template<class T>
tline<T>& lti::tline< T >::getOrthogonal ( const tline< T > &  other,
double  offset 
) [inline]

Compute the orthogonal line to the other line and leave the result here.

Parameters:
other the line segment of which the orthogonal line is going to be computed.
offset the offset to the point on the line, where the orthogonal shall start. This parameter is scaled by the length of the line.
Returns:
a reference to this line

This method can be overloaded in derived classes and other information to accellerate the computations.

template<class T>
tline<T>& lti::tline< T >::getOrthogonal ( double  offset  ) 

Compute the orthogonal line and leave the result here.

Parameters:
offset the offset to the point on the line, where the orthogonal shall start. This parameter is scaled by the length of the line.
Returns:
a reference to this line

This method can be overloaded in derived classes and other information to accellerate the computations.

template<class T>
const tpoint<T>& lti::tline< T >::getStart (  )  const [inline]

return a read only reference to the start point

Referenced by lti::draw< rgbPixel >::line().

template<class T>
bool lti::tline< T >::intersect ( const tline< T > &  other,
const trectangle< T > &  rect 
) [inline]

Compute the part of the other line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented in lti::tfastLine< T >.

template<class T>
bool lti::tline< T >::intersect ( const trectangle< T > &  rect  ) 

Compute the part of this line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented in lti::tfastLine< T >.

template<class T>
bool lti::tline< T >::intersectXPol ( const tline< T > &  other,
const trectangle< T > &  rect 
) [inline]

Compute the part of the infinite extrapolated line containing the other line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented in lti::tfastLine< T >.

template<class T>
bool lti::tline< T >::intersectXPol ( const trectangle< T > &  rect  ) 

Compute the part of the infinite extrapolated line containing this line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented in lti::tfastLine< T >.

template<class T>
void lti::tline< T >::invert (  )  [inline]

exchange the start and end points, making the previous end a start point and the previous start the end point.

Reimplemented in lti::tfastLine< T >.

template<class T>
bool lti::tline< T >::isColinear ( const tline< T > &  other  )  const

Check if this line segment is parallel and colinear to the other given one.

Parameters:
other the other line segment to which parallelism is going to be checked.
Returns:
true if both line segments are parallel.
template<class T>
bool lti::tline< T >::isParallel ( const tline< T > &  other  )  const

Check if this line segment is parallel to the other given one.

Parameters:
other the other line segment to which parallelism is going to be checked.
Returns:
true if both line segments are parallel.
template<class T>
bool lti::tline< T >::operator!= ( const tline< T > &  other  )  const [inline]

operator !=

template<class T>
template<class U >
tline<T> lti::tline< T >::operator* ( const U  c  )  const [inline]

create a new line equal this one scaled by the given c factor.

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
template<class U >
tline<T>& lti::tline< T >::operator*= ( const U  c  )  [inline]

scale this line by the given c factor.

Reimplemented in lti::tfastLine< T >.

template<class T>
template<class U >
tline<T> lti::tline< T >::operator/ ( const U  c  )  const [inline]

divide both points by the given c factor

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
template<class U >
tline<T>& lti::tline< T >::operator/= ( const U  c  )  [inline]

divide both points of tline<T> by a given factor

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::divide().

template<class T>
tline<T>& lti::tline< T >::operator= ( const tline< T > &  other  )  [inline]

operator =

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::copy().

template<class T>
bool lti::tline< T >::operator== ( const tline< T > &  other  )  const [inline]

operator ==

template<class T>
template<class U >
tline<T>& lti::tline< T >::scale ( const U  c  )  [inline]

scale this line by the given c factor.

Reimplemented in lti::tfastLine< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
void lti::tline< T >::set ( const tpoint< T > &  theStart,
const tpoint< T > &  theEnd 
) [inline]

general operator to set both points of the line

Reimplemented in lti::tfastLine< T >.

template<class T>
void lti::tline< T >::setEnd ( const tpoint< T > &  theEnd  )  [inline]

set the end point.

Does not compute the slope.

Reimplemented in lti::tfastLine< T >.

template<class T>
void lti::tline< T >::setStart ( const tpoint< T > &  theStart  )  [inline]

set the start point.

Reimplemented in lti::tfastLine< T >.

template<class T>
T lti::tline< T >::sqrLength (  )  const [inline]

square of the length of this line

template<class T>
tline<T>& lti::tline< T >::translate ( const tline< T > &  other,
const tpoint< T > &  p 
) [inline]

add given point to both ends of the other line and leave the result here.

Parameters:
other the other line to be tranlated
p the translation factor
Returns:
a reference to this line
template<class T>
tline<T>& lti::tline< T >::translate ( const tpoint< T > &  p  )  [inline]

add given point to both ends of this line and leave the result here.

Parameters:
p the other line to be added to this one
Returns:
a reference to this line

Reimplemented in lti::tfastLine< T >.


Member Data Documentation

template<class T>
tpoint<T> lti::tline< T >::end [protected]
template<class T>
tpoint<T> lti::tline< T >::start [protected]

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

Generated on Sat Apr 10 15:28:27 2010 for LTI-Lib by Doxygen 1.6.1