52                 double Ratio = ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy);
    67                                 out_x = x1 + (Ratio * Dx);
    68                                 out_y = y1 + (Ratio * Dy);
    96                 double Ratio = ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy);
    98                 out_x = x1 + (Ratio * Dx);
    99                 out_y = y1 + (Ratio * Dy);
   114         if (x1==x2 && y1==y2)
   122                 double Ratio = ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy);
   124                 return square( x1 + (Ratio * Dx) - Px ) + 
square( y1 + (Ratio * Dy) - Py );
   134                         const double x1,
const double y1,
   135                         const double x2,
const double y2,
   136                         const double x3,
const double y3,
   137                         const double x4,
const double y4,
   138                         double  &ix,
double  &iy)
   140         double          UpperX,UpperY,LowerX,LowerY,Ax,Bx,Cx,Ay,By,Cy,d,f,e,Ratio;
   158                         if (UpperX < x4 || x3 < LowerX) 
return false;
   160         else    if (UpperX < x3 || x4 < LowerX) 
return false;
   178                         if (UpperY < y4 || y3 < LowerY) 
return false;
   180         else    if (UpperY < y3 || y4 < LowerY) 
return false;
   184         d  = (By * Cx) - (Bx * Cy);
   185         f  = (Ay * Bx) - (Ax * By);
   189                         if (d < 0 || d > f) 
return false;
   191         else    if (d > 0 || d < f) 
return false;
   193         e = (Ax * Cy) - (Ay * Cx);
   197                         if (e < 0 || e > f) 
return false;
   199         else    if (e > 0 || e < f) 
return false;
   201         Ratio = (Ax * -By) - (Ay * -Bx);
   205                 Ratio = ((Cy * -Bx) - (Cx * -By)) / Ratio;
   206                 ix    = x1 + (Ratio * Ax);
   207                 iy    = y1 + (Ratio * Ay);
   211                 if ( (Ax * -Cy)==(-Cx * Ay) )
   229                         const double x1,
const double y1,
   230                         const double x2,
const double y2,
   231                         const double x3,
const double y3,
   232                         const double x4,
const double y4,
   237         ix = 
static_cast<float>(
x);
   238         iy = 
static_cast<float>(
y);
   246 bool  math::pointIntoPolygon2D(
const double & px, 
const double & py, 
unsigned int polyEdges, 
const double *poly_xs, 
const double *poly_ys )
   251         if (polyEdges<3) 
return res;
   255         for (i=0;i<polyEdges;i++)
   257                 if ((poly_ys[i] <= py && py < poly_ys[j]) ||     
   258                         (poly_ys[j] <= py && py < poly_ys[i]) )   
   261                         if (px - poly_xs[i]<((poly_xs[j] - poly_xs[i]) * (py - poly_ys[i]) / (poly_ys[j] - poly_ys[i]) ))
   276         double                  minDist = 1e20f;
   285         for (i=0;i<polyEdges;i++)
   289                 double  closestX,closestY;
   292                 minDist = 
min(d,minDist);
   305                                         const double &  p1_x, 
const double &    p1_y, 
const double & p1_z,
   306                                         const double &  p2_x, 
const double &    p2_y, 
const double & p2_z,
   307                                         const double &  p3_x, 
const double & p3_y, 
const double & p3_z,
   308                                         const double &  p4_x, 
const double & p4_y, 
const double & p4_z,
   309                                         double  &
x,   
double &
y,   
double &
z,
   312         const double EPS = 1e-30f;
   314         double  p13_x,p13_y,p13_z;
   315         double  p43_x,p43_y,p43_z;
   316         double  p21_x,p21_y,p21_z;
   318         double  d1343,d4321,d1321,d4343,d2121;
   329         if (fabs(p43_x)  < EPS && fabs(p43_y) < EPS && fabs(p43_z)  < EPS)      
return false;
   334         if (fabs(p21_x)  < EPS && fabs(p21_y)  < EPS && fabs(p21_z)  < EPS)     
return false;
   336         d1343 = p13_x * p43_x + p13_y * p43_y + p13_z * p43_z;
   337         d4321 = p43_x * p21_x + p43_y * p21_y + p43_z * p21_z;
   338         d1321 = p13_x * p21_x + p13_y * p21_y + p13_z * p21_z;
   339         d4343 = p43_x * p43_x + p43_y * p43_y + p43_z * p43_z;
   340         d2121 = p21_x * p21_x + p21_y * p21_y + p21_z * p21_z;
   342         denom = d2121 * d4343 - d4321 * d4321;
   343         if (fabs(denom) < EPS)  
return false;
   345         numer = d1343 * d4321 - d1321 * d4343;
   347         double mua = numer / denom;
   348         double mub = (d1343 + d4321 * mua) / d4343;
   349         double pa_x, pa_y, pa_z;
   350         double pb_x, pb_y, pb_z;
   352         pa_x = p1_x + mua * p21_x;
   353         pa_y = p1_y + mua * p21_y;
   354         pa_z = p1_z + mua * p21_z;
   356         pb_x = p3_x + mub * p43_x;
   357         pb_y = p3_y + mub * p43_y;
   358         pb_z = p3_z + mub * p43_z;
   360         dist = (double) sqrt( 
square( pa_x - pb_x ) + 
square( pa_y - pb_y ) + 
square( pa_z - pb_z ) );
   363         x = 0.5*(pa_x + pb_x);
   364         y = 0.5*(pa_y + pb_y);
   365         z = 0.5*(pa_z + pb_z);
   375                         const double &  R1_x_min,       
