|
@@ -2008,26 +2008,199 @@ void Road::ResetPriority()
|
|
|
|
|
|
double Road::GetDis(const double x,const double y, const double hdg, double & fRefDis, double & fHdgDiff, int & nlane,double & s,double & refx,double & refy,double & refhdg)
|
|
|
{
|
|
|
-// unsigned int ngbsize = static_cast<unsigned int >(mGeometryBlockVector.size());
|
|
|
-// unsigned int i;
|
|
|
-// double fdismin = 1000000.0;
|
|
|
-// for(i=0;i<ngbsize;i++)
|
|
|
-// {
|
|
|
-// GeometryBlock * pgb = GetGeometryBlock(i);
|
|
|
-// RoadGeometry * pg;
|
|
|
-// pg = pgb->GetGeometryAt(0);
|
|
|
-// double xstart,ystart;
|
|
|
-// xstart = pg->GetX();
|
|
|
-// ystart = pg->GetY();
|
|
|
-// double fdisstart = sqrt(pow(xstart - x,2) + pow(ystart - y,2));
|
|
|
-
|
|
|
-// if(fdis)
|
|
|
-
|
|
|
-// if(fdisstart<(100.0 + pg->GetLength()))
|
|
|
-// {
|
|
|
-
|
|
|
-// }
|
|
|
-// }
|
|
|
+ unsigned int ngbsize = static_cast<unsigned int >(mGeometryBlockVector.size());
|
|
|
+ unsigned int i;
|
|
|
+ double fdismin = 1000000.0;
|
|
|
+ for(i=0;i<ngbsize;i++)
|
|
|
+ {
|
|
|
+ GeometryBlock * pgb = GetGeometryBlock(i);
|
|
|
+ RoadGeometry * pg;
|
|
|
+ pg = pgb->GetGeometryAt(0);
|
|
|
+ double xstart,ystart;
|
|
|
+ xstart = pg->GetX();
|
|
|
+ ystart = pg->GetY();
|
|
|
+ double fdisstart = sqrt(pow(xstart - x,2) + pow(ystart - y,2));
|
|
|
+ double sstart = pg->GetS();
|
|
|
+ double geolen = pg->GetLength();
|
|
|
+
|
|
|
+ if(fdismin > fdisstart)
|
|
|
+ {
|
|
|
+ fdismin = fdisstart;
|
|
|
+ fRefDis = fdismin;
|
|
|
+ nlane = 1000;
|
|
|
+ s = sstart;
|
|
|
+ refx = xstart;
|
|
|
+ refy = ystart;
|
|
|
+ refhdg = pg->GetHdg();
|
|
|
+ fHdgDiff = hdg - refhdg;
|
|
|
+ if(fHdgDiff<(-M_PI))fHdgDiff = fHdgDiff + 2.0*M_PI;
|
|
|
+ if(fHdgDiff>M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fdisstart<(100.0 + geolen))
|
|
|
+ {
|
|
|
+ double fstep = 0.1;
|
|
|
+ double fsnow = 0.1;
|
|
|
+ while(fsnow<=geolen)
|
|
|
+ {
|
|
|
+ double xnow,ynow,hdgnow;
|
|
|
+ GetGeometryCoords(fsnow,xnow,ynow,hdgnow);
|
|
|
+ fsnow = fsnow + fstep;
|
|
|
+ double fdisnow = sqrt(pow(xnow - x,2)+pow(ynow - y,2));
|
|
|
+ if(fdisnow < fdismin)
|
|
|
+ {
|
|
|
+ fdismin = fdisnow;;
|
|
|
+ fRefDis = fdismin;
|
|
|
+ nlane = 1000;
|
|
|
+ s = fsnow;
|
|
|
+ refx = xnow;
|
|
|
+ refy = ynow;
|
|
|
+ refhdg = hdgnow;
|
|
|
+ fHdgDiff = hdg - hdgnow;
|
|
|
+ if(fHdgDiff<(-M_PI))fHdgDiff = fHdgDiff + 2.0*M_PI;
|
|
|
+ if(fHdgDiff>M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ double frealdis = fRefDis;
|
|
|
+
|
|
|
+ if(fdismin < 100.0)
|
|
|
+ {
|
|
|
+ double fOffset = GetLaneOffsetValue(s);
|
|
|
+ double realx,realy,realhdg;
|
|
|
+ realhdg = refhdg;
|
|
|
+ if(fabs(fOffset)<0.00001)
|
|
|
+ {
|
|
|
+ realx = refx;
|
|
|
+ realy = refy;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ realx = refx + fOffset * cos(refhdg + M_PI/2.0);
|
|
|
+ realy = refy + fOffset * sin(refhdg + M_PI/2.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if((fabs(realx - x)<0.001)&&(fabs(realy - y)<0.001))
|
|
|
+ {
|
|
|
+ if(GetRightDrivingLaneCount(s)>0)
|
|
|
+ {
|
|
|
+ nlane = -1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(GetLeftDrivingLaneCount(s)>0)
|
|
|
+ {
|
|
|
+ nlane = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nlane = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double x0,y0,x1,y1;
|
|
|
+ x0 = realx;
|
|
|
+ y0 = realy;
|
|
|
+ x1 = x;
|
|
|
+ y1 = y;
|
|
|
+ double hdgpoint;
|
|
|
+ if(x0 == x1)
|
|
|
+ {
|
|
|
+ if(y0 < y1)
|
|
|
+ {
|
|
|
+ hdgpoint = M_PI/2.0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ hdgpoint = M_PI*3.0/2.0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double ratio = (y1-y0)/(x1-x0);
|
|
|
+ double hdgpoint = atan(ratio);
|
|
|
+ if(ratio > 0)
|
|
|
+ {
|
|
|
+ if(y1 > y0)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hdgpoint = hdg + M_PI;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(y1 > y0)
|
|
|
+ {
|
|
|
+ hdgpoint = hdg + M_PI;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hdgpoint = hdg + 2.0*M_PI;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ hdgpoint = hdgpoint - refhdg;
|
|
|
+
|
|
|
+ while(hdgpoint>=M_PI)hdgpoint = hdgpoint -2.0*M_PI;
|
|
|
+ while(hdgpoint <(-M_PI))hdgpoint = hdgpoint +2.0*M_PI;
|
|
|
+
|
|
|
+ frealdis = sqrt(pow(realx - x,2)+pow(realy - y,2));
|
|
|
+
|
|
|
+ if(hdgpoint > 0)
|
|
|
+ {
|
|
|
+ if(GetLeftDrivingLaneCount(s)>0)
|
|
|
+ {
|
|
|
+ std::vector<double> fvectorwidth = GetDrivingLaneWidthVector(s,1);
|
|
|
+ if(fvectorwidth.size()>0)
|
|
|
+ {
|
|
|
+ unsigned int i;
|
|
|
+ unsigned int nwidthsize = fvectorwidth.size();
|
|
|
+ for(i=0;i<nwidthsize;i++)
|
|
|
+ {
|
|
|
+ frealdis = frealdis - fvectorwidth[i];
|
|
|
+ if(frealdis<=0)
|
|
|
+ {
|
|
|
+ nlane = static_cast<int>(i+1);
|
|
|
+ frealdis = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(GetRightDrivingLaneCount(s)>0)
|
|
|
+ {
|
|
|
+ std::vector<double> fvectorwidth = GetDrivingLaneWidthVector(s,2);
|
|
|
+ if(fvectorwidth.size()>0)
|
|
|
+ {
|
|
|
+ unsigned int i;
|
|
|
+ unsigned int nwidthsize = fvectorwidth.size();
|
|
|
+ for(i=0;i<nwidthsize;i++)
|
|
|
+ {
|
|
|
+ frealdis = frealdis - fvectorwidth[i];
|
|
|
+ if(frealdis<=0)
|
|
|
+ {
|
|
|
+ nlane = (static_cast<int>(i+1))*(-1);
|
|
|
+ frealdis = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return frealdis;
|
|
|
}
|
|
|
|
|
|
|