诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.0 KiB

  1. #include "stdafx.h"
  2. #include "ZuoBiao.h"
  3. #include <math.h>
  4. #include "stdlib.h"
  5. //WGS-84椭球体参数
  6. const double a = 6378137.0;//长半轴
  7. const double flattening = 1 / 298.257223563;//扁率
  8. const double delta = 0.0000001;
  9. // 两个数的差的平方,坐标差的平方。
  10. inline double diffsqr(double x1, double x2){
  11. return (x1 - x2)* (x1 - x2);
  12. }
  13. //直接坐标表示,求距离
  14. inline double distance(double x1, double y1, double z1
  15. , double x2, double y2, double z2)
  16. {
  17. return sqrt(diffsqr(x1, x2) + diffsqr(y1, y2) + diffsqr(z1, z2));
  18. }
  19. //点表示,求距离
  20. double distance(const CRDCARTESIAN &p1, const CRDCARTESIAN &p2)
  21. {
  22. return sqrt(diffsqr(p1.x, p2.x) + diffsqr(p1.y, p2.y) + diffsqr(p1.z, p2.z));
  23. }
  24. //pcc:指向所转换出的笛卡尔坐标的指针;
  25. //pcg:指向待转换的大地坐标的指针;
  26. //dSemiMajorAxis:参考椭球的长半轴;
  27. //dFlattening:参考椭球的扁率。
  28. //由大地坐标转换为笛卡尔坐标
  29. void GeodeticToCartesian(PCRDCARTESIAN pcc, PCRDGEODETIC pcg, double dSemiMajorAxis, double dFlattening)
  30. {
  31. double e2;//第一偏心率的平方
  32. double N;//卯酉圈半径
  33. e2 = 2 * dFlattening - dFlattening*dFlattening;
  34. N = dSemiMajorAxis / sqrt(1 - e2*sin(pcg->latitude)*sin(pcg->latitude));
  35. pcc->x = (N + pcg->height)*cos(pcg->latitude)*cos(pcg->longitude);
  36. pcc->y = (N + pcg->height)*cos(pcg->latitude)*sin(pcg->longitude);
  37. pcc->z = (N*(1 - e2) + pcg->height)*sin(pcg->latitude);
  38. }
  39. //获取两个经纬度之间距离
  40. //经度
  41. //维度
  42. double GetJuLi(double longitude1, double latitude1, double longitude2, double latitude2)
  43. {
  44. double dRet = 0;
  45. tagCRDGEODETIC aa;
  46. aa.height = 0;
  47. aa.longitude = longitude1;
  48. aa.latitude = latitude1;
  49. CRDCARTESIAN bb;
  50. bb.x = 0;
  51. bb.y = 0;
  52. bb.z = 0;
  53. tagCRDGEODETIC cc;
  54. cc.height = 0;
  55. cc.longitude = longitude2;
  56. cc.latitude = latitude2;
  57. CRDCARTESIAN dd;
  58. dd.x = 0;
  59. dd.y = 0;
  60. bb.z = 0;
  61. try
  62. {
  63. GeodeticToCartesian(&bb, &aa, a, flattening);
  64. GeodeticToCartesian(&dd, &cc, a, flattening);
  65. dRet = distance(bb, dd);
  66. }
  67. catch (...)
  68. {
  69. dRet = 100;
  70. }
  71. return dRet;
  72. }