|
@@ -496,6 +496,66 @@ static double GetParamPoly3Dis(GeometryParamPoly3 * parc,double xnow,double ynow
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+static double GetPoly3Dis(GeometryPoly3 * ppoly,double xnow,double ynow,double & nearx,
|
|
|
|
+ double & neary,double & nearhead)
|
|
|
|
+{
|
|
|
|
+ double x,y,hdg;
|
|
|
|
+// double s = 0.0;
|
|
|
|
+ double fdismin = 100000.0;
|
|
|
|
+ // double s0 = ppoly->GetS();
|
|
|
|
+
|
|
|
|
+ x = ppoly->GetX();
|
|
|
|
+ y = ppoly->GetY();
|
|
|
|
+ double A,B,C,D;
|
|
|
|
+ A = ppoly->GetA();
|
|
|
|
+ B = ppoly->GetB();
|
|
|
|
+ C = ppoly->GetC();
|
|
|
|
+ D = ppoly->GetD();
|
|
|
|
+ const double steplim = 0.3;
|
|
|
|
+ double du = steplim;
|
|
|
|
+ double u = 0;
|
|
|
|
+ double v = 0;
|
|
|
|
+ double oldx,oldy;
|
|
|
|
+ oldx = x;
|
|
|
|
+ oldy = y;
|
|
|
|
+ double xstart,ystart;
|
|
|
|
+ xstart = x;
|
|
|
|
+ ystart = y;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ double hdgstart = ppoly->GetHdg();
|
|
|
|
+ double flen = 0;
|
|
|
|
+ u = u+du;
|
|
|
|
+ while(flen < ppoly->GetLength())
|
|
|
|
+ {
|
|
|
|
+ double fdis = 0;
|
|
|
|
+ v = A + B*u + C*u*u + D*u*u*u;
|
|
|
|
+ x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
|
|
|
|
+ y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
|
|
|
|
+ fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
|
|
|
|
+
|
|
|
|
+ if(fdis>(steplim*2.0))du = du/2.0;
|
|
|
|
+ flen = flen + fdis;
|
|
|
|
+ u = u + du;
|
|
|
|
+ hdg = CalcHdg(QPointF(oldx,oldy),QPointF(x,y));
|
|
|
|
+
|
|
|
|
+ double fdisnow = calcpointdis(QPointF(x,y),QPointF(xnow,ynow));
|
|
|
|
+ if(fdisnow<fdismin)
|
|
|
|
+ {
|
|
|
|
+ fdismin = fdisnow;
|
|
|
|
+ nearhead = hdg;
|
|
|
|
+ nearx = x;
|
|
|
|
+ neary = y;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ oldx = x;
|
|
|
|
+ oldy = y;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fdismin;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @brief GetNearPoint
|
|
* @brief GetNearPoint
|
|
* 计算点到圆弧的最短距离,首先用点和圆弧中心点的直线与圆的交点,计算点到交点的距离,如果交点在圆弧上,则最短距离是交点之一,否则计算点到圆弧两个端点的距离。
|
|
* 计算点到圆弧的最短距离,首先用点和圆弧中心点的直线与圆的交点,计算点到交点的距离,如果交点在圆弧上,则最短距离是交点之一,否则计算点到圆弧两个端点的距离。
|
|
@@ -542,7 +602,7 @@ int GetNearPoint(const double x,const double y,OpenDrive * pxodr,Road ** pObjRoa
|
|
break;
|
|
break;
|
|
|
|
|
|
case 3:
|
|
case 3:
|
|
- dis = 100000.0;
|
|
|
|
|
|
+ dis = GetPoly3Dis((GeometryPoly3 *)pg,x,y,nx,ny,nh);
|
|
break;
|
|
break;
|
|
case 4:
|
|
case 4:
|
|
dis = GetParamPoly3Dis((GeometryParamPoly3 *)pg,x,y,nx,ny,nh);
|
|
dis = GetParamPoly3Dis((GeometryParamPoly3 *)pg,x,y,nx,ny,nh);
|
|
@@ -1049,6 +1109,65 @@ static std::vector<PlanPoint> getspiralpoint(GeometrySpiral * pspiral)
|
|
return xvectorPP;
|
|
return xvectorPP;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static std::vector<PlanPoint> getpoly3dpoint(GeometryPoly3 * ppoly)
|
|
|
|
+{
|
|
|
|
+ double x,y;
|
|
|
|
+ x = ppoly->GetX();
|
|
|
|
+ y = ppoly->GetY();
|
|
|
|
+ double A,B,C,D;
|
|
|
|
+ A = ppoly->GetA();
|
|
|
|
+ B = ppoly->GetB();
|
|
|
|
+ C = ppoly->GetC();
|
|
|
|
+ D = ppoly->GetD();
|
|
|
|
+ const double steplim = 0.1;
|
|
|
|
+ double du = steplim;
|
|
|
|
+ double u = 0;
|
|
|
|
+ double v = 0;
|
|
|
|
+ double oldx,oldy;
|
|
|
|
+ oldx = x;
|
|
|
|
+ oldy = y;
|
|
|
|
+ double xstart,ystart;
|
|
|
|
+ xstart = x;
|
|
|
|
+ ystart = y;
|
|
|
|
+ double hdgstart = ppoly->GetHdg();
|
|
|
|
+ double flen = 0;
|
|
|
|
+ std::vector<PlanPoint> xvectorPP;
|
|
|
|
+ PlanPoint pp;
|
|
|
|
+ pp.x = xstart;
|
|
|
|
+ pp.y = ystart;
|
|
|
|
+ pp.hdg = hdgstart;
|
|
|
|
+ pp.dis = 0;
|
|
|
|
+ pp.mS = ppoly->GetS();
|
|
|
|
+ xvectorPP.push_back(pp);
|
|
|
|
+ while(flen < ppoly->GetLength())
|
|
|
|
+ {
|
|
|
|
+ double fdis = 0;
|
|
|
|
+ v = A + B*u + C*u*u + D*u*u*u;
|
|
|
|
+ x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
|
|
|
|
+ y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
|
|
|
|
+ fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
|
|
|
|
+ double hdg = CalcHdg(QPointF(oldx,oldy),QPointF(x,y));
|
|
|
|
+ oldx = x;
|
|
|
|
+ oldy = y;
|
|
|
|
+ if(fdis>(steplim*2.0))du = du/2.0;
|
|
|
|
+ flen = flen + fdis;
|
|
|
|
+ u = u + du;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ pp.x = x;
|
|
|
|
+ pp.y = y;
|
|
|
|
+ pp.hdg = hdg;
|
|
|
|
+
|
|
|
|
+ // s = s+ dt;
|
|
|
|
+ pp.dis = flen;;
|
|
|
|
+ pp.mS = ppoly->GetS() + flen;
|
|
|
|
+ xvectorPP.push_back(pp);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return xvectorPP;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
static std::vector<PlanPoint> getparampoly3dpoint(GeometryParamPoly3 * parc)
|
|
static std::vector<PlanPoint> getparampoly3dpoint(GeometryParamPoly3 * parc)
|
|
{
|
|
{
|
|
double s = 0.1;
|
|
double s = 0.1;
|
|
@@ -1147,6 +1266,7 @@ std::vector<PlanPoint> GetPoint(Road * pRoad)
|
|
|
|
|
|
break;
|
|
break;
|
|
case 3:
|
|
case 3:
|
|
|
|
+ xvectorPP = getpoly3dpoint((GeometryPoly3 *)prg);
|
|
break;
|
|
break;
|
|
case 4:
|
|
case 4:
|
|
xvectorPP = getparampoly3dpoint((GeometryParamPoly3 *)prg);
|
|
xvectorPP = getparampoly3dpoint((GeometryParamPoly3 *)prg);
|
|
@@ -1341,6 +1461,7 @@ inline double getoff(int nlane,double s,std::vector<iv::lanewidthabcd> xvectorLW
|
|
double off = 0;
|
|
double off = 0;
|
|
double a,b,c,d;
|
|
double a,b,c,d;
|
|
if(xvectorIndex.size() == 0)return off;
|
|
if(xvectorIndex.size() == 0)return off;
|
|
|
|
+
|
|
for(i=0;i<(xvectorIndex.size()-1);i++)
|
|
for(i=0;i<(xvectorIndex.size()-1);i++)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -1364,7 +1485,8 @@ inline double getoff(int nlane,double s,std::vector<iv::lanewidthabcd> xvectorLW
|
|
d = xvectorLWA[xvectorIndex[i]].D;
|
|
d = xvectorLWA[xvectorIndex[i]].D;
|
|
off = off + (a + b*s + c*s*s + d*s*s*s)/2.0;
|
|
off = off + (a + b*s + c*s*s + d*s*s*s)/2.0;
|
|
if(nlane < 0) off = off*(-1.0);
|
|
if(nlane < 0) off = off*(-1.0);
|
|
-// std::cout<<"s is "<<s<<std::endl;
|
|
|
|
|
|
+ std::cout<<"s is "<<s<<std::endl;
|
|
|
|
+ std::cout<<" off is "<<off<<std::endl;
|
|
return off;
|
|
return off;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1606,6 +1728,84 @@ void CalcInLaneAvoid(pathsection xps,std::vector<PlanPoint> & xvectorPP,const do
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+double getoff(Road * pRoad,int nlane,const double s)
|
|
|
|
+{
|
|
|
|
+ int i;
|
|
|
|
+ int nLSCount = pRoad->GetLaneSectionCount();
|
|
|
|
+ double s_section = 0;
|
|
|
|
+
|
|
|
|
+ double foff = 0;
|
|
|
|
+
|
|
|
|
+ for(i=0;i<nLSCount;i++)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ LaneSection * pLS = pRoad->GetLaneSection(i);
|
|
|
|
+ if(i<(nLSCount -1))
|
|
|
|
+ {
|
|
|
|
+ if(pRoad->GetLaneSection(i+1)->GetS()<s)
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ s_section = pLS->GetS();
|
|
|
|
+ int nlanecount = pLS->GetLaneCount();
|
|
|
|
+ int j;
|
|
|
|
+ for(j=0;j<nlanecount;j++)
|
|
|
|
+ {
|
|
|
|
+ Lane * pLane = pLS->GetLane(j);
|
|
|
|
+
|
|
|
|
+ int k;
|
|
|
|
+ double s_lane = s-s_section;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(pLane->GetId() != 0)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ for(k=0;k<pLane->GetLaneWidthCount();k++)
|
|
|
|
+ {
|
|
|
|
+ if(k<(pLane->GetLaneWidthCount()-1))
|
|
|
|
+ {
|
|
|
|
+ if((pLane->GetLaneWidth(k+1)->GetS()+s_section)<s)
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ s_lane = pLane->GetLaneWidth(k)->GetS();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ LaneWidth * pLW = pLane->GetLaneWidth(k);
|
|
|
|
+ if(pLW == 0)
|
|
|
|
+ {
|
|
|
|
+ std::cout<<"not find LaneWidth"<<std::endl;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ double fds = s - s_lane - s_section;
|
|
|
|
+ double fwidth= pLW->GetA() + pLW->GetB() * fds
|
|
|
|
+ +pLW->GetC() * pow(fds,2) + pLW->GetD() * pow(fds,3);
|
|
|
|
+ if(nlane == pLane->GetId())
|
|
|
|
+ {
|
|
|
|
+ foff = foff + fwidth/2.0;
|
|
|
|
+ }
|
|
|
|
+ if((nlane*(pLane->GetId())>0)&&(abs(nlane)>abs(pLane->GetId())))
|
|
|
|
+ {
|
|
|
|
+ foff = foff + fwidth;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(nlane<0)foff = foff*(-1);
|
|
|
|
+ return foff;
|
|
|
|
+}
|
|
|
|
+
|
|
//暂不考虑多个LaneSection的情况,不考虑车道宽度变化
|
|
//暂不考虑多个LaneSection的情况,不考虑车道宽度变化
|
|
std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,const double fvehiclewidth)
|
|
std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,const double fvehiclewidth)
|
|
{
|
|
{
|
|
@@ -1681,7 +1881,9 @@ std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,
|
|
{
|
|
{
|
|
|
|
|
|
PlanPoint pp = xvPP.at(i);
|
|
PlanPoint pp = xvPP.at(i);
|
|
- off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
|
|
|
|
|
|
+// off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
|
|
|
|
+
|
|
|
|
+ off1 = getoff(xps.mpRoad,nlane1,pp.mS);
|
|
pp.x = pp.x + off1 *cos(pp.hdg + M_PI/2.0);
|
|
pp.x = pp.x + off1 *cos(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off1 *sin(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off1 *sin(pp.hdg + M_PI/2.0);
|
|
|
|
|
|
@@ -1699,8 +1901,10 @@ std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,
|
|
{
|
|
{
|
|
|
|
|
|
PlanPoint pp = xvPP.at(i);
|
|
PlanPoint pp = xvPP.at(i);
|
|
- off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
|
|
|
|
- off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
|
|
+// off1 = getoff(nlane1,pp.mS,xvectorLWA,xvectorindex1);
|
|
|
|
+// off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
+ off1 = getoff(xps.mpRoad,nlane1,pp.mS);
|
|
|
|
+ off2 = getoff(xps.mpRoad,nlane2,pp.mS);
|
|
double offx = off1 + (off2 - off1) *(i-nchange1 + nchangepoint/2)/nchangepoint;
|
|
double offx = off1 + (off2 - off1) *(i-nchange1 + nchangepoint/2)/nchangepoint;
|
|
pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
|
|
pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
|
|
@@ -1752,7 +1956,9 @@ std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,
|
|
for(i=(nchange1 + nchangepoint/2);i<(nchange2-nchangepoint/2);i++)
|
|
for(i=(nchange1 + nchangepoint/2);i<(nchange2-nchangepoint/2);i++)
|
|
{
|
|
{
|
|
PlanPoint pp = xvPP.at(i);
|
|
PlanPoint pp = xvPP.at(i);
|
|
- off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
|
|
+ // off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
+
|
|
|
|
+ off2 = getoff(xps.mpRoad,nlane2,pp.mS);
|
|
pp.x = pp.x + off2 *cos(pp.hdg + M_PI/2.0);
|
|
pp.x = pp.x + off2 *cos(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off2 *sin(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off2 *sin(pp.hdg + M_PI/2.0);
|
|
|
|
|
|
@@ -1770,8 +1976,11 @@ std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,
|
|
{
|
|
{
|
|
|
|
|
|
PlanPoint pp = xvPP.at(i);
|
|
PlanPoint pp = xvPP.at(i);
|
|
- off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
- off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
|
|
|
|
|
|
+// off2 = getoff(nlane2,pp.mS,xvectorLWA,xvectorindex2);
|
|
|
|
+// off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
|
|
|
|
+
|
|
|
|
+ off2 = getoff(xps.mpRoad,nlane2,pp.mS);
|
|
|
|
+ off3 = getoff(xps.mpRoad,nlane3,pp.mS);
|
|
double offx = off2 + (off3 - off2) *(i-nchange2 + nchangepoint/2)/nchangepoint;
|
|
double offx = off2 + (off3 - off2) *(i-nchange2 + nchangepoint/2)/nchangepoint;
|
|
pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
|
|
pp.x = pp.x + offx *cos(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + offx *sin(pp.hdg + M_PI/2.0);
|
|
@@ -1823,7 +2032,8 @@ std::vector<PlanPoint> GetLanePoint(pathsection xps,std::vector<PlanPoint> xvPP,
|
|
for(i=(nchange2 + nchangepoint/2);i<nsize;i++)
|
|
for(i=(nchange2 + nchangepoint/2);i<nsize;i++)
|
|
{
|
|
{
|
|
PlanPoint pp = xvPP.at(i);
|
|
PlanPoint pp = xvPP.at(i);
|
|
- off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
|
|
|
|
|
|
+ // off3 = getoff(nlane3,pp.mS,xvectorLWA,xvectorindex3);
|
|
|
|
+ off3 = getoff(xps.mpRoad,nlane3,pp.mS);
|
|
pp.x = pp.x + off3 *cos(pp.hdg + M_PI/2.0);
|
|
pp.x = pp.x + off3 *cos(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off3 *sin(pp.hdg + M_PI/2.0);
|
|
pp.y = pp.y + off3 *sin(pp.hdg + M_PI/2.0);
|
|
|
|
|