netlogo - 如何让代理/乌龟看不到多堵墙?(网标)
问题描述
我是在stackoverflow中发帖的新手。
在我看到代理/海龟穿过我制作的墙壁时遇到问题之前,但我在这里找到了解决方案:
现在的问题是,当视锥内有另一堵墙时,有效视线(绿色斑块)不正确。我目前仍在修补如何解决此问题。
这是我目前正在处理的代码,
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 80
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]
;;my wall is vertical. you can do trig above and below to adjust for not vert lines.
ask wall 1 [set heading 45]
ask wall 1 [set color hsb 216 50 100]
;; I made it so that it could consider not vertical lines
ask wall 1 [ set first-end (list (round (sin heading * (size / 2))) (round (cos heading * (size / 2))))]
ask wall 1 [ set second-end (list (round((-1 * (size / 2) * sin heading))) (round ((-1 * (size / 2) * cos heading))))]
;;Test wall. UN-COMMENT THE SET BELOW TO SEE THE PROBLEM
; create-walls 1 [setxy 4 4]
; ask wall 2 [set size 10]
; ask wall 2 [set heading 90]
; ask wall 2 [ set first-end (list (round (sin heading * (size / 2))) (round (cos heading * (size / 2))))]
; ask wall 2 [ set second-end (list (round((-1 * (size / 2) * sin heading))) (round ((-1 * (size / 2) * cos heading))))]
; ask wall 2 [set color hsb 216 50 100]
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 trutle isnt 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
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: Doesnt work for colinear segments
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
如果您取消注释测试墙的代码集,这就是它的样子。
任何建议或提示都会非常有帮助!先感谢您。
解决方案
推荐阅读
- node.js - 如何在 Sequelize ORM 中获取不带前缀表名的连接数据结果
- ruby-on-rails - 如何使用 fb meta og 标签分享帖子描述
- google-maps - 在谷歌地图中找不到地点 ID
- python - Jupyter笔记本;无法使用 Jupyter 笔记本上未显示的列
- amazon-web-services - 将 jpostal/libpostal 部署到 EC2 实例中
- android - 如何在android中保存文本视图?
- c - 当未声明的变量被传递给 for 循环并改变 for 循环的语法时会发生什么
- php - 异常处理程序中的错误:在 laravel 中找不到查看 [errors.error]
- javascript - 空输入的 JS 验证指示器
- javascript - 执行 WebAPI /CheckConnection 请求时出现错误响应