const double &  R1_x_max,
   376                         const double &  R1_y_min,       
const double &  R1_y_max,
   377                         const double &  R2_x_min,       
const double &  R2_x_max,
   378                         const double &  R2_y_min,       
const double &  R2_y_max,
   379                         const double &  R2_pose_x,
   380                         const double &  R2_pose_y,
   381                         const double &  R2_pose_phi )
   386         double                  ccos = cos(R2_pose_phi);
   387         double                  ssin = sin(R2_pose_phi);
   389         xs[0] = R2_pose_x + ccos * R2_x_min - ssin * R2_y_min;
   390         ys[0] = R2_pose_y + ssin * R2_x_min + ccos * R2_y_min;
   392         xs[1] = R2_pose_x + ccos * R2_x_max - ssin * R2_y_min;
   393         ys[1] = R2_pose_y + ssin * R2_x_max + ccos * R2_y_min;
   395         xs[2] = R2_pose_x + ccos * R2_x_max - ssin * R2_y_max;
   396         ys[2] = R2_pose_y + ssin * R2_x_max + ccos * R2_y_max;
   398         xs[3] = R2_pose_x + ccos * R2_x_min - ssin * R2_y_max;
   399         ys[3] = R2_pose_y + ssin * R2_x_min + ccos * R2_y_max;
   403         if ( R1_x_min<=xs[0] && xs[0]<=R1_x_max && R1_y_min<=ys[0] && ys[0]<=R1_y_max) 
return true;
   404         if ( R1_x_min<=xs[1] && xs[1]<=R1_x_max && R1_y_min<=ys[1] && ys[1]<=R1_y_max) 
return true;
   405         if ( R1_x_min<=xs[2] && xs[2]<=R1_x_max && R1_y_min<=ys[2] && ys[2]<=R1_y_max) 
return true;
   406         if ( R1_x_min<=xs[3] && xs[3]<=R1_x_max && R1_y_min<=ys[3] && ys[3]<=R1_y_max) 
return true;
   424         for (
int idx=0;idx<4;idx++)
   426                 if ( 
math::SegmentsIntersection( R1_x_min,R1_y_min, R1_x_max,R1_y_min, xs[idx],ys[idx], xs[(idx+1)%4],ys[(idx+1)%4], ix,iy) ) 
return true;
   427                 if ( 
math::SegmentsIntersection( R1_x_max,R1_y_min, R1_x_max,R1_y_max, xs[idx],ys[idx], xs[(idx+1)%4],ys[(idx+1)%4], ix,iy) ) 
return true;
   428                 if ( 
math::SegmentsIntersection( R1_x_max,R1_y_max, R1_x_min,R1_y_max, xs[idx],ys[idx], xs[(idx+1)%4],ys[(idx+1)%4], ix,iy) ) 
return true;
   429                 if ( 
math::SegmentsIntersection( R1_x_min,R1_y_max, R1_x_min,R1_y_min, xs[idx],ys[idx], xs[(idx+1)%4],ys[(idx+1)%4], ix,iy) ) 
return true;
   448         proj1.generate2DObject(proj1_2D);
   449         proj2.generate2DObject(proj2_2D);
   452         if (
intersect(proj1_2D,proj2_2D,obj2D)) {
   466         TPoint3D pMin=((s11[0][i1]<s21[0][i1])?s21:s11)[0];
   467         TPoint3D pMax=((s11[1][i1]<s21[1][i1])?s11:s21)[1];
   471         }       
else if (pMax[i1]<pMin[i1]) 
return false;       
   482         TPoint2D pMin=((s11[0][i1]<s21[0][i1])?s21:s11)[0];
   483         TPoint2D pMax=((s11[1][i1]<s21[1][i1])?s11:s21)[1];
   487         }       
else if (pMax[i1]<pMin[i1]) 
return false;       
   498         size_t N=poly.size();
   511                 if (d<0||d>bestKnown) 
