locate_algorithm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef _LOCATE_ALGORITHM_H
  2. #define _LOCATE_ALGORITHM_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "classdef.h"
  6. #include "tdoa/TDOAFunctor.h"
  7. #define M_PI 3.14159265358979323846 // 角度转弧度 角度 * pi / 180
  8. #define M_PI_2 1.57079632679489661923
  9. #define M_PI_4 0.785398163397448309616
  10. // 最终定位坐标计算公式
  11. void AOAformula(struct _coordinate* ant, double angle, struct _coordinate* tar, bool is_line = false, double z_offset = 0);
  12. // 两个坐标之间的距离计算公式
  13. double Distanceformula(struct _coordinate* ant, struct _coordinate* last);
  14. // 三点定位
  15. void locatebycordinate(struct _coordinate** coor_list, struct _coordinate* dest);
  16. // 定位算法
  17. void algorithm_locate(struct _coordinate** coor_list, int size, struct _coordinate* hist, struct _coordinate* dest, double dist_limit, double z_offset);
  18. void algorithm_locate_ex(_coordinate** coor_list, int coor_size, _coordinate* hist, _coordinate* dest, double dist_limit);
  19. double getAngleByCoordinate(_coordinate* p1, _coordinate* p2);
  20. double getAngleByAngle(_coordinate* p1, _coordinate* p2);
  21. double getDistance(_coordinate* p1, _coordinate *p2);
  22. _coordinate* getCross(_coordinate* p1, _coordinate* p2);
  23. void calcCoordinate(_coordinate* p1, double dist, double angle, _coordinate* dest);
  24. bool is_all_inline(_coordinate** coor_list, int cnt );
  25. void HeapSort(_coordinate** pCoordinateArray,int nLen);
  26. void BuildMaxHeap(_coordinate** pCoordinateArray,int nLen);
  27. void AdjustMaxHeap(_coordinate** pCoordinateArray,int n,int nHeapSize);
  28. void SwapElement(_coordinate* a,_coordinate*b);
  29. void SelectSort(_coordinate** pCoordinateArray,int nLen);
  30. //static double Pnt2SegmentDist(Point A, Point B, Point C,Point* pD = NULL)
  31. //{
  32. //
  33. // //AB为线段,C为点,pD为需要返回C距离AB最近的点,返回值为C到AB的距离
  34. //
  35. // //Dist为求两点之间的距离,第三个参数若是0不开方,若使用默认参数值1则需要开方。
  36. // Point AB = B - A; //向量AB
  37. // Point AC = C - A;
  38. // double r = AB.x * AC.x + AB.y * AC.y;//AB与AC的点乘积
  39. // r /= Dist(A,B,0);//AC在AB上的投影比上AB。调用Dist(),不开方
  40. // //若C的投影在AB外
  41. // if(r < 0)
  42. // {
  43. // if(pD)
  44. // *pD = A;
  45. // return Dist(A, C);//调用Dist(),开方
  46. // }
  47. // if(r > 1)
  48. // {
  49. // if(pD)
  50. // *pD = B;
  51. // return Dist(B, C);
  52. // }
  53. // //若C的投影在AB之间
  54. // Point D = AB;
  55. // D.x *= r;
  56. // D.y *= r;//因为AB是向量,所以可以这样做。得到AC在AB上的投影向量。
  57. // D.Offset(A);//点D的绝对坐标
  58. // if(pD)
  59. // {
  60. // *pD = D;
  61. // }
  62. // return Dist(C, D);
  63. //}
  64. /*
  65. * 定位算法
  66. *
  67. */
  68. class LocateAlgorithm{
  69. public:
  70. //TOF算法函数
  71. static POS* Pos(ReaderPathMap rpm,int sta_num,int ant,double dist,INFO_PRE info_pre);
  72. static SOLUTION* GetPos(ReaderPathMap rpm,int sta_num,int ant,double dist,int i);
  73. //TDOA算法函数
  74. static std::unique_ptr<POS> Pos(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm);
  75. static std::unique_ptr<POS> LocatePos(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm);
  76. static std::shared_ptr<POS> Pos(std::shared_ptr<POS> pos,std::shared_ptr<TDOAReaderPathMap> trpm);
  77. static std::shared_ptr<POS> MappingToPath(std::shared_ptr<POS> pos, std::shared_ptr<TDOAReaderPathMap> trpm);
  78. static std::shared_ptr<POS> TdoaLocate2d(std::shared_ptr<ReceiveDataMap> pRdm);
  79. static std::unique_ptr<POS> CalcCardPosition(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm);
  80. static std::unique_ptr<SOLUTION> GetPos(std::shared_ptr<ReaderPath> pRP,double dist,int i);
  81. static bool CheckPosInValid(POS* pos,ReceiveDataMap* pRdm,double dScale);
  82. static bool IsOnMap(std::shared_ptr<POS>& pos,std::shared_ptr<TDOAReaderPathMap> trpm);
  83. static bool IsInTriangle(std::vector<_point> vtp,_point p);
  84. static double GetTriangleArea(_point p0,_point p1,_point p2);
  85. static bool IsInLine(_point p,_point start_p,_point end_p);
  86. static bool PointIsInRect(point p,point tp,point lp,point bp,point rp);
  87. //
  88. static int CalcTdoaPosition(std::shared_ptr<ReceiveDataMap> pRdm,std::shared_ptr<TDOAReaderPathMap> trpm,std::vector<std::shared_ptr<POS>>& udm_pos);
  89. };
  90. #endif