|
@@ -20,7 +20,18 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+type Point struct {
|
|
|
|
+ x, y float64
|
|
|
|
+}
|
|
|
|
+
|
|
var (
|
|
var (
|
|
|
|
+ //定义了车间四个边界点,将车间抽象成一个四边形
|
|
|
|
+ vertices = []Point{
|
|
|
|
+ {x: 456128.413, y: 4397847.78},
|
|
|
|
+ {x: 456288.257, y: 4397953.51},
|
|
|
|
+ {x: 456359.022, y: 4397822.84},
|
|
|
|
+ {x: 456191.065, y: 4397733.3},
|
|
|
|
+ }
|
|
cicvLocationTime = time.Now()
|
|
cicvLocationTime = time.Now()
|
|
// -----------------------------共享变量
|
|
// -----------------------------共享变量
|
|
// /tpperception
|
|
// /tpperception
|
|
@@ -597,7 +608,9 @@ func ProduceWindow() {
|
|
shareVars.Store("PositionYOfCicvLocation", data.PositionY)
|
|
shareVars.Store("PositionYOfCicvLocation", data.PositionY)
|
|
// 用于判断是否在车间内
|
|
// 用于判断是否在车间内
|
|
if time.Since(cicvLocationTime).Seconds() > 1 {
|
|
if time.Since(cicvLocationTime).Seconds() > 1 {
|
|
- shareVars.Store("key", "value")
|
|
|
|
|
|
+ p := Point{x: data.PositionX, y: data.PositionY}
|
|
|
|
+ OutsideWorkshopFlag := isPointInPolygon(p, vertices) //在车间返回0,不在车间返回1
|
|
|
|
+ shareVars.Store("OutsideWorkshopFlag", OutsideWorkshopFlag)
|
|
cicvLocationTime = time.Now()
|
|
cicvLocationTime = time.Now()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -1893,3 +1906,51 @@ func getTopicsOfNode(faultLabel string) (masterTopics []string, slaveTopics []st
|
|
}
|
|
}
|
|
return masterTopics, slaveTopics
|
|
return masterTopics, slaveTopics
|
|
}
|
|
}
|
|
|
|
+func isPointInPolygon(p Point, vertices []Point) bool {
|
|
|
|
+ intersections := 0
|
|
|
|
+ for i := 0; i < len(vertices); i++ {
|
|
|
|
+ j := (i + 1) % len(vertices)
|
|
|
|
+ if rayIntersectsSegment(p, vertices[i], vertices[j]) {
|
|
|
|
+ intersections++
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return !(intersections%2 == 1)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func rayIntersectsSegment(p, p1, p2 Point) bool {
|
|
|
|
+ if p1.y > p2.y {
|
|
|
|
+ p1, p2 = p2, p1
|
|
|
|
+ }
|
|
|
|
+ if p.y == p1.y || p.y == p2.y {
|
|
|
|
+ p.y += 0.0001
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if p.y < p1.y || p.y > p2.y {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if p.x > max(p1.x, p2.x) {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if p.x < min(p1.x, p2.x) {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ blueSlope := (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y) + p1.x
|
|
|
|
+ return p.x < blueSlope
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func min(a, b float64) float64 {
|
|
|
|
+ if a < b {
|
|
|
|
+ return a
|
|
|
|
+ }
|
|
|
|
+ return b
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func max(a, b float64) float64 {
|
|
|
|
+ if a > b {
|
|
|
|
+ return a
|
|
|
|
+ }
|
|
|
|
+ return b
|
|
|
|
+}
|