AURobotServers  4
Public Member Functions | Protected Attributes | List of all members
U2Dlined Class Reference

#include <u2dline.h>

Inheritance diagram for U2Dlined:
Inheritance graph

Public Member Functions

double A ()
 
double B ()
 
double C ()
 
double distanceSigned (const double x, const double y)
 
bool fit (double fx[], double fy[], int count, double *V=NULL)
 
bool fitV (double fx[], double fy[], int count, double *V)
 
void getARLine (double *a, double *r)
 
bool getCrossing (U2Dlined L2, double *x, double *y)
 
void getOnLine (const double x, const double y, double *lx, double *ly)
 
void getPV (double *Px, double *Py, double *Vx, double *Vy)
 
double heading ()
 
void print (const char *prestring)
 
int set (const double A, const double B, const double C)
 
int set (double fx[], double fy[], int count, double *V=NULL)
 
int set2P (const double x1, const double y1, const double x2, const double y2)
 
void setAR (const double a, const double r)
 
int setPH (const double Px, const double Py, const double h)
 
int setPV (const double Px, const double Py, const double Vx, const double Vy)
 
bool setXline (double sX, double sY, double sX2, double sXY, int count)
 
bool setYline (double sX, double sY, double sY2, double sXY, int count)
 
virtual void shiftLeft (double dist)
 
virtual void shiftRight (double dist)
 
 U2Dlined ()
 
 U2Dlined (const double A, const double B, const double C)
 
 U2Dlined (const double a, const double r)
 
 U2Dlined (const double x1, const double y1, const double x2, const double y2)
 
double variance (double fx[], double fy[], int count, double *E=NULL)
 
double vx ()
 
double vy ()
 
virtual ~U2Dlined ()
 

Protected Attributes

double lA
 
double lB
 
double lC
 

Detailed Description

This is a 2D line with parameters in double precition based on line equation Ax + By + C = 0.
sqr(A) + sqr(B) is always 1.0. and should be kept that way to simplify some calculations.

Constructor & Destructor Documentation

U2Dlined::U2Dlined ( )

Constructor (A=1.0, B=0.0, C=0.0 line

References U2Dline::lA, U2Dline::lB, and U2Dline::lC.

U2Dlined::U2Dlined ( const double  A,
const double  B,
const double  C 
)
inline

Construct from A, B, C)

References U2Dline::A(), U2Dline::B(), and U2Dline::C().

U2Dlined::U2Dlined ( const double  a,
const double  r 
)
inline

Construct from A, B, C)

U2Dlined::U2Dlined ( const double  x1,
const double  y1,
const double  x2,
const double  y2 
)
inline

Construct from 2 points

References U2Dline::set2P().

virtual U2Dlined::~U2Dlined ( )
inlinevirtual

Destructor

Member Function Documentation

double U2Dlined::A ( )
inline

Get A parameter in Ax + By + C = 0

References U2Dline::lA.

Referenced by getCrossing(), UResAuEf::initializeWalls(), and UResAuEf::updateWalls().

double U2Dlined::B ( )
inline

Get B parameter in Ax + By + C = 0

References U2Dline::lB.

Referenced by getCrossing(), UResAuEf::initializeWalls(), and UResAuEf::updateWalls().

double U2Dlined::C ( )
inline

Get C parameter in Ax + By + C = 0

References U2Dline::lC.

Referenced by getCrossing(), and UResAuEf::updateWalls().

double U2Dlined::distanceSigned ( const double  x,
const double  y 
)
inline
bool U2Dlined::fit ( double  fx[],
double  fy[],
int  count,
double *  V = NULL 
)

Set as best fit line through a series of points. if V != NULL then the variance is returned here

References a, absd(), U2Dline::lA, U2Dline::lB, U2Dline::lC, sqr(), and U2Dline::variance().

Referenced by UResPoseHist::getPoseFitAtDistance(), and test2DlineFit().

bool U2Dlined::fitV ( double  fx[],
double  fy[],
int  count,
double *  V 
)
void U2Dlined::getARLine ( double *  a,
double *  r 
)
inline

Get line described as alpha,r, where r is distance to line from origo and alpha is the angle to the thpoint on the line closest to the origo.

Parameters
ais where the alpha angle is returned.
ris where the distance to the line is returned

References U2Dline::lA, U2Dline::lB, and U2Dline::lC.

Referenced by UFuncLoca2::correlateLines().

bool U2Dlined::getCrossing ( U2Dlined  L2,
double *  x,
double *  y 
)

Find crossing between this line and line L2. Returns the result in x and y if the lines are not parallel.

Parameters
line2is the other line
x,yis the crossing point, unchanged if not crossing.
Returns
false if lines are parallel.

References U2Dline::A(), A(), U2Dline::B(), B(), U2Dline::C(), and C().

Referenced by UPolygon::cut(), UPolygon::cutPoints(), UAvoidCellGraph::findCellPointPath(), UManArc::getFoodprintPolygon(), UManLine::getMinDistanceXYSigned(), ULine::getXYCrossing(), and UResAuEf::updateWalls().

void U2Dlined::getOnLine ( const double  x,
const double  y,
double *  lx,
double *  ly 
)

