last update 20 Sep 2009 |
#include <cvrLine.h>
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 | |
T | distanceTo (const point< T > &c) const |
T | distanceSqr (const point< T > &c) const |
T | distanceSqr (const point< T > &c, point< T > &p) const |
T | distanceToXPol (const point< T > &c) const |
T | distanceSqrXPol (const point< T > &c) const |
T | distanceSqrXPol (const point< T > &c, point< T > &p) const |
T | 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 |
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.
default constructor.
Both points are left uninitialized (this can save some time)
constructor with both points
copy constructor
line<T>& cvr::line< T >::castFrom | ( | const line< U > & | other | ) | [inline] |
cast operator
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. |
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. |
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. |
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.
divide both points by the given c factor
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. |
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.
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.
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. |
return a read only reference to the end point
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.
This method can be overloaded in derived classes and other information to accellerate the computations.
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.
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.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.
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. |
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.
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. |
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. |
return a read only reference to the start point
bool cvr::line< T >::intersect | ( | const line< T > & | other, | |
const rectangle< T > & | rect | |||
) | [inline] |
bool cvr::line< T >::intersectXPol | ( | const line< T > & | other, | |
const rectangle< T > & | rect | |||
) | [inline] |
void cvr::line< T >::invert | ( | ) | [inline] |
operator !=
create a new line equal this one scaled by the given c factor.
scale this line by the given c factor.
divide both points by the given c factor
divide both points of line<T> by a given factor
operator ==
scale this line by the given c factor.
void cvr::line< T >::set | ( | const point< T > & | theStart, | |
const point< T > & | theEnd | |||
) | [inline] |
general operator to set both points of the line
set the end point.
Does not compute the slope.
set the start point.