通过视锥旋转海龟 [英] Rotating a turtle through cone of vision
问题描述
我希望写信给乌龟有视锥锥角的地方.
I wish to write to where I have a cone-of-vision cone angle for the turtle.
然后我将乌龟旋转通过视锥.
And I rotate the turtle through the cone-of-vision.
因此,首先是视锥的开始,以0.05度为增量,直到视锥结束为止.
Therefore, first it's heading the start of cone-of-vision and with a increment of 0.05 degree it changes till it reaches the end of cone-of-vision
let max-head heading + (cone-angle / 2)
set heading subtract-headings heading (zero-dash / 2)
while[(subtract-headings heading max-head ) < 0]
[
set heading heading + .05
;wait 0.1
]
我写的上述代码不正确.但是我找不到错误.
The above code I wrote isnt correct. But I can't find the mistake.
推荐答案
我认为您的部分困难是使用减法标题.这会找到两个方向之间最短角度的大小,而这并不是您想要的视锥范围(可能很宽)的大小.由于您的代码沿顺时针方向旋转,因此我假设您想从最逆时针的点开始旋转.唯一的困难就是航向经过360度,因此您需要将锥扫计数器与实际航向分开,并使用mod算术从计数器进行转换.
I think part of your difficulty is using subtract-headings. This finds the size of the shortest angle between two headings and that's not what you want for a cone of vision (which could potentially be wide). Since your code rotates clockwise, I have assumed you want to start at the most anti-clockwise point and rotate. The only difficulty then is if the heading goes through 360, so you need to separate the cone sweeping counter and the actual heading, and use mod arithmetic to convert from the counter.
globals
[ cone-angle]
to setup
clear-all
create-turtles 1
set cone-angle 25
end
to go
ask turtles
[ let max-head heading + (cone-angle / 2)
let fake-head heading - (cone-angle / 2)
while [fake-head < max-head]
[ print fake-head
set fake-head fake-head + 1
set heading fake-head mod 360
wait 0.1
]
]
end
这篇关于通过视锥旋转海龟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!