CVR-Lib last update 20 Sep 2009

cvr::line< T > Class Template Reference
[Geometry Data Structures]

Type for computations with lines. More...

#include <cvrLine.h>

List of all members.

Public Member Functions

 line ()
 line (const point< T > &theStart, const point< T > &theEnd)
template<class U >
 line (const line< U > &other)
template<class U >
line< T > & castFrom (const line< U > &other)
void set (const point< T > &theStart, const point< T > &theEnd)
void setStart (const point< T > &theStart)
void setEnd (const point< T > &theEnd)
void invert ()
const point< T > & getStart () const
const point< T > & getEnd () const
line< T > & copy (const line< T > &other)
line< T > & operator= (const line< T > &other)
bool operator== (const line< T > &other) const
bool operator!= (const line< T > &other) const
Distance computation
distanceTo (const point< T > &c) const
distanceSqr (const point< T > &c) const
distanceSqr (const point< T > &c, point< T > &p) const
distanceToXPol (const point< T > &c) const
distanceSqrXPol (const point< T > &c) const
distanceSqrXPol (const point< T > &c, point< T > &p) const
sqrLength () const
Intersections
bool doesIntersect (const line< T > &other) const
bool isParallel (const line< T > &other) const
bool isColinear (const line< T > &other) const
bool intersect (const rectangle< T > &rect)
bool intersect (const line< T > &other, const rectangle< T > &rect)
template<class U >
bool getIntersectionPoint (const line< T > &other, point< U > &p, bool &colinear) const
bool getCommonLine (const line< T > &other)
bool getCommonLine (const line< T > &first, const line< T > &second)
bool doesPointIntersectXPol (const line< T > &other) const
template<class U >
bool getIntersectionPointXPol (const line< T > &other, point< U > &p, bool &onThisLine, bool &onOtherLine, bool &colinear) const
template<class U >
bool getIntersectionPointXPol (const line< T > &other, point< U > &p) const
bool intersectXPol (const rectangle< T > &rect)
bool intersectXPol (const line< T > &other, const rectangle< T > &rect)
Scaling and Translation operations
template<class U >
line< T > & scale (const U c)
template<class U >
line< T > operator* (const U c) const
template<class U >
line< T > & operator*= (const U c)
template<class U >
line< T > & divide (const U c)
template<class U >
line< T > operator/ (const U c) const
template<class U >
line< T > & operator/= (const U c)
line< T > & translate (const point< T > &p)
line< T > & translate (const line< T > &other, const point< T > &p)
line< T > & getOrthogonal (double offset)
line< T > & getOrthogonal (const line< T > &other, double offset)

Protected Attributes

point< T > start
point< T > end


Detailed Description

template<class T>
class cvr::line< T >

Type for computations with lines.

A line (or more generally a line<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>
cvr::line< T >::line (  )  [explicit]

default constructor.

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

template<class T>
cvr::line< T >::line ( const point< T > &  theStart,
const point< T > &  theEnd 
)

constructor with both points

template<class T>
template<class U >
cvr::line< T >::line ( const line< U > &  other  )  [inline]

copy constructor


Member Function Documentation

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

cast operator

template<class T>
line<T>& cvr::line< T >::copy ( const line< T > &  other  )  [inline]

copy operator

Referenced by cvr::line< T >::operator=().

template<class T>
T cvr::line< T >::distanceSqr ( const point< T > &  c,
point< 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 cvr::line< T >::distanceSqr ( const point< 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 cvr::line< T >::distanceSqrXPol ( const point< T > &  c,
point< 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()

template<class T>
T cvr::line< T >::distanceSqrXPol ( const point< 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).

template<class T>
T cvr::line< T >::distanceTo ( const point< 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 cvr::line< T >::distanceToXPol ( const point< 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

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

divide both points by the given c factor

template<class T>
bool cvr::line< T >::doesIntersect ( const line< 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 cvr::line< T >::doesPointIntersectXPol ( const line< 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 cvr::line< T >::getCommonLine ( const line< T > &  first,
const line< 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 cvr::line< T >::getCommonLine ( const line< 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 point<T>& cvr::line< T >::getEnd (  )  const [inline]

return a read only reference to the end point

template<class T>
template<class U >
bool cvr::line< T >::getIntersectionPoint ( const line< T > &  other,
point< 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.

template<class T>
template<class U >
bool cvr::line< T >::getIntersectionPointXPol ( const line< T > &  other,
point< 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.

template<class T>
template<class U >
bool cvr::line< T >::getIntersectionPointXPol ( const line< T > &  other,
point< 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.

template<class T>
line<T>& cvr::line< T >::getOrthogonal ( const line< 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>
line<T>& cvr::line< 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 point<T>& cvr::line< T >::getStart (  )  const [inline]

return a read only reference to the start point

template<class T>
bool cvr::line< T >::intersect ( const line< T > &  other,
const rectangle< 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.

template<class T>
bool cvr::line< T >::intersect ( const rectangle< 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.

template<class T>
bool cvr::line< T >::intersectXPol ( const line< T > &  other,
const rectangle< 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.

template<class T>
bool cvr::line< T >::intersectXPol ( const rectangle< 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.

template<class T>
void cvr::line< T >::invert (  )  [inline]

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

template<class T>
bool cvr::line< T >::isColinear ( const line< 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 cvr::line< T >::isParallel ( const line< 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 cvr::line< T >::operator!= ( const line< T > &  other  )  const [inline]

operator !=

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

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

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

scale this line by the given c factor.

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

divide both points by the given c factor

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

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

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

operator =

References cvr::line< T >::copy().

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

operator ==

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

scale this line by the given c factor.

template<class T>
void cvr::line< T >::set ( const point< T > &  theStart,
const point< T > &  theEnd 
) [inline]

general operator to set both points of the line

template<class T>
void cvr::line< T >::setEnd ( const point< T > &  theEnd  )  [inline]

set the end point.

Does not compute the slope.

template<class T>
void cvr::line< T >::setStart ( const point< T > &  theStart  )  [inline]

set the start point.

template<class T>
T cvr::line< T >::sqrLength (  )  const [inline]

square of the length of this line

template<class T>
line<T>& cvr::line< T >::translate ( const line< T > &  other,
const point< 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>
line<T>& cvr::line< T >::translate ( const point< 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


Member Data Documentation

template<class T>
point<T> cvr::line< T >::end [protected]

end point

template<class T>
point<T> cvr::line< T >::start [protected]

start point


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

Generated on Sun Sep 20 22:09:08 2009 for CVR-Lib by Doxygen 1.5.8