JNR
laLine2 Class Reference

2D line segment More...

#include <laLine2.h>

Public Member Functions

laPoint2 normal (int direction=1) const
 Get a perpendicular vector of lenght 1 (normal of the line segment)
 
int direction (const laPoint2 &pt) const
 
M_BOOL onSameSide (const laPoint2 &a, const laPoint2 &b) const
 Check if two points are on the same side of the line.
 
M_BOOL intersection (const laLine2 &ln, double *k, double *k_ln) const
 
double distance (laPoint2 &pt) const
 Compute the distance between a point and the line.
 
double distance_sq (laPoint2 &pt) const
 Compute the square of the distance between a point and the line.
 
void draw (class laRenderer *r, laPoint2 &pos)
 Draw the line ( primarily for debug purposes )
 
Line constructors and initialization methods
 laLine2 (void)
 
 laLine2 (const laPoint2 &a, const laPoint2 &b)
 
void build (const laPoint2 &a, const laPoint2 &b)
 Build a line from two end-points.
 
void build_v (const laPoint2 &a, const laPoint2 &v)
 Build a line from an end-point and a vector.
 
Lenght of the segment
double lenght () const
 
double lenght_sq () const
 Squared root of segment lenght.
 
Getting points at different positions on the line
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) More...
 
const laPoint2 at (double k) const
 
double getX (double k) const
 Get X at 1/k lenght.
 
double getY (double k) const
 Get Y at 1/k lenght.
 
Getting the parameter k at specified XY coordinates
double getK (const laPoint2 &pt) const
 
double getK_atX (double x) const
 
double getK_atY (double y) const
 

Static Public Member Functions

static void drawLine2s (laLine2 *arLines, unsigned n, class laRenderer *r, laPoint2 &pos)
 Draw many lines ( primarily for debug purposes )
 

Public Attributes

laPoint2 origin
 Point of origin.
 
laPoint2 vector
 Vector ( not normalized, so k = [0;1] traces the whole line segment )
 

Detailed Description

2D line segment

Author
Atanas Laskov

Definition at line 40 of file laLine2.h.

Member Function Documentation

void laLine2::at ( double  k,
laPoint2 ppt 
) const
inline

Get point at 1/k lenght (returns in user-specified pointer)

Get point at 1/k lenght (retruns a new object)

Definition at line 81 of file laLine2.h.

Referenced by distance(), distance_sq(), and intersection().

int laLine2::direction ( const laPoint2 pt) const
inline

Get {+1; -1} depending on the side of the line where a point resides. NOTE: This can be used to reason about the relative position of two points

Definition at line 123 of file laLine2.h.

Referenced by normal(), and onSameSide().

123  {
124  PROFILE_COL(laPoint2_direction);
125  double k;// = getK(pt.x());
126 
127  if( M_ABS( vector.x() )>M_ABS( vector.y() ) )
128  {
129  k = getK_atX( pt.x() );
130  return ( getY(k) > pt.y() ) ? +1 : -1;
131  }
132  else
133  {
134  k = getK_atY( pt.y() );
135  return ( getX(k) > pt.x() ) ? +1 : -1;
136  }
137  }
laPoint2 vector
Vector ( not normalized, so k = [0;1] traces the whole line segment )
Definition: laLine2.h:44
#define M_ABS(a)
Return abs(a)
double getX(double k) const
Get X at 1/k lenght.
Definition: laLine2.h:90
double getY(double k) const
Get Y at 1/k lenght.
Definition: laLine2.h:91
M_BOOL laLine2::intersection ( const laLine2 ln,
double *  k,
double *  k_ln 
) const
inline

Find the point of intersection with another line segment; If the vectors are parallel, returns false; Otherwise returns parameters k and k_ln, corresponding to positions along the two line segments.

Definition at line 149 of file laLine2.h.

Referenced by distance(), and distance_sq().

149  {
150  //PROFILE_COL(laLine2_intersection);
151  //ASSERT(k && k_ln, "Nil k or k_ln recepient ptr");
152  double dCross1 = vector.cross( ln.vector );
153 
154  if( M_ABS(dCross1) < 0.00001) return M_FALSE; // parallel vectors?
155 
156  // ln.origin.cross( ln.vector ) - origin.cross( ln.vec )
157  *k = ( (ln.origin.x() - origin.x())*ln.vector.y() + (origin.y() - ln.origin.y())*ln.vector.x() ) / dCross1;
158  *k_ln = ln.getK( at(*k) );
159 
160  return M_TRUE;
161  }
void at(double k, laPoint2 *ppt) const
Get point at 1/k lenght (returns in user-specified pointer)
Definition: laLine2.h:81
laPoint2 vector
Vector ( not normalized, so k = [0;1] traces the whole line segment )
Definition: laLine2.h:44
#define M_ABS(a)
Return abs(a)
laPoint2 origin
Point of origin.
Definition: laLine2.h:43

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