Library of Assembled Shared Sources
|
2D Line More...
#include <line_2d.h>
Public Member Functions | |
Side | classify (const TPoint &iPoint) const |
Return on what side a point is located. | |
const TValue | signedDistance (const TPoint &iPoint) const |
Return signed distance of point to line. | |
const TValue | squaredDistance (const TPoint &iPoint) const |
Return signed distance of point to line. | |
Side | classify (const TPoint &iPoint, TParam iRelativeTolerance) const |
Return on what side a point is located. | |
const TValue | signedDistance (const TPoint &iPoint, TParam iRelativeTolerance) const |
Return signed distance of point to line. | |
const TValue | squaredDistance (const TPoint &iPoint, TParam iRelativeTolerance) const |
Return signed distance of point to line. | |
const TPoint | support () const |
return generated support point. | |
const TVector | direction () const |
return generated direction vector. | |
const TValue | equation (const TPoint &iPoint) const |
Return value of point in equation. | |
const TValue | equation (const TPoint &iPoint, TParam iRelativeTolerance) const |
Return value of point in equation, snapped to zero by iRelativeTolerance. | |
const TVector | reject (const TPoint &iPoint) const |
return the vector that, if added to the PROJECTION of iPoint, you get iPoint again. | |
const TVector | reject (const TVector &iVector) const |
return the part of iVector that is orthogonal to the line. | |
const TPoint | project (const TPoint &iPoint) const |
project a point orthogonally onto the line | |
const TVector | project (const TVector &iVector) const |
project a vector orthogonally onto the line | |
const TPoint | reflect (const TPoint &iPoint) const |
reflect a point orthogonally into the line. | |
const TVector | reflect (const TVector &iVector) const |
reflect a vector orthogonally into the line | |
const TPoint | point (TParam iT) const |
return point by filling in parameter in generated parametric equation | |
const TValue | t (const TPoint &iPoint) const |
return parameter along generated paremetric equation. | |
bool | isValid () const |
return true if line is a valid line (no normal or direction vectors that are zero). | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename T, class EP, class NP> | |
T | distance (const Point2D< T > &iA, const Line2D< T, EP, NP > &iB) |
absolute distance between point and line. | |
template<typename T, class EPa, class NPa, class EPb, class NPb> | |
T | distance (const Line2D< T, EPa, NPa > &iA, const Line2D< T, EPb, NPb > &iB) |
absolute distance between two lines | |
template<typename T, class EPa, class NPa, class EPb, class NPb> | |
Result | intersect (const Line2D< T, EPa, NPa > &iA, const Line2D< T, EPb, NPb > &iB, T &oTa, T &oTb) |
intersection of two lines | |
template<typename T, class EPa, class NPa, class EPb, class NPb> | |
Result | intersect (const Line2D< T, EPa, NPa > &iA, const Line2D< T, EPb, NPb > &iB, Point2D< T > &oPoint) |
intersection of two lines | |
template<typename T, class PPa, class PPb> | |
Result | intersect (const LineSegment2D< T, PPa > &a, const LineSegment2D< T, PPb > &b, Point2D< T > &point) |
intersection of two line segments | |
2D Line
I assume if you look to this class, you'll wonder ... "where the heck did all the code go?" Hah, I'll tell ya. There is more than one possible model to represent a line. We can use a cartesian equation N.P+S=0
, or we can use a parametric equation P=S+t*U
. This class lets you choose what implementation you want: a pure cartesian model, a pure parametric model, or a model that combines both. This is done by moving all code to implemenations impl::Line2DCartesian, impl::Line2DParametric or impl::Line2DCombined. Line2D will inherit its implementation of the model you've choosen. You can select the one you want by specifying the template parameter EquationPolicy. You can either use Cartesian (which is the default), Parametric or Combined. Each of them will model the line differently. They all provide the same interface, but might have different results. They might have different memory footprints, different performances, and are optimized for different purposes. Cartesian will select an implementation that only uses the cartesian equation and will be the smallest and the fastest for most purposes (that's why it is the default :). But sometimes, you might more like the Parametric model, because it has better support for direction vectors, but it'll have to calculate the normal on the spot if you need it. Combined is the workhorse for heavy duties and implements both..
Anyway, let me give you some general info on this whole Line2D thing. Though there are three different implentations, they all have the same interface. We'll explore them by this common interface:
TSelf:
the type of this TImpl:
type of implemantion, can be impl::Line2DCartesian, impl::Line2DParametric or impl::Line2DCombined.TNormalizingPolicy:
the type you've used as NormalizingPolicy.TPoint:
type of a afine point in space.TVector:
type of a vector in space.TValue:
same as util::CallTraits<T>::TValue.TParam:
same as util::CallTraits<T>::TParam.TReference:
same as util::CallTraits<T>::TReference.TConstReference:
same as util::CallTraits<T>::TConstReference.TNumTraits:
same as num::NumTraits<T>.After construction, all vectors are normalized depending on the NormalizingPolicy you've choosen as template argument. if the normal vector N is scaled, then d is scaled as well, so it still represents the same line.
Now, we have a series of accessors that give you access to the internal data of the line, including support point, direction vectors, normal vector, ... Only Line2DCombined will be able to pull these directly from its internals, but the others don't have all data aboard, so they have to generate them. Be carefull, because it's not always what you suspect.
support()
. If you've created the line by a direction vector ot two points (which leads to the direction vector), then models Line2DParametric and Line2DCombined will give you back these originals (for Unnormalized lines only! but in case of Normalized lines, they still correspond with the original directions). Line2DCartesian has to regenerate them, but it will result in the same direction vector as the others.So far the accessors. let's get to cooler stuff. For most of this stuff, we need the cartesian equation. Line2DCartesian and Line2DCombined have it on board, but Line2DParametric will have to generate it each call. Keep that in mind!
signedDistances()
as described below. Again you might have a performance hit for the Line2DParametric model because of the need of the cartesian equation.classify()
). The real (absolute) distances is simply the absolute value of the result. For Normalized lines signedDistances()
will be equal to equation()
. But for Unnormalized lines signedDistances still divides through the normal's length Again performance hit for Line2DParametric because of the need of the cartesian equation.reject
(iPoint-S), see below). But more descriptive might be: it is the vector you have to add to the projection of this point on the line (given by project(iPoint)
, see below), to get back iPoint: iPoint==project(iPoint)+reject(iPoint)
. Again performance hit for Line2DParametric because of the cartesian equation.iPoint==project(iPoint)+reject(iPoint)
. Again performance hit for Line2DParametric because of the cartesian equation.iVector==project(iVector)+reject(iVector)
. Again performance hit for Line2DParametric because of the cartesian equation.reflect(iPoint)==project(iPoint)-reject(iPoint)
. Again performance hit for Line2DParametric because of the cartesian equation.reflect(iVector)==project(iVector)-reject(iVector)
. Again performance hit for Line2DParametric because of the cartesian equation.So far functions for the cartesian boys. Now some stuff for parametric fellows. It's about how we can get a point of the line if we now its parametr t, and how we can find @t if we know the point on the line.
P=S+iT*U
. In case of Line2DCartesian, we have the same remarks as for direction(): not only we have a performance hit, we probably also have to deal with totally different direction vectors than the ones we have put in the constructor.iPoint==S+t*U
. In theory, if you put this back in point()
, you should end up with the projection of iPoint: point(t(iPoint))==project(iPoint)
? Well, this is not totally true. In practice, numerical imprecisions will probably give you a slightly different result. You'll be very close, but the last bits will differ enough to make the them inequal. But with some epsilons, you'll be alright.N=-N
and d=-d
. Of the parametric equation, direction vector U is flipped: U=-U
.There are some free functions listed below: distances and intersections. They are common for all lines and can handle mixed equation policies (two lines with different equation policies).
const Line2D< T, EP, NP >::TValue lass::prim::Line2D< T, EP, NP >::signedDistance | ( | const TPoint & | iPoint | ) | const |
Return signed distance of point to line.
negative value means point is in the back.
Definition at line 118 of file line_2d.inl.
References lass::prim::impl::Line2DCartesian< T, NormalizingPolicy >::equation(), and signedDistance().
Referenced by distance(), distance(), signedDistance(), signedDistance(), squaredDistance(), and squaredDistance().
const Line2D< T, EP, NP >::TValue lass::prim::Line2D< T, EP, NP >::squaredDistance | ( | const TPoint & | iPoint | ) | const |
Return signed distance of point to line.
negative value means point is in the back.
Definition at line 130 of file line_2d.inl.
References signedDistance(), lass::num::sqr(), and squaredDistance().
Referenced by squaredDistance(), and squaredDistance().
const Line2D< T, EP, NP >::TValue lass::prim::Line2D< T, EP, NP >::signedDistance | ( | const TPoint & | iPoint, |
TParam | iRelativeTolerance ) const |
Return signed distance of point to line.
negative value means point is in the back.
Definition at line 153 of file line_2d.inl.
References lass::prim::impl::Line2DCartesian< T, NormalizingPolicy >::equation(), and signedDistance().
const Line2D< T, EP, NP >::TValue lass::prim::Line2D< T, EP, NP >::squaredDistance | ( | const TPoint & | iPoint, |
TParam | iRelativeTolerance ) const |
Return signed distance of point to line.
negative value means point is in the back.
Definition at line 165 of file line_2d.inl.
References signedDistance(), lass::num::sqr(), and squaredDistance().
|
inherited |
return generated support point.
|
inherited |
|
inherited |
return the vector that, if added to the PROJECTION of iPoint, you get iPoint again.
iPoint == (almost) project(iPoint) + reject(iPoint)
|
inherited |
return the part of iVector that is orthogonal to the line.
it's the vector that, if added to the PROJECTION of iVector, you get iVector again. iVector == (almost) project(iVector) + reject(iVector).
|
inherited |
return the vector that, if added to the PROJECTION of iPoint, you get iPoint again.
iPoint == (almost) project(iPoint) + reject(iPoint)
Definition at line 98 of file line_2d_cartesian.inl.
|
inherited |
return the part of iVector that is orthogonal to the line.
it's the vector that, if added to the PROJECTION of iVector, you get iVector again. iVector == (almost) project(iVector) + reject(iVector).
Definition at line 99 of file line_2d_cartesian.inl.
|
absolute distance between point and line.
iA | point |
iB | line |
Definition at line 189 of file line_2d.inl.
|
absolute distance between two lines
iA | line A |
iB | line B |
Definition at line 203 of file line_2d.inl.
|
intersection of two lines
iA | line A |
iB | line B |
oTa | parameter of intersection point on line A |
oTb | parameter of intersection point on line B |
Definition at line 235 of file line_2d.inl.
|
intersection of two lines
iA | line A |
iB | line B |
oPoint | intersection point |
Definition at line 285 of file line_2d.inl.
|
intersection of two line segments
a | [in] line segment A |
b | [in] line segment B |
point | [out] intersection point |
Definition at line 276 of file line_segment_2d.inl.