navigation - Netlogo中的二维比例导航
问题描述
我正在尝试在 Netlogo 中实现二维比例导航,因为它由以下公式定义:
其中 v_r 是速度差,r 是视线,phi 是角度。Theta 应该是视线的变化,N 是导航常数。因为我是二维的,所以我正在使用带有 sin 的公式。
而且我有点迷茫,因为在我当前的实现中,两个移动的物体根本没有碰撞。
因此,目前我正在像这样计算 v_r 和 r ,并且我相当确定这是正确的,因为使用预定义的位置/方向对其进行测试会产生所需的结果:
;; line of sight
let rx [xcor] of target - xcor
let ry [ycor] of target - ycor
; difference in velocity components
let vx ([dx] of target * speed) - dx * predator-speed
let vy ([dy] of target * speed) - dy * predator-speed
角度是这样计算的,也应该是正确的:
let dot (vx * rx + vy * ry)
let det (vx * ry - vy * rx)
set angle atan det dot
把它们放在一起,theta 是这样的:
let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt(rx ^ 2 + ry ^ 2)
然后我计算与先前计算的 theta 的差,因为第一个公式使用它的微分,将它乘以常数并将其转换为度数:
let delta-theta theta - theta-old
set theta-old theta
let turn-rate (delta-theta * N * 180 / pi)
turn-at-most turn-rate max-hunt-turn
当我运行它时,会发生以下情况(两只海龟的速度相同,一只向右移动,一只向上移动)(对于大多数介于 3 和 5 之间的 N 值变化不大)
我认为我在理解最后一步时有一些错误,因为我确实认为组件应该没问题。 把它变成一个问题:为了改变航向,我该如何处理 theta(或 delta theta)?
编辑:这里是实际转折发生的地方:
to turn-at-most [turn max-turn] ;; turtle procedure
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
编辑 2:当前状态是我认为为 theta 给出的公式实际上已经是 theta 的导数,因为使用 theta 而不是 delta-theta 给了我想要的行为(或者至少看起来像它)。我仍然需要对此进行确认,但我会保持更新。
解决方案
这不是一个答案,但评论太长了。以下是使用您的代码的完整模型。在我看来,角度的计算很好,但是你确定theta的公式吗?无论捕食者的起始角度如何,我都得到非常小的 theta 数字(用弧度校正到度数)。
globals [N]
breed [predators predator]
breed [preys prey]
turtles-own [speed]
predators-own [angle theta-old]
to setup
clear-all
create-preys 1
[ setxy 0 10
set heading 90
set speed 1
set color blue
]
create-predators 1
[ setxy 0 0
set heading 0 ; experiment with this
set speed 1
set color red
]
set N 4
reset-ticks
end
to go
ask one-of predators
[ let target one-of preys
;; line of sight
let rx [xcor] of target - xcor
let ry [ycor] of target - ycor
; difference in velocity components
let vx ([dx] of target * [speed] of target) - dx * speed
let vy ([dy] of target * [speed] of target) - dy * speed
; calculate change in direction
let dot (vx * rx + vy * ry)
let det (vx * ry - vy * rx)
set angle atan det dot
type "Angle is: " print angle
let theta (sqrt (vx ^ 2 + vy ^ 2) * sin angle) / sqrt (rx ^ 2 + ry ^ 2)
type "Theta is: " print round (180 * theta / pi)
let delta-theta theta - theta-old
type "change in theta is: " print round (180 * delta-theta / pi)
set theta-old theta
let turn-rate (delta-theta * N * 180 / pi)
turn-at-most turn-rate 360
]
ask turtles [forward speed]
end
to turn-at-most [turn max-turn] ;; turtle procedure
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
NetLogo 没有使用公式,而是有一些很好的处理方向的原语。这似乎是一份工作subtract-headings
。
推荐阅读
- c# - 通过 ASP .NET MVC 填充 IIS 用户名?
- php - 如何在 Laravel 中保存没有密码的会话?
- python - 标准化数据以进行预测
- python - PyTorch:提供的尺寸数量(0)必须大于或等于张量中的维度数量(1)
- javascript - 获取点击元素的索引
- python-3.x - TypeError 将带有 dtype int 的 Series 传递给 dateutil.relativedelta
- python - 如何获取通过 url 传递给 django 中的类 Create View 的值?
- amazon-web-services - JupyterHub 笔记本服务器返回 500 错误,Pod 卡在“终止”状态
- bash - 从 find 命令返回 True 或 False
- javascript - 在javascript中组合多个回调