distance.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // 秒寻科技
  2. // 队列排序
  3. // 周涛
  4. // 2023-03-04
  5. #include "../includes/includes.h"
  6. // 计算两点之间的距离
  7. // 输入参数,单位厘米
  8. // 返回参数,单位米
  9. flt32 util_distance_cal_p2p_distance(int32 x1, int32 y1, int32 x2, int32 y2)
  10. {
  11. flt32 fDistance = 0.0;
  12. flt32 xx = (flt32)(x1 - x2) / 100;
  13. flt32 yy = (flt32)(y1 - y2) / 100;
  14. fDistance = (flt32)sqrt(xx * xx + yy * yy);
  15. return fDistance;
  16. }
  17. // 计算两点之间的距离
  18. // 输入参数,单位厘米
  19. // 返回参数,单位米
  20. flt32 util_distance_cal_p2p_space_distance(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2)
  21. {
  22. flt32 fDistance = 0.0;
  23. flt32 xx = (flt32)(x1 - x2);
  24. flt32 yy = (flt32)(y1 - y2);
  25. flt32 zz = (flt32)(z1 - z2);
  26. fDistance = (flt32)sqrt(xx * xx + yy * yy + zz * zz);
  27. fDistance /= 100;
  28. return fDistance;
  29. }
  30. // 根据一个数,在该数左右两侧范围内生成一个随机数
  31. // dwBaseData:基数
  32. // wRange:单边偏移
  33. int32 util_distance_gen_rand_num(int32 dwBaseData, uint16 wRange)
  34. {
  35. int32 dwTotalRange = 2 * wRange + 1; // 总范围
  36. int32 dwRemainder = 0;
  37. int32 randomNum = 0; // 随机数
  38. // 初始化随机数生成器
  39. srand(time(NULL));
  40. // 生成随机数
  41. dwRemainder = rand() % dwTotalRange; // 生成 [0, dwTotalRange) 范围内的随机数
  42. randomNum = dwBaseData - wRange + dwRemainder; // 生成所需的随机数
  43. return randomNum;
  44. }