EnterTjunction.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "cicv-data-closedloop/pjisuv_msgs"
  4. "math"
  5. )
  6. func Topic() string {
  7. return "/cicv_location"
  8. }
  9. // Label todo 禁止存在下划线_
  10. func Label() string {
  11. return "EnterTjunction"
  12. }
  13. type Point struct {
  14. Latitude float64
  15. Longitude float64
  16. }
  17. var (
  18. count2 int = 0
  19. //定义园区部门T字路口的经纬度坐标值
  20. point3 = Point{39.73040966605621, 116.48995329696209}
  21. point4 = Point{39.73083727413453, 116.49079780188244}
  22. point5 = Point{39.72976753711939, 116.49043130389033}
  23. point6 = Point{39.73012466515933, 116.49128381717591}
  24. point7 = Point{39.729251498328246, 116.49077484625299}
  25. point8 = Point{39.72964529630643, 116.49164592200161}
  26. pointlist = []Point{point3, point4, point5, point6, point7, point8}
  27. )
  28. func Rule(data *pjisuv_msgs.PerceptionLocalization) string {
  29. if count2%10 == 0 {
  30. enterflag := IfEnter(pointlist, 12.0, data.Latitude, data.Longitude)
  31. if enterflag {
  32. //eventLabel := "EnterTjunction"
  33. //fmt.Println(eventLabel)
  34. return "EnterTjunction"
  35. }
  36. }
  37. count2++
  38. return ""
  39. }
  40. func IfEnter(pointlist []Point, radius float64, lat, lon float64) bool {
  41. // 判断是否进入点列表中的区域
  42. point1 := Point{Latitude: lat, Longitude: lon}
  43. for _, point := range pointlist {
  44. d := distance(point1, point)
  45. if d <= radius {
  46. return true
  47. }
  48. }
  49. return false
  50. }
  51. // 计算两点之间的距离(米)
  52. func distance(point1, point2 Point) float64 {
  53. // 经纬度转弧度
  54. lat1 := point1.Latitude * math.Pi / 180
  55. lon1 := point1.Longitude * math.Pi / 180
  56. lat2 := point2.Latitude * math.Pi / 180
  57. lon2 := point2.Longitude * math.Pi / 180
  58. // 计算距离
  59. dlon := lon2 - lon1
  60. dlat := lat2 - lat1
  61. a := math.Sin(dlat/2)*math.Sin(dlat/2) + math.Sin(dlon/2)*math.Sin(dlon/2)*math.Cos(lat1)*math.Cos(lat2)
  62. c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
  63. d := 6371000 * c
  64. return d
  65. }