return false;
   524         if (
obj.getLine(lin3D)) {
   563         size_t N=oldPolys.size();
   565         for (
size_t i=0;i<N;i++) newPolys[i]=oldPolys[i];
   592                 if (!
obj.getPoint(
p)) 
return false;
   606                 if (!
obj.getPoint(
p)) 
return false;
   627                 size_t c1=(i1+1)%3,c2=(i1+2)%3;
   663         const static size_t c1[]={1,2,0};
   664         const static size_t c2[]={2,0,1};
   666         for (
size_t i=0;i<3;i++)        {
   727         double c=0,n1=0,n2=0;
   728         for (
size_t i=0;i<3;i++)        {
   733         double s=sqrt(n1*n2);
   735         if (abs(
s)<abs(
c)) 
return (
c/
s<0)?
M_PI:0;
   736         else return acos(
c/
s);
   740         double c=0,n1=0,n2=0;
   741         for (
size_t i=0;i<3;i++)        {
   746         double s=sqrt(n1*n2);
   749         else return asin(
c/
s);
   753         double c=0,n1=0,n2=0;
   754         for (
size_t i=0;i<3;i++)        {
   759         double s=sqrt(n1*n2);
   761         if (abs(
s)<abs(
c)) 
return (
c/
s<0)?
M_PI:0;
   762         else return acos(
c/
s);
   766         double c=0,n1=0,n2=0;
   767         for (
size_t i=0;i<2;i++)        {
   772         double s=sqrt(n1*n2);
   774         if (abs(
s)<abs(
c)) 
return (
c/
s<0)?
M_PI:0;
   775         else return acos(
c/sqrt(n1*n2));
   781         for (
size_t i=0;i<3;i++)        {
   782                 r.pBase[i]=m.get_unsafe(i,3);
   783                 r.director[i]=m.get_unsafe(i,axis);
   802         for (
size_t i=0;i<3;i++)        {
   803                 r.pBase[i]=m.get_unsafe(i,3);
   805                 for (
size_t j=0;j<3;j++) 
r.director[i]+=m.get_unsafe(i,j)*vector[j];
   810         r.coefs[0]=cos(
p.phi);
   811         r.coefs[1]=-sin(
p.phi);
   812         r.coefs[2]=-
r.coefs[0]*
p.x-
r.coefs[1]*
p.y;
   816         r.coefs[0]=sin(
p.phi);
   817         r.coefs[1]=cos(
p.phi);
   818         r.coefs[2]=-
r.coefs[0]*
p.x-
r.coefs[1]*
p.y;
   824         r.coefs[0]=vector[0]*
c+vector[1]*
s;
   825         r.coefs[1]=-vector[0]*
s+vector[1]*
c;
   826         r.coefs[2]=-
r.coefs[0]*
p.x-
r.coefs[1]*
p.y;
   831         if (N<3) 
return false;
   834         for (
size_t i=0;i<N-1;i++)      {
   849         if (N<2) 
return false;
   852         for (
size_t i=0;i<N-1;i++)      {
   863         for (
size_t i=1;;i++) 
try       {
   866         }       
catch (logic_error &)   {}
   871         if (N<2) 
return false;
   874         for (
size_t i=0;i<N-1;i++)      {
   886         for (
size_t i=1;;i++) 
try       {
   889         }       
catch (logic_error &)   {}
   895         for (
size_t i=0;i<3;i++)        {
   897                 for (
size_t j=0;j<3;j++) newLine.
director[i]+=mat.get_unsafe(i,j)*line.
director[j];
   904         for (
size_t i=0;i<3;i++)        {
   906                 for (
size_t j=0;j<3;j++) newPlane.
coefs[i]+=mat.get_unsafe(i,j)*plane.
coefs[j];
   916         size_t N=polygon.size();
   917         newPolygon.resize(N);
   918         for (
size_t i=0;i<N;i++) 
project3D(polygon[i],newXYpose,newPolygon[i]);
   922         switch (
object.getType())       {
   934                                 object.getSegment(
p);
   958                                 object.getPolygon(
p);
   973         double c=cos(newXpose.
phi());
   974         double s=sin(newXpose.
phi());
   982         size_t N=line.size();
   984         for (
size_t i=0;i<N;i++) newLine[i]=newXpose+line[i];
   989         switch (
obj.getType())  {
  1040         if (p1.size()<3) 
return false;
  1046         size_t N=projPoly.size();
  1047         projPoly.push_back(projPoly[0]);
  1048         double pre=projPoly[0].y;
  1049         vector<TPoint2D> pnts;
  1051         for (
size_t i=1;i<=N;i++)       {
  1052                 double cur=projPoly[i].y;
  1056                                 pnts[0]=projPoly[i-1];
  1057                                 pnts[1]=projPoly[i];
  1059                         }       
else pnts.push_back(projPoly[i]);
  1061                         double a=projPoly[i-1].x;
  1062                         double c=projPoly[i].x;
  1063                         double x=
a-pre*(
c-
a)/(cur-pre);
  1069         switch (pnts.size())    {
  1087                         throw std::logic_error(
"Polygon is not convex");
  1108                                 delete data.segment;
  1123             if (&
r==
this) 
return *
this;
  1125                 switch (
type=
r.type)    {
  1166             if (&
t==
this) 
return *
this;
  1168                 switch (
type=
t.type)    {
  1201         size_t N=poly.size();
  1208         switch (
obj.getType())  {
  1223         std::vector<TSegmentWithLine> segs1,segs2;
  1226         unsigned int hmInters=0;
  1227         for (
size_t i=0;i<segs1.size();i++)     {
  1229                 for (
size_t j=0;j<segs2.size();j++) 
if (
intersect(s1,segs2[j],
obj))     {
  1230                         intersections(i,j)=
obj;
  1234         for (
size_t i=0;i<intersections.
getRowCount();i++)      {
  1239                 if (p1.contains(p2[0])) {
  1242                 }       
else if (p2.contains(p1[0]))    {
  1245                 }       
else return false;
  1269         if (
obj.getPoint(pnt))  {
  1271                 p.getAsPose3DForcingOrigin(p1[0],pose);
  1278         }       
else if (
obj.getSegment(sgm)) 
return intersectInCommonPlane<TPolygon2D,TSegment2D>(p1,s2,
p,
obj);
  1287         if (
obj.getPoint(pnt))  {
  1289                 p.getAsPose3DForcingOrigin(p1[0],pose);
  1296         }       
else if (
obj.isLine()) 
return intersectInCommonPlane<TPolygon2D,TLine2D>(p1,r2,
p,
obj);
  1305         if (
obj.isPlane())      {
  1309         }       
else if (
obj.getLine(ln)) 
return intersectInCommonPlane<TPolygon2D,TLine2D>(p1,ln,
p,
obj);
  1317         if (
obj.isPlane()) 
return intersectInCommonPlane<TPolygon2D,TPolygon2D>(p1,p2,pl1,
obj); 
  1318         else if (
obj.getLine(ln))       {
  1320                 if (!intersectInCommonPlane<TPolygon2D,TLine2D>(p1,ln,pl1,obj1)) 
return false;
  1321                 if (!intersectInCommonPlane<TPolygon2D,TLine2D>(p2,ln,pl2,obj2)) 
return false;
  1334         for (
size_t i=0;i<3;i++) if ((min1[i]>max2[i])||(min2[i]>max1[i])) 
return false;
  1345         if (!p1.
getPlane(pl1)) 
return false;
  1346         if (!p2.
getPlane(pl2)) 
return false;
  1351 inline void getPlanes(
const std::vector<TPolygon3D> &polys,std::vector<TPlane> &planes) {
  1352         size_t N=polys.size();
  1358 void getMinAndMaxBounds(
const std::vector<TPolygon3D> &
v1,std::vector<TPoint3D> &minP,std::vector<TPoint3D> &maxP)      {
  1373         std::vector<TPlane> 
w1,
w2;
  1376         std::vector<TPoint3D> minBounds1,maxBounds1,minBounds2,maxBounds2;
  1379         size_t M=
v1.size(),N=
v2.size();
  1383         for (
size_t i=0;i<M;i++) 
for (
size_t j=0;j<N;j++) 
if (!
compatibleBounds(minBounds1[i],maxBounds1[i],minBounds2[j],maxBounds2[j])) 
continue;
  1388 size_t math::intersect(
const std::vector<TPolygon3D> &
v1,
const std::vector<TPolygon3D> &
v2,std::vector<TObject3D> &objs)        {
  1390         std::vector<TPlane> 
w1,
w2;
  1393         std::vector<TPoint3D> minBounds1,maxBounds1,minBounds2,maxBounds2;
  1402                 const TPlane &plane1=*itP1;
  1404                 const TPoint3D &min1=*itMin1,max1=*itMax1;
  1512         double dx=p2.
x-p1.
x;
  1513         double dy=p2.
y-p1.
y;
  1514         return sqrt(dx*dx+dy*dy);
  1518         double dx=p2.
x-p1.
x;
  1519         double dy=p2.
y-p1.
y;
  1520         double dz=p2.
z-p1.
z;
  1521         return sqrt(dx*dx+dy*dy+dz*dz);
  1525         size_t N=poly.size();
  1526         if (N<1) 
throw logic_error(
"Empty polygon");
  1529         for (
size_t i=1;i<N;i++)        {
  1530                 pMin.
x=
min(pMin.
x,poly[i].x);
  1531                 pMin.
y=
min(pMin.
y,poly[i].y);
  1532                 pMax.
x=max(pMax.
x,poly[i].x);
  1533                 pMax.
y=max(pMax.
y,poly[i].y);
  1555                 return p.distance(r2.
pBase);
  1607         size_t N=poly.size();
  1608         if (N<1) 
throw logic_error(
"Empty polygon");
  1611         for (
size_t i=1;i<N;i++)        {
  1612                 pMin.
x=
min(pMin.
x,poly[i].x);
  1613                 pMin.
y=
min(pMin.
y,poly[i].y);
  1614                 pMin.
z=
min(pMin.
z,poly[i].z);
  1615                 pMax.
x=max(pMax.
x,poly[i].x);
  1616                 pMax.
y=max(pMax.
y,poly[i].y);
  1617                 pMax.
z=max(pMax.
z,poly[i].z);
  1624         for (
size_t i=0;i<3;i++)        {
  1625                 plane.
coefs[i]=m.get_unsafe(i,axis);
  1626                 plane.
coefs[3]-=plane.
coefs[i]*m.get_unsafe(i,3);
  1645         for (
size_t i=0;i<3;i++)        {
  1647                 for (
size_t j=0;j<3;j++) plane.
coefs[i]+=normal[j]*m.get_unsafe(i,j);
  1648                 plane.
coefs[3]-=plane.
coefs[i]*m.get_unsafe(i,3);
  1655         char coord1=(
coord+1)%3;
  1656         char coord2=(
coord+2)%3;
  1659         for (
size_t i=0;i<3;i++) 
matrix.set_unsafe(i,
coord,vec[i]);
  1660         matrix.set_unsafe(0,coord1,0);
  1661         double h=hypot(vec[1],vec[2]);
  1663                 matrix.set_unsafe(1,coord1,1);
  1664                 matrix.set_unsafe(2,coord1,0);
  1666                 matrix.set_unsafe(1,coord1,-vec[2]/h);
  1667                 matrix.set_unsafe(2,coord1,vec[1]/h);
  1678         covars.eigenVectors(eigenVec,eigenVal);
  1679         size_t selected=(eigenVal.get_unsafe(0,0)>=eigenVal.get_unsafe(1,1))?0:1;
  1680         line.
coefs[0]=-eigenVec.get_unsafe(1,selected);
  1681         line.
coefs[1]=eigenVec.get_unsafe(0,selected);
  1683         return sqrt(eigenVal.get_unsafe(1-selected,1-selected)/eigenVal.get_unsafe(selected,selected));
  1688         return (e1<e2)?((e1<e3)?0:2):((e2<e3)?1:2);
  1693         return (e1>e2)?((e1>e3)?0:2):((e2>e3)?1:2);
  1700         covars.eigenVectors(eigenVec,eigenVal);
  1701         size_t selected=
getIndexOfMax(eigenVal.get_unsafe(0,0),eigenVal.get_unsafe(1,1),eigenVal.get_unsafe(2,2));
  1702         for (
size_t i=0;i<3;i++)        {
  1703                 line.
pBase[i]=means[i];
  1704                 line.
director[i]=eigenVec.get_unsafe(i,selected);
  1706         size_t i1=(selected+1)%3,i2=(selected+2)%3;
  1707         return sqrt((eigenVal.get_unsafe(i1,i1)+eigenVal.get_unsafe(i2,i2))/eigenVal.get_unsafe(selected,selected));
  1711         vector<double> means;
  1715         covars.eigenVectors(eigenVec,eigenVal);
  1716         for (
size_t i=0;i<3;++i) 
if (eigenVal.get_unsafe(i,i)<0&&fabs(eigenVal.get_unsafe(i,i))<
geometryEpsilon) eigenVal.set_unsafe(i,i,0);
  1717         size_t selected=
getIndexOfMin(eigenVal.get_unsafe(0,0),eigenVal.get_unsafe(1,1),eigenVal.get_unsafe(2,2));
  1719         for (
size_t i=0;i<3;i++)        {
  1720                 plane.
coefs[i]=eigenVec.get_unsafe(i,selected);
  1723         size_t i1=(selected+1)%3,i2=(selected+2)%3;
  1724         return sqrt(eigenVal.get_unsafe(selected,selected)/(eigenVal.get_unsafe(i1,i1)+eigenVal.get_unsafe(i2,i2)));
  1728         std::vector<TSegment3D> tmp;
  1738         MatchingVertex(
size_t s1,
size_t s2,
bool s1p,
bool s2p):seg1(s1),seg2(s2),seg1Point(s1p),seg2Point(s2p)   {}
  1742         const std::vector<TSegment3D> &
segs;
  1746                 size_t N=vertices.size();
  1753         if (
v.size()>0&&
v[0].seg1==i) 
return true;
  1759                 unsigned char match=mat(searching,i)&
mask;
  1760                 if (!match) 
continue;
  1763                         if (
true==(s1p=(!(match&3)))) match>>=2;
  1765                         if (current.size()>=2&¤t[0].seg1==i)      {
  1766                                 if (s2p!=current[0].seg1Point)  {
  1769                                         res.push_back(current);
  1783         vector<MatchingVertex> cur;
  1784         for (
size_t i=0;i<used.size();i++) 
if (!used[i]) 
if (
depthFirstSearch(mat,
res,used,i,0xf,cur)) cur.clear();
  1786 void math::assemblePolygons(
const std::vector<TSegment3D> &segms,std::vector<TPolygon3D> &polys,std::vector<TSegment3D> &remainder)     {
  1787         std::vector<TSegment3D> tmp;
  1788         tmp.reserve(segms.size());
  1790         else remainder.push_back(*it);
  1791         size_t N=tmp.size();
  1793         for (
size_t i=0;i<N-1;i++) 
for (
size_t j=i+1;j<N;j++)   {
  1811         std::vector<std::vector<MatchingVertex> > results;
  1812         std::vector<bool> usedSegments(N,
false);
  1814         polys.resize(results.size());
  1816         for (
size_t i=0;i<N;i++) 
if (!usedSegments[i]) remainder.push_back(tmp[i]);
  1820         std::vector<TObject3D> tmp;
  1821         std::vector<TSegment3D> sgms;
  1827 void math::assemblePolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder)        {
  1828         std::vector<TObject3D> tmp;
  1829         std::vector<TSegment3D> sgms,remainderSgms;
  1833         remainder.insert(remainder.end(),remainderSgms.begin(),remainderSgms.end());
  1836 void math::assemblePolygons(
const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TSegment3D> &remainder1,std::vector<TObject3D> &remainder2)   {
  1837         std::vector<TObject3D> tmp;
  1838         std::vector<TSegment3D> sgms;
  1854         }       
else return false;
  1863         size_t N=poly.size();
  1864         if (N<=3) 
return false;
  1865         vector<TSegmentWithLine> segms(N);
  1870         for (
size_t i=0;i<N;i++)        {
  1871                 size_t ii=(i+2)%N,i_=(i+N-1)%N;
  1872                 for (
size_t j=ii;j!=i_;j=(j+1)%N) 
if (
intersect(segms[i].line,segms[j],
obj)&&
obj.getPoint(pnt)) {
  1879                         if (
cross) 
continue;
  1882                         if (
sign(segms[i].line.evaluatePoint(poly[(i+N-1)%N]))==
sign(segms[i].line.evaluatePoint(poly[(i+2)%N]))) 
continue;
  1885                                 p1.insert(p1.end(),poly.begin()+i+1,poly.end());
  1886                                 p1.insert(p1.end(),poly.begin(),poly.begin()+j+1);
  1887                                 p2.insert(p2.end(),poly.begin()+j+1,poly.begin()+i+1);
  1889                                 p1.insert(p1.end(),poly.begin()+i+1,poly.begin()+j+1);
  1890                                 p2.insert(p2.end(),poly.begin()+j+1,poly.end());
  1891                                 p2.insert(p2.end(),poly.begin(),poly.begin()+i+1);
  1897                         vector<TPolygon2D> tempComps;
  1921         if (!poly.
getPlane(
p)) 
throw std::logic_error(
"Polygon is skew");
  1923         p.getAsPose3DForcingOrigin(poly[0],pose1);
  1928         vector<TPolygon2D> components2D;
  1933         }       
else return false;
  1969         }       
else if (
obj.getPoint(
p))       {
  1973                 double ang=(ang1+ang2)/2;
  1974                 bis.
coefs[0]=-sin(ang);
  1975                 bis.
coefs[1]=cos(ang);
  1988         p.getAsPose3D(pose);
 void getCenter(TPoint2D &p) const
Segment's central point. 
 
void BASE_IMPEXP createPlaneFromPoseAndNormal(const mrpt::poses::CPose3D &pose, const double(&normal)[3], TPlane &plane)
Given a pose and any vector, creates a plane orthogonal to that vector in the pose's coordinates...
 
bool intersectInCommonLine(const mrpt::math::TSegment3D &s1, const mrpt::math::TSegment3D &s2, const mrpt::math::TLine3D &lin, mrpt::math::TObject3D &obj)
 
const unsigned char GEOMETRIC_TYPE_PLANE
Object type identifier for TPlane. 
 
bool getPoint(TPoint2D &p) const
Gets the content as a point, returning false if the type is inadequate. 
 
double x() const
Common members of all points & poses classes. 
 
bool isNotNull(size_t nRow, size_t nCol) const
Checks whether an element of the matrix is not the default object. 
 
TSegmentWithLine(const TPoint2D &p1, const TPoint2D &p2)
 
TPolygon3D operator()(const TPolygon2D &poly2D)
 
bool getPolygon(TPolygon2D &p) const
Gets the content as a polygon, returning false if the type is inadequate. 
 
bool BASE_IMPEXP RectanglesIntersection(const double &R1_x_min, const double &R1_x_max, const double &R1_y_min, const double &R1_y_max, const double &R2_x_min, const double &R2_x_max, const double &R2_y_min, const double &R2_y_max, const double &R2_pose_x, const double &R2_pose_y, const double &R2_pose_phi)
Returns whether two rotated rectangles intersect. 
 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL. 
 
const unsigned char GEOMETRIC_TYPE_LINE
Object type identifier for TLine2D or TLine3D. 
 
bool BASE_IMPEXP splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components. 
 
void BASE_IMPEXP generateAxisBaseFromDirectionAndAxis(const double(&vec)[3], char coord, CMatrixDouble &matrix)
Creates a homogeneus matrix (4x4) such that the coordinate given (0 for x, 1 for y, 2 for z) corresponds to the provided vector. 
 
const unsigned char GEOMETRIC_TYPE_POINT
Object type identifier for TPoint2D or TPoint3D. 
 
bool intersect(const TPolygonWithPlane &p1, const TLine3D &l2, double &d, double bestKnown)
 
void getPlanes(const std::vector< TPolygon3D > &polys, std::vector< TPlane > &planes)
 
bool firstOrNonPresent(size_t i, const std::vector< MatchingVertex > &v)
 
double distance(const TPoint3D &point) const
Distance between the line and a point. 
 
void BASE_IMPEXP closestFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a (infinite) line. 
 
void BASE_IMPEXP closestFromPointToSegment(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a segment. 
 
bool BASE_IMPEXP minDistBetweenLines(const double &p1_x, const double &p1_y, const double &p1_z, const double &p2_x, const double &p2_y, const double &p2_z, const double &p3_x, const double &p3_y, const double &p3_z, const double &p4_x, const double &p4_y, const double &p4_z, double &x, double &y, double &z, double &dist)
Calculates the minimum distance between a pair of lines. 
 
bool getSegment(TSegment3D &s) const
Gets the content as a segment, returning false if the type is not adequate. 
 
double BASE_IMPEXP closestSquareDistanceFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2)
Returns the square distance from a point to a line. 
 
bool contains(const TPoint2D &point) const
Check whether a point is inside a segment. 
 
bool BASE_IMPEXP pointIntoPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns true if the 2D point (px,py) falls INTO the given polygon. 
 
size_t getNonNullElements() const
Gets the amount of non-null elements inside the matrix. 
 
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties. 
 
void BASE_IMPEXP assemblePolygons(const std::vector< TSegment3D > &segms, std::vector< TPolygon3D > &polys)
Tries to assemble a set of segments into a set of closed polygons. 
 
void BASE_IMPEXP getSegmentBisector(const TSegment2D &sgm, TLine2D &bis)
Gets the bisector of a 2D segment. 
 
char fromObject(const TObject2D &obj)
 
void createPlaneFromPoseAndAxis(const CPose3D &pose, TPlane &plane, size_t axis)
 
#define THROW_EXCEPTION(msg)
 
void unsafeProjectPolygon(const TPolygon3D &poly, const CPose3D &pose, TPolygon2D &newPoly)
 
Slightly heavyweight type to speed-up calculations with polygons in 3D. 
 
This file implements several operations that operate element-wise on individual or pairs of container...
 
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
 
size_t getColCount() const
Returns the amount of columns in this matrix. 
 
Standard type for storing any lightweight 2D type. 
 
A wrapper of a TPolygon2D class, implementing CSerializable. 
 
bool getLine(TLine2D &r) const
Gets the content as a line, returning false if the type is inadequate. 
 
void BASE_IMPEXP createFromPoseAndVector(const mrpt::poses::CPose3D &p, const double(&vector)[3], TLine3D &r)
Gets a 3D line corresponding to any arbitrary vector, in the base given by the pose. 
 
void getAsPose3D(mrpt::poses::CPose3D &outPose)
Gets a pose whose XY plane corresponds to this plane. 
 
bool getPlane(TPlane &p) const
Gets the content as a plane, returning false if the type is not adequate. 
 
TPoint3D pBase
Base point. 
 
Standard object for storing any 3D lightweight object. 
 
bool getSegment(TSegment2D &s) const
Gets the content as a segment, returning false if the type is inadequate. 
 
bool contains(const TPoint2D &point) const
Check whether a point is inside the line. 
 
TSegmentWithLine(const TSegment2D &s)
 
const Scalar * const_iterator
 
void getSegmentsWithLine(const TPolygon2D &poly, vector< TSegmentWithLine > &segs)
 
bool intersectInCommonPlane(const T3D &o1, const U3D &o2, const mrpt::math::TPlane &p, mrpt::math::TObject3D &obj)
 
double z
X,Y,Z coordinates. 
 
GLenum GLenum GLuint components
 
double distance(const TPoint3D &point) const
Distance to 3D point. 
 
struct BASE_IMPEXP TObject3D
 
size_t getIndexOfMin(const T &e1, const T &e2, const T &e3)
 
GLsizei GLsizei GLuint * obj
 
void BASE_IMPEXP getAngleBisector(const TLine2D &l1, const TLine2D &l2, TLine2D &bis)
Gets the bisector of two lines or segments (implicit constructor will be used if necessary) ...
 
void BASE_IMPEXP project2D(const TPoint2D &point, const mrpt::poses::CPose2D &newXpose, TPoint2D &newPoint)
Uses the given pose 2D to project a point into a new base. 
 
struct BASE_IMPEXP TSegment3D
 
A sparse matrix container (with cells of any type), with iterators. 
 
TTempIntersection(const TCommonRegion &common)
 
void BASE_IMPEXP createFromPoseY(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Y axis in a given pose. 
 
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both. 
 
TPoint3D point1
Origin point. 
 
T square(const T x)
Inline function for the square of a number. 
 
bool BASE_IMPEXP conformAPlane(const std::vector< TPoint3D > &points)
Checks whether this polygon or set of points acceptably fits a plane. 
 
GLsizei const GLfloat * points
 
static void getSegments(const std::vector< TObject3D > &objs, std::vector< TSegment3D > &sgms)
Static method to retrieve every segment included in a vector of objects. 
 
void generate2DObject(TLine2D &l) const
Project into 2D space, discarding the Z coordinate. 
 
void BASE_IMPEXP createFromPoseX(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the X axis in a given pose. 
 
const std::vector< TSegment3D > & segs
 
TTempIntersection & operator=(const TTempIntersection &t)
 
TPolygonWithPlane()
Basic constructor. 
 
bool contains(const TPoint3D &point) const
Check whether a point is inside the line. 
 
size_t getRowCount() const
Returns the amount of rows in this matrix. 
 
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing  with G and L being 3D points and P this 6D pose...
 
void unitarize()
Unitarize line's normal vector. 
 
A numeric matrix of compile-time fixed size. 
 
bool getPolygon(TPolygon3D &p) const
Gets the content as a polygon, returning false if the type is not adequate. 
 
This base provides a set of functions for maths stuff. 
 
2D segment, consisting of two points. 
 
bool isPoint() const
Checks whether content is a point. 
 
TCommonRegion & operator=(const TCommonRegion &r)
 
3D segment, consisting of two points. 
 
void BASE_IMPEXP createPlaneFromPoseXY(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Z vector. 
 
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler. 
 
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
 
TPoint3D point2
Destiny point. 
 
double BASE_IMPEXP distancePointToPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns the closest distance of a given 2D point to a polygon, or "0" if the point is INTO the polygo...
 
void BASE_IMPEXP createPlaneFromPoseXZ(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Y vector. 
 
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon. 
 
void unitarize()
Unitarize normal vector. 
 
void BASE_IMPEXP getRectangleBounds(const std::vector< TPoint2D > &poly, TPoint2D &pMin, TPoint2D &pMax)
Gets the rectangular bounds of a 2D polygon or set of 2D points. 
 
const unsigned char GEOMETRIC_TYPE_SEGMENT
Object type identifier for TSegment2D or TSegment3D. 
 
TPolygon3D poly
Actual polygon. 
 
static void getPolygons(const std::vector< TObject3D > &objs, std::vector< TPolygon3D > &polys)
Static method to retrieve every polygon included in a vector of objects. 
 
3D Plane, represented by its equation  
 
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon. Returns false if the polygon is skew and cannot be fit insid...
 
double coefs[3]
Line coefficients, stored as an array: . 
 
class BASE_IMPEXP TPolygon3D
 
double BASE_IMPEXP getRegressionPlane(const std::vector< TPoint3D > &points, TPlane &plane)
Using eigenvalues, gets the best fitting plane for a set of 3D points. 
 
void getCenter(TPoint3D &p) const
Segment's central point. 
 
FCreatePolygon(const std::vector< TSegment3D > &s)
 
TPoint2D point2
Destiny point. 
 
TPolygon2D poly2D
Polygon, after being projected to the plane using inversePose. 
 
TCommonRegion(const TPoint2D &p)
 
double BASE_IMPEXP getAngle(const TPlane &p1, const TPlane &p2)
Computes the angle between two planes. 
 
static void getPlanes(const std::vector< TPolygon3D > &oldPolys, std::vector< TPolygonWithPlane > &newPolys)
Static method for vectors. 
 
A class used to store a 2D point. 
 
void unitarize()
Unitarize director vector. 
 
int sign(T x)
Returns the sign of X as "1" or "-1". 
 
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
 
bool contains(const TPoint3D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge). This works for concave...
 
float cross(const mPointHull &O, const mPointHull &A, const mPointHull &B)
 
bool getPoint(TPoint3D &p) const
Gets the content as a point, returning false if the type is not adequate. 
 
mrpt::poses::CPose3D pose
Plane's pose. 
 
double director[3]
Director vector. 
 
TPoint2D point1
Origin point. 
 
bool BASE_IMPEXP SegmentsIntersection(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, const double x4, const double y4, double &ix, double &iy)
Returns the intersection point, and if it exists, between two segments. 
 
void clear()
Completely removes all elements, although maintaining the matrix's size. 
 
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge). This works for concave...
 
void getAsPose2D(mrpt::poses::CPose2D &outPose) const
Get a pose2D whose X axis corresponds to the line. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
FUnprojectPolygon2D(const CPose3D &p)
 
TTempIntersection(const T2ListsOfSegments &segms)
 
TPolygon3D operator()(const std::vector< MatchingVertex > &vertices)
 
void createFromPoseAndAxis(const CPose3D &p, TLine3D &r, size_t axis)
 
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
 
GLdouble GLdouble GLdouble r
 
double BASE_IMPEXP getRegressionLine(const std::vector< TPoint2D > &points, TLine2D &line)
Using eigenvalues, gets the best fitting line for a set of 2D points. 
 
void generate3DObject(TObject3D &obj) const
Project into 3D space. 
 
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
 
A class used to store a 3D pose (a 3D translation + a rotation in 3D). 
 
struct BASE_IMPEXP TLine3D
 
T2ListsOfSegments * segms
 
void BASE_IMPEXP getPrismBounds(const std::vector< TPoint3D > &poly, TPoint3D &pMin, TPoint3D &pMax)
Gets the prism bounds of a 3D polygon or set of 3D points. 
 
double coefs[4]
Plane coefficients, stored as an array: . 
 
const double & phi() const
Get the phi angle of the 2D pose (in radians) 
 
void resize(size_t nRows, size_t nCols)
Changes the size of the matrix. 
 
void project3D(const TPoint3D &point, const mrpt::poses::CPose3D &newXYpose, TPoint3D &newPoint)
Uses the given pose 3D to project a point into a new base. 
 
void removeRedundantVertices()
Erase every redundant vertex from the polygon, saving space. 
 
MatchingVertex(size_t s1, size_t s2, bool s1p, bool s2p)
 
bool contains(const TPoint3D &point) const
Check whether a point is inside the segment. 
 
bool getLine(TLine3D &r) const
Gets the content as a line, returning false if the type is not adequate. 
 
double evaluatePoint(const TPoint3D &point) const
Evaluate a point in the plane's equation. 
 
bool depthFirstSearch(const CSparseMatrixTemplate< unsigned char > &mat, std::vector< std::vector< MatchingVertex > > &res, std::vector< bool > &used, size_t searching, unsigned char mask, std::vector< MatchingVertex > ¤t)
 
mrpt::poses::CPose3D inversePose
Plane's inverse pose. 
 
void unsafeProjectPoint(const TPoint3D &point, const CPose3D &pose, TPoint2D &newPoint)
 
void BASE_IMPEXP createPlaneFromPoseYZ(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its X vector. 
 
bool BASE_IMPEXP areAligned(const std::vector< TPoint2D > &points)
Checks whether this set of points acceptably fits a 2D line. 
 
bool compatibleBounds(const TPoint3D &min1, const TPoint3D &max1, const TPoint3D &min2, const TPoint3D &max2)
 
size_t getIndexOfMax(const T &e1, const T &e2, const T &e3)
 
GLfloat GLfloat GLfloat v2
 
void BASE_IMPEXP createFromPoseZ(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Z axis in a given pose. 
 
TCommonRegion(const TCommonRegion &r)
 
bool intersectAux(const TPolygon3D &p1, const TPlane &pl1, const TPolygon3D &p2, const TPlane &pl2, TObject3D &obj)
 
TTempIntersection(const TTempIntersection &t)
 
void covariancesAndMean(const VECTOR_OF_VECTORS &elements, MATRIXLIKE &covariances, VECTORLIKE &means, const bool *elem_do_wrap2pi=NULL)
Computes covariances and mean of any vector of containers. 
 
double distance(const TPoint2D &point) const
Distance from a given point. 
 
GLuint GLenum GLenum transform
 
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
 
TPlane plane
Plane containing the polygon. 
 
const unsigned char GEOMETRIC_TYPE_POLYGON
Object type identifier for TPolygon2D or TPolygon3D. 
 
void AddVertex(double x, double y)
Add a new vertex to polygon. 
 
double minimumDistanceFromPointToSegment(const double Px, const double Py, const double x1, const double y1, const double x2, const double y2, T &out_x, T &out_y)
Computes the closest point from a given point to a segment, and returns that minimum distance...
 
GLsizei GLsizei GLenum GLenum const GLvoid * data
 
GLubyte GLubyte GLubyte a
 
bool BASE_IMPEXP intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments. 
 
TCommonRegion(const TSegment2D &s)
 
GLuint GLuint GLsizei GLenum type
 
2D polygon, inheriting from std::vector<TPoint2D>. 
 
3D polygon, inheriting from std::vector<TPoint3D> 
 
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space. 
 
void getMinAndMaxBounds(const std::vector< TPolygon3D > &v1, std::vector< TPoint3D > &minP, std::vector< TPoint3D > &maxP)
 
bool contains(const TPoint3D &point) const
Check whether a point is contained into the plane. 
 
double BASE_IMPEXP geometryEpsilon
Global epsilon to overcome small precision errors (Default=1e-5) 
 
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
 
3D line, represented by a base point and a director vector. 
 
2D line without bounds, represented by its equation .