gpt4 book ai didi

netlogo - 无法透过墙壁看到

转载 作者:行者123 更新时间:2023-12-02 20:32:30 24 4
gpt4 key购买 nike

我正在尝试在 Netlogo 中对一些建筑物搜索进行建模,但现在我陷入困境,因为我不知道如何解决看穿墙壁的问题。我的特工可以看到圆锥体,比如说 60 度和前方 5 个斑 block 。我可以检测视线中某处的墙壁,也可以检测其他物体,问题是检测物体是否在墙后面。我该如何解决?有什么想法吗?

最佳答案

这是一个完整的工作示例。您可以对需要检查的墙壁或补丁进行一些优化,而不是全部,但我将把它留给您......本质上,您可以想象您在代理和所有其他补丁之间画一条线位于特工的视野内并移除补丁,从而形成一堵相交的墙。线相交问题已经得到了很好的研究,我放了一个链接供您查看。为了使计算更容易,我存储了墙的端点 - 如果墙不像我的情况那样垂直,您可以使用 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

关于netlogo - 无法透过墙壁看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43684740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com