|
@@ -0,0 +1,323 @@
|
|
|
+#include "sissunmap.h"
|
|
|
+
|
|
|
+#include "math.h"
|
|
|
+
|
|
|
+sissunmap::sissunmap()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+double sissunmap::GetPointDis(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2)
|
|
|
+{
|
|
|
+ double x1,y1,x2,y2;
|
|
|
+ GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
|
|
|
+ GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
|
|
|
+ return sqrt(pow(x2-x1,2)+pow(y2-y1,2));
|
|
|
+}
|
|
|
+
|
|
|
+double sissunmap::GetHdg(iv::siasun::waypoint * p1,iv::siasun::waypoint * p2)
|
|
|
+{
|
|
|
+ double x0,y0,x1,y1;
|
|
|
+ GaussProjCal(p1->mflon(),p1->mflat(),&x0,&y0);
|
|
|
+ GaussProjCal(p2->mflon(),p2->mflat(),&x1,&y1);
|
|
|
+
|
|
|
+ if(x0 == x1)
|
|
|
+ {
|
|
|
+ if(y0 < y1)
|
|
|
+ {
|
|
|
+ return M_PI/2.0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return M_PI*3.0/2.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ double ratio = (y1-y0)/(x1-x0);
|
|
|
+
|
|
|
+ double hdg = atan(ratio);
|
|
|
+
|
|
|
+ if(ratio > 0)
|
|
|
+ {
|
|
|
+ if(y1 > y0)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hdg = hdg + M_PI;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(y1 > y0)
|
|
|
+ {
|
|
|
+ hdg = hdg + M_PI;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hdg = hdg + 2.0*M_PI;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return hdg;
|
|
|
+}
|
|
|
+
|
|
|
+bool sissunmap::CheckPointNear(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ for(i=0;i<(int)xvectorpointindex.size();i++)
|
|
|
+ {
|
|
|
+ iv::siasun::waypoint * p2 = ppointarray->mutable_mwaypoint(xvectorpointindex[i]);
|
|
|
+ double fdis = GetPointDis(p,p2);
|
|
|
+ if(fdis<mfDisMin)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+double sissunmap::GetPoint2LineCrossDis(QPointF xpoint, QPointF linepoint1, QPointF linepoint2,double & spos,int & nnear,bool & bright)
|
|
|
+{
|
|
|
+
|
|
|
+ double spp = (linepoint1.x()-xpoint.x())*(linepoint2.y()-xpoint.y())-(linepoint1.y()-xpoint.y())*(linepoint2.x()-xpoint.x()) ;
|
|
|
+ if(spp>0)
|
|
|
+ {
|
|
|
+ bright = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bright = true;
|
|
|
+ }
|
|
|
+ double xc,yc,fdis;
|
|
|
+ if(linepoint1.x() == linepoint2.x())
|
|
|
+ {
|
|
|
+ xc = linepoint1.x();
|
|
|
+ yc = xpoint.y();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double k, b;/*y=kx+b*/
|
|
|
+ k = (linepoint2.y() - linepoint1.y()) / (linepoint2.x() - linepoint1.x());
|
|
|
+ b = linepoint2.y() - linepoint2.x() * k;
|
|
|
+
|
|
|
+ double A,B,C;
|
|
|
+ A= k;
|
|
|
+ B = -1;
|
|
|
+ C = b;
|
|
|
+
|
|
|
+ xc = (B*B*xpoint.x() - A*B*xpoint.y() - A*C)/(A*A + B*B);
|
|
|
+ yc = (A*A*xpoint.y() - A*B*xpoint.x() - B*C)/(A*A + B*B); //https://blog.csdn.net/hbuxiaoshe/article/details/5889366
|
|
|
+ }
|
|
|
+
|
|
|
+ fdis = sqrt(pow(xc - xpoint.x(),2) + pow(yc - xpoint.y(),2));
|
|
|
+ if((xc - linepoint1.x())*(xc-linepoint2.x())<=0)
|
|
|
+ {
|
|
|
+
|
|
|
+ spos = sqrt(pow(xc - linepoint1.x(),2)+pow(yc-linepoint1.y(),2));
|
|
|
+ nnear = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double fdis1 = sqrt(pow(linepoint1.x() - xpoint.x(),2)+pow(linepoint1.y() - xpoint.y(),2));
|
|
|
+ double fdis2 = sqrt(pow(linepoint2.x()-xpoint.x(),2)+pow(linepoint2.y()-xpoint.y(),2));
|
|
|
+ if(fdis1<fdis2)
|
|
|
+ {
|
|
|
+ nnear = 1;
|
|
|
+ spos = -sqrt(pow(xc - linepoint1.x(),2)+pow(yc-linepoint1.y(),2));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nnear = 2;
|
|
|
+ spos = -sqrt(pow(xc - linepoint2.x(),2)+pow(yc-linepoint2.y(),2));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(spp<0)fdis = fdis * (-1.0); //right, dis < 0;
|
|
|
+ return fdis;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int sissunmap::JustPointPos(std::vector<int> & xvectorpointindex,iv::siasun::waypointarray * ppointarray,iv::siasun::waypoint * p)
|
|
|
+{
|
|
|
+ if(xvectorpointindex.size() <= 1)return 1;
|
|
|
+ int index1min = -1;
|
|
|
+ int index2min = -1;
|
|
|
+ double fdis1min = 1000000000.0;
|
|
|
+ double fdis2min = 1000000000.0;
|
|
|
+ int i;
|
|
|
+ for(i=0;i<(int)xvectorpointindex.size();i++)
|
|
|
+ {
|
|
|
+ double fdis = GetPointDis(ppointarray->mutable_mwaypoint(xvectorpointindex[i]),p);
|
|
|
+ if(index1min == -1)
|
|
|
+ {
|
|
|
+ index1min = i;
|
|
|
+ fdis1min = fdis;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(index2min == -1)
|
|
|
+ {
|
|
|
+ if(fdis<fdis1min)
|
|
|
+ {
|
|
|
+ index2min = index1min;
|
|
|
+ fdis2min = fdis1min;
|
|
|
+ index1min = i;
|
|
|
+ fdis1min = fdis;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ index2min = i;
|
|
|
+ fdis2min = fdis;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(fdis<fdis1min)
|
|
|
+ {
|
|
|
+ index2min = index1min;
|
|
|
+ fdis2min = fdis1min;
|
|
|
+ index1min = i;
|
|
|
+ fdis1min = fdis;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(fdis<fdis2min)
|
|
|
+ {
|
|
|
+ index2min = i;
|
|
|
+ fdis2min = fdis;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(index1min>index2min)
|
|
|
+ {
|
|
|
+ int temindex;
|
|
|
+ double fdistem;
|
|
|
+ temindex = index1min;
|
|
|
+ fdistem = fdis1min;
|
|
|
+ fdis1min = fdis2min;
|
|
|
+ index1min = index2min;
|
|
|
+ fdis2min = fdistem;
|
|
|
+ index2min = temindex;
|
|
|
+ }
|
|
|
+
|
|
|
+ double x,y;
|
|
|
+ double x1,y1;
|
|
|
+ double x2,y2;
|
|
|
+ iv::siasun::waypoint * p1 = ppointarray->mutable_mwaypoint(xvectorpointindex[index1min]);
|
|
|
+ iv::siasun::waypoint * p2 = ppointarray->mutable_mwaypoint(xvectorpointindex[index2min]);
|
|
|
+ GaussProjCal(p->mflon(),p->mflat(),&x,&y);
|
|
|
+ GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
|
|
|
+ GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
|
|
|
+
|
|
|
+ double spos;
|
|
|
+ int near;
|
|
|
+ bool bright;
|
|
|
+ GetPoint2LineCrossDis(QPointF(x,y),QPointF(x1,y1),QPointF(x2,y2),spos,near,bright);
|
|
|
+
|
|
|
+ if(near == 0)return index2min;
|
|
|
+ if(near == 1)return index1min;
|
|
|
+ return index2min+1;
|
|
|
+}
|
|
|
+
|
|
|
+std::vector<iv::mapline> sissunmap::GetMapLine(iv::siasun::map *psiamap)
|
|
|
+{
|
|
|
+ std::vector<iv::mapline> xvectormapline;
|
|
|
+ iv::mapline xmapline;
|
|
|
+ iv::siasun::waypointarray * pwayarray = psiamap->mutable_mwayarray();
|
|
|
+
|
|
|
+ if(pwayarray == NULL)return xvectormapline;
|
|
|
+
|
|
|
+ std::vector<int> xvectorpointindex;
|
|
|
+ int index = 0;
|
|
|
+
|
|
|
+ xvectorpointindex.push_back(0);
|
|
|
+ iv::siasun::waypoint * ppoint;
|
|
|
+
|
|
|
+ for(index =1;index<pwayarray->mwaypoint_size();index++)
|
|
|
+ {
|
|
|
+ ppoint = pwayarray->mutable_mwaypoint(index);
|
|
|
+ if(ppoint == NULL)return xvectormapline;
|
|
|
+
|
|
|
+ bool bPointNear = CheckPointNear(xvectorpointindex,pwayarray,ppoint);
|
|
|
+ if(bPointNear == false)
|
|
|
+ {
|
|
|
+ xvectorpointindex.push_back(index);
|
|
|
+ index++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ int i;
|
|
|
+ for(i=index;i<pwayarray->mwaypoint_size();i++)
|
|
|
+ {
|
|
|
+ ppoint = pwayarray->mutable_mwaypoint(i);
|
|
|
+ if(ppoint == NULL)return xvectormapline;
|
|
|
+
|
|
|
+ bool bPointNear = CheckPointNear(xvectorpointindex,pwayarray,ppoint);
|
|
|
+ if(bPointNear == true)
|
|
|
+ {
|
|
|
+ std::cout<<" point at "<<i<<" is near exist point. "<<std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int npos = JustPointPos(xvectorpointindex,pwayarray,ppoint);
|
|
|
+ if(npos>= xvectorpointindex.size())xvectorpointindex.push_back(i);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ xvectorpointindex.insert(xvectorpointindex.begin()+npos,i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// for(i=0;i<(int)xvectorpointindex.size();i++)
|
|
|
+// {
|
|
|
+// std::cout<<" i: "<<i<<" index: "<<xvectorpointindex[i]<<std::endl;
|
|
|
+// }
|
|
|
+
|
|
|
+ for(i=1;i<(int)xvectorpointindex.size();i++)
|
|
|
+ {
|
|
|
+ iv::mapline xmapline;
|
|
|
+ iv::siasun::waypoint * p1 = pwayarray->mutable_mwaypoint(xvectorpointindex[i-1]);
|
|
|
+ iv::siasun::waypoint * p2 = pwayarray->mutable_mwaypoint(xvectorpointindex[i]);
|
|
|
+ double x1,y1,x2,y2;
|
|
|
+ GaussProjCal(p1->mflon(),p1->mflat(),&x1,&y1);
|
|
|
+ GaussProjCal(p2->mflon(),p2->mflat(),&x2,&y2);
|
|
|
+ xmapline.mfLat1 = p1->mflat();
|
|
|
+ xmapline.mfLon1 = p1->mflon();
|
|
|
+ xmapline.mfLat2 = p2->mflat();
|
|
|
+ xmapline.mfLon2 = p2->mflon();
|
|
|
+ xmapline.mfx1 = x1;
|
|
|
+ xmapline.mfy1 = y1;
|
|
|
+ xmapline.mfx2 = x2;
|
|
|
+ xmapline.mfy2 = y2;
|
|
|
+ xvectormapline.push_back(xmapline);
|
|
|
+ }
|
|
|
+
|
|
|
+ return xvectormapline;
|
|
|
+
|
|
|
+// iv::siasun::waypoint * ppoint = pwayarray->mutable_mwaypoint(index);
|
|
|
+// if(ppoint == NULL)return xvectormapline;
|
|
|
+
|
|
|
+// double fLat = ppoint->mflat();
|
|
|
+// double fLon = ppoint->mflon();
|
|
|
+// double x,y;
|
|
|
+// GaussProjCal(fLon,fLat,&x,&y);
|
|
|
+// xmapline.mfLat1 = fLat;
|
|
|
+// xmapline.mfLon1 = fLon;
|
|
|
+// xmapline.mfx1 = x;
|
|
|
+// xmapline.mfy1 = y;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// for(index =1;index<pwayarray->mwaypoint_size();index++)
|
|
|
+// {
|
|
|
+// ppoint = pwayarray->mutable_mwaypoint(index);
|
|
|
+// if(ppoint == NULL)return xvectormapline;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+}
|