Get nearest point on line to this point. Found by minimizing distance
$ d = \sqrt{(x_l - x)^2+(y_l - y)^2} $.
where $(x_l, y_l)$ is point on line expressed by parameter t.
$ [x_l,y_l] = [P_x,P_y] + [V_x,V_y] * t $. Insert into first equation.
$ d^2 = (P_x + V_x * t - x)^2 + (P_y + V_y * t - y)^2 $.
find $ \frac{d d^2}{dt} = 0$ gives
$ t = (-P_x * V_x + V_x * x - P_y * V_y + V_y * y)/((V_x^2 + V_y^2) $. Denominator is equal to 1.0 and can be ignored. Setting t into point-vector line expression gives nearest (lx,ly) point on line. Px, Py, Vx, Vy can then be replaced by A,B,C to simplify expression.

Parameters
x,yis the input x,y position
lx,lyis the found position on the line.

References U2Dline::lA, U2Dline::lB, and U2Dline::lC.

Referenced by UResPoseHist::getPoseFitAtDistance(), UResSmrCtl::getSMRCLDrive2cmd(), and UResLocater::makeRowPolygon().

void U2Dlined::getPV ( double *  Px,
double *  Py,
double *  Vx,
double *  Vy 
)

Get line as in position - vector format on the form [x,y] = [Px,Py] + [Vx,Vy]*t Either Px or Py will be zero.

References absf(), U2Dline::lA, U2Dline::lB, and U2Dline::lC.

double U2Dlined::heading ( )
inline

Get line heading in radians

References U2Dline::getPV(), U2Dline::lA, U2Dline::lB, and U2Dline::setPV().

Referenced by U2Dseg::heading().

void U2Dlined::print ( const char *  prestring)

Print A, B, C to console

References U2Dline::lA, U2Dline::lB, and U2Dline::lC.

Referenced by test2DlineFit().

int U2Dlined::set ( const double  A,
const double  B,
const double  C 
)
inline
int U2Dlined::set ( double  fx[],
double  fy[],
int  count,
double *  V = NULL 
)

Set as best fit line through a series of points. if V != NULL then the variance is returned here

References a, absd(), U2Dline::lA, U2Dline::lB, U2Dline::lC, sqr(), and U2Dline::variance().

int U2Dlined::set2P ( const double  x1,
const double  y1,
const double  x2,
const double  y2 
)
inline
void U2Dlined::setAR ( const double  a,
const double  r 
)
inline

Sets the line from an alpha (a) and r notation. like A = cos(a), B = sin(a), C = -r

Parameters
ais the angle to the closest point on the line - from origo.
ris the distance to the closest point (from origo) to the line.

References U2Dline::lA, U2Dline::lB, and U2Dline::lC.

int U2Dlined::setPH ( const double  Px,
const double  Py,
const double  h 
)

Set line from point-heading format. the resulting line is normalized, so that the A,B vector is a unit vector.

Parameters
Pxis X-position (in meter)
Pyis Y position (in meter)
his heading of line in radians.
Returns
0.

References U2Dline::C().

Referenced by UManSeq::getDistanceFromEndPoseLine(), UResSmrCtl::getSMRCLDrive2cmd(), UResRuleState::methodCallV(), and UAvoidPath2::splitObstGroup().

int U2Dlined::setPV ( const double  Px,
const double  Py,
const double  Vx,
const double  Vy 
)

Set line from point-vector format. the resulting line is normalized, so that the A,B vector is a unit vector.

Parameters
Pxis X-position (in meter)
Pyis Y position (in meter)
Vxis X-component of heading vector (in meter)
Vyis Y component of heading vector (in meter) returns -1 if zero vector.

References U2Dline::C().

Referenced by UPolygon::getMostDistantVertexXY(), UPolygon::getMostDistantXY(), ULine::getXYCrossing(), ULine::getXYsignedDistance(), and UResRuleState::methodCallV().

bool U2Dlined::setXline ( double  sX,
double  sY,
double  sX2,
double  sXY,
int  count 
)

Set line parameters, assuming that the line is more or less parallel with the x-axis

References a, absd(), U2Dline::lA, U2Dline::lB, U2Dline::lC, and sqr().

bool U2Dlined::setYline ( double  sX,
double  sY,
double  sY2,
double  sXY,
int  count 
)

Set line parameters, assuming that the line is more or less parallel with the y-axis

References a, absd(), U2Dline::lA, U2Dline::lB, U2Dline::lC, and sqr().

virtual void U2Dlined::shiftLeft ( double  dist)
inlinevirtual

Shift the line this distance to the Left This moves the C parameter and the start position.

Parameters
distis the distance shifted.

Reimplemented in U2Dseg.

References dist, and U2Dline::lC.

Referenced by U2Dseg::shiftLeft().

virtual void U2Dlined::shiftRight ( double  dist)
inlinevirtual

Shift the line this distance to the Right This moves the C parameter and the start position.

Parameters
distis the distance shifted.

Reimplemented in U2Dseg.

References dist, and U2Dline::lC.

Referenced by U2Dseg::shiftRight().

double U2Dlined::variance ( double  fx[],
double  fy[],
int  count,
double *  E = NULL 
)

Get mean and variance for the distance from these points to the line if E == NULL then mean is not returned. if no points are given, then -1.0 is returned

References U2Dline::distanceSigned(), and sqr().

Referenced by test2DlineFit().

double U2Dlined::vx ( )
inline

Get line vextor X component

References U2Dline::lB.

double U2Dlined::vy ( )
inline

Get line vextor Y component

References U2Dline::lA.

Member Data Documentation

double U2Dlined::lA
protected

Parameters in line equation Ax + By + C = 0

double U2Dlined::lB
protected
double U2Dlined::lC
protected

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