latest version v1.9 - last update 10 Apr 2010 |
Type for computations with lines. More...
#include <ltiLine.h>
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 | |
T | distanceTo (const tpoint< T > &c) const |
T | distanceSqr (const tpoint< T > &c) const |
T | distanceSqr (const tpoint< T > &c, tpoint< T > &p) const |
T | distanceToXPol (const tpoint< T > &c) const |
T | distanceSqrXPol (const tpoint< T > &c) const |
T | distanceSqrXPol (const tpoint< T > &c, tpoint< T > &p) const |
T | 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 |
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.
lti::tline< T >::tline | ( | ) | [explicit] |
default constructor.
Both points are left uninitialized (this can save some time)
lti::tline< T >::tline | ( | const tpoint< T > & | theStart, | |
const tpoint< T > & | theEnd | |||
) |
constructor with both points
copy constructor
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.
tline<T>& lti::tline< T >::copy | ( | const tline< T > & | other | ) | [inline] |
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).
c | point to which the minimal distance is searched. | |
p | point in the line segment with the minimal distance to c. |
T lti::tline< T >::distanceSqr | ( | const tpoint< T > & | c | ) | const [inline] |
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.
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).
Reimplemented in lti::tfastLine< 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.
c | point to which the minimal distance is searched. |
This method is faster than distanceToXPol (because it does not calculate the square root).
Reimplemented in lti::tfastLine< 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.
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.
Reimplemented in lti::tfastLine< T >.
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/=().
bool lti::tline< T >::doesIntersect | ( | const tline< T > & | other | ) | const |
Check if this line segment intersects the other given one.
other | the other line segment to which an intersection is going to be checked. |
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.
other | the other line segment to which an intersection is going to be checked. |
This method can be overloaded in derived classes and other information to accellerate the computations.
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.
first | first line segment. | |
second | second line segment. |
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.
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.
other | the other line segment to which the intersection is going to be computed. |
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.
const tpoint<T>& lti::tline< T >::getEnd | ( | ) | const [inline] |
return a read only reference to the end point
Referenced by lti::draw< rgbPixel >::line().
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.
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. |
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.
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.
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. |
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.
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.
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. |
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.
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.
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. |
This method can be overloaded in derived classes and other information to accellerate the computations.
tline<T>& lti::tline< T >::getOrthogonal | ( | double | offset | ) |
Compute the orthogonal line and leave the result here.
offset | the offset to the point on the line, where the orthogonal shall start. This parameter is scaled by the length of the line. |
This method can be overloaded in derived classes and other information to accellerate the computations.
const tpoint<T>& lti::tline< T >::getStart | ( | ) | const [inline] |
return a read only reference to the start point
Referenced by lti::draw< rgbPixel >::line().
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.
Reimplemented in lti::tfastLine< 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.
Reimplemented in lti::tfastLine< 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.
Reimplemented in lti::tfastLine< 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.
Reimplemented in lti::tfastLine< 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 >.
bool lti::tline< T >::isColinear | ( | const tline< T > & | other | ) | const |
Check if this line segment is parallel and colinear to the other given one.
other | the other line segment to which parallelism is going to be checked. |
bool lti::tline< T >::isParallel | ( | const tline< T > & | other | ) | const |
Check if this line segment is parallel to the other given one.
other | the other line segment to which parallelism is going to be checked. |
bool lti::tline< T >::operator!= | ( | const tline< T > & | other | ) | const [inline] |
operator !=
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.
scale this line by the given c factor.
Reimplemented in lti::tfastLine< T >.
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.
divide both points of tline<T> by a given factor
Reimplemented in lti::tfastLine< T >.
References lti::tline< T >::divide().
tline<T>& lti::tline< T >::operator= | ( | const tline< T > & | other | ) | [inline] |
bool lti::tline< T >::operator== | ( | const tline< T > & | other | ) | const [inline] |
operator ==
scale this line by the given c factor.
Reimplemented in lti::tfastLine< T >.
References lti::tline< T >::end, and lti::tline< T >::start.
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 >.
void lti::tline< T >::setEnd | ( | const tpoint< T > & | theEnd | ) | [inline] |
void lti::tline< T >::setStart | ( | const tpoint< T > & | theStart | ) | [inline] |
set the start point.
Reimplemented in lti::tfastLine< T >.
T lti::tline< T >::sqrLength | ( | ) | const [inline] |
square of the length of this line
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.
other | the other line to be tranlated | |
p | the translation factor |
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.
p | the other line to be added to this one |
Reimplemented in lti::tfastLine< T >.
tpoint<T> lti::tline< T >::end [protected] |
end point
Referenced by lti::tline< T >::castFrom(), lti::tline< T >::divide(), lti::tfastLine< T >::divide(), lti::tline< T >::getIntersectionPoint(), lti::tline< T >::getIntersectionPointXPol(), lti::tline< T >::operator*(), lti::tfastLine< T >::operator*(), lti::tline< T >::operator/(), lti::tfastLine< T >::operator/(), lti::tline< T >::scale(), and lti::tfastLine< T >::scale().
tpoint<T> lti::tline< T >::start [protected] |
start point
Referenced by lti::tline< T >::castFrom(), lti::tline< T >::divide(), lti::tfastLine< T >::divide(), lti::tline< T >::getIntersectionPoint(), lti::tline< T >::getIntersectionPointXPol(), lti::tline< T >::operator*(), lti::tfastLine< T >::operator*(), lti::tline< T >::operator/(), lti::tfastLine< T >::operator/(), lti::tline< T >::scale(), and lti::tfastLine< T >::scale().