53 origin = a; vector = b - a;
58 origin = a; vector = v;
64 inline double lenght()
const{
65 return vector.lenght();
70 return vector.lenght_sq();
82 *ppt = origin + vector*k;
87 return origin + vector*k ;
90 inline double getX(
double k)
const{
return k*vector.x() + origin.x(); }
91 inline double getY(
double k)
const{
return k*vector.y() + origin.y(); }
96 inline double getK(
const laPoint2 &pt )
const{
97 return (
M_ABS(vector.x())>
M_ABS(vector.y()) ) ? getK_atX(pt.x()) : getK_atY(pt.y());
100 inline double getK_atX(
double x)
const{
102 return (x - origin.x()) / vector.x();
105 inline double getK_atY(
double y)
const{
107 return (y - origin.y() ) / vector.y();
124 PROFILE_COL(laPoint2_direction);
129 k = getK_atX( pt.x() );
130 return (
getY(k) > pt.y() ) ? +1 : -1;
134 k = getK_atY( pt.y() );
135 return (
getX(k) > pt.x() ) ? +1 : -1;
152 double dCross1 = vector.cross( ln.
vector );
154 if(
M_ABS(dCross1) < 0.00001)
return M_FALSE;
158 *k_ln = ln.getK(
at(*k) );
186 return v.lenght_sq();
196 #endif //#ifndef M_LINE_H
void draw(class laRenderer *r, laPoint2 &pos)
Draw the line ( primarily for debug purposes )
M_BOOL onSameSide(const laPoint2 &a, const laPoint2 &b) const
Check if two points are on the same side of the line.
void build(const laPoint2 &a, const laPoint2 &b)
Build a line from two end-points.
double lenght_sq() const
Squared root of segment lenght.
int direction(const laPoint2 &pt) const
void build_v(const laPoint2 &a, const laPoint2 &v)
Build a line from an end-point and a vector.
M_BOOL intersection(const laLine2 &ln, double *k, double *k_ln) const
laPoint2 end() const
Get the end-point.
void at(double k, laPoint2 *ppt) const
Get point at 1/k lenght (returns in user-specified pointer)
laPoint2 vector
Vector ( not normalized, so k = [0;1] traces the whole line segment )
double distance(laPoint2 &pt) const
Compute the distance between a point and the line.
laPoint2 normal(int direction=1) const
Get a perpendicular vector of lenght 1 (normal of the line segment)
#define M_ABS(a)
Return abs(a)
double getX(double k) const
Get X at 1/k lenght.
Virtual interface for the Engine graphics renderer.
laPoint2 origin
Point of origin.
static void drawLine2s(laLine2 *arLines, unsigned n, class laRenderer *r, laPoint2 &pos)
Draw many lines ( primarily for debug purposes )
double getY(double k) const
Get Y at 1/k lenght.
double distance_sq(laPoint2 &pt) const
Compute the square of the distance between a point and the line.