geomatry.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef GEOMATRY_H
  2. #define GEOMATRY_H
  3. #include <stdbool.h>
  4. //二维坐标或向量
  5. typedef struct
  6. {
  7. float x;
  8. float y;
  9. } Coords2df;
  10. //二维坐标或向量
  11. typedef struct
  12. {
  13. int x;
  14. int y;
  15. } Coords2dint;
  16. //三维坐标或向量
  17. typedef struct
  18. {
  19. float x;
  20. float y;
  21. float z;
  22. } Coords3df;
  23. //三维坐标或向量
  24. typedef struct
  25. {
  26. int x;
  27. int y;
  28. int z;
  29. } Coords3dint;
  30. typedef struct
  31. {
  32. double x;
  33. double y;
  34. } Coords2ddouble;
  35. typedef struct
  36. {
  37. double x;
  38. double y;
  39. double z;
  40. } Coords3ddouble;
  41. typedef Coords2df Vector2df;
  42. typedef Coords2ddouble Vector2ddouble;
  43. typedef Coords3df Vector3df;
  44. typedef Coords3ddouble Vector3ddouble;
  45. typedef Coords2dint Vector2dint;
  46. typedef Coords3dint Vector3dint;
  47. // 两直线相交
  48. Coords2df lineInterLine(const Vector3ddouble *lineParama,
  49. const Vector3ddouble *lineParamb);
  50. // 两点求直线方程
  51. Vector3ddouble calLineEquation(const Coords2ddouble *pa,
  52. const Coords2ddouble *pb);
  53. // 求点是否在多边行内
  54. bool PointInPolygon(const Coords3dint *point, const Coords3dint *polygon,
  55. int count);
  56. // 求二维平面点到线段的最短距离
  57. void PointToSegmentDist(const Coords2dint *p, const Coords2dint *segment_a,
  58. const Coords2dint *segment_b, float *dist,
  59. float *angle);
  60. // 求点到多边形的最短距离
  61. void PointToPolygonDist(const Coords3dint *p, const Coords3dint *polygon,
  62. int count, float *dist, float *angle);
  63. void Cal_LngLat_To_FlatM_Ratio(double lat, double lng, double *ratiox,
  64. double *ratioy);
  65. void LanLat_To_Flat_Dist_Bearing(int lon1, int lat1, int lon2, int lat2,
  66. double lonToM, double latToM, float *dist_m,
  67. float *bearing_rad);
  68. #endif