【问题标题】:Not see through the walls看不透墙壁
【发布时间】:2017-04-28 16:18:58
【问题描述】:

我正在尝试在 Netlogo 中模拟一些建筑物搜索,但现在我被卡住了,因为我不知道如何解决透视墙问题。我的代理可以看到圆锥体,比如说 60 度和 5 个补丁。我可以检测到我视线中的某处墙壁,我也可以检测到其他物体,问题是检测物体是否在墙壁后面。我该如何解决?有什么想法吗?

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    这是一个完整的工作示例。您可以针对需要检查哪些墙壁或补丁进行一些优化,而不是所有这些,但我将把它留给您......基本上,您可以想象您在代理和所有其他补丁之间画一条线在代理的视野中并移除补丁,从而形成相交的墙。线交点问题已得到很好的研究,我放了一个链接供您查看。为了使我的计算更容易,我存储了墙壁的端点——如果墙壁不像我的情况那样垂直,你可以使用 trig 来计算端点。我也使用了一些美学...

    breed [ walls wall]
    walls-own [first-end second-end]
    
    to setup
      ca
      reset-ticks
      set-default-shape walls "line"
      crt 1 [ setxy 4 0]
      ask turtles [facexy 0 0]
    
      ;;color all cones in radius blue by default
      let dist 10
      let angle 30
      ask turtles [ ask patches in-cone dist angle [set pcolor blue]]
    
      ;; place a wall down...the line of sight is blocked (keyword: line)
      create-walls 1 [ setxy 0 0 ]
      ;;This is an interpretation of a wall. Two points that define the edges.
      ask wall 1 [set size 10]
      ask wall 1 [set first-end (list 0 (size / 2))]
      ask wall 1 [set second-end (list 0 (-1 * size / 2))]
      ;;my wall is vertical. You can do trig above and below to adjust for not vert lines.
      ask wall 1 [ set heading 0]
      ask wall 1 [set color hsb  216 50 100] ;;pretty blue =)
    
      ask turtle 0 [ ask in-sight dist angle [ set pcolor green]]
    end
    
    ;;a turtle can see a patch if the line from the patch to the turtle isn't intersected by a wall.
    to-report in-sight [dist angle]
      let turtle-x xcor
      let turtle-y ycor
      report patches in-cone dist angle with 
      [
        not any? walls with [intersects [pxcor] of myself [pycor] of myself turtle-x turtle-y  ;; line 1
                                       (first first-end) (last first-end) (first second-end) (last second-end)] ;; line 2
      ]
    end
    ;; See http://stackoverflow.com/questions/3838329/how-can-i-check-if-two-segments-intersect
    ;;counter clockwise method (doesn't consider colinearity)
    to-report counter-clockwise [x1 y1 x2 y2 x3 y3]
      ;;returns true if triplet creates counter clockwise angle (uses slopes)
      ;(C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
      report (y3 - y1) * (x2 - x1) > (y2 - y1) * (x3 - x1)
    end
    
    to-report intersects [x1 y1 x2 y2 x3 y3 x4 y4]
      ;;line 1: x1 y1 x2 y2
      ;;line 2: x3 y3 x4 y4
      ;;DANGER: Doesn't work for colinear segments!!!
      ;ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D)
      report (counter-clockwise x1 y1 x3 y3 x4 y4) != (counter-clockwise x2 y2 x3 y3 x4 y4)
      and (counter-clockwise x1 y1 x2 y2 x3 y3) != (counter-clockwise x1 y1 x2 y2 x4 y4)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 1970-01-01
      • 2014-05-24
      • 2018-03-22
      • 1970-01-01
      • 2016-10-26
      • 2017-03-23
      相关资源
      最近更新 更多