Using Vectors in NetLogo

非 Y 不嫁゛ 提交于 2019-12-24 05:26:11

问题


How can you define add or subtract vectors in NetLogo. It doesn't seem to have any datatype pertaining to it.

By vectors I here am talking in terms specifically velocity of a turtle.

Are there any extensions in netlogo that support this, I can't find any.


回答1:


I don't know of an extension that provides vectors. But the math involved to code it in NetLogo itself is generally not that complicated. So for example suppose you choose to represent a two-dimensional vector as a list of two numbers. Then:

to-report vector-add [v1 v2]
  report (list (first v1 + first v2) (last v1 + last v2))
end

observer> show vector-add [0.1 0.2] [0.5 0.3]
observer: [0.6 0.5]

vector-add can also be written as:

to-report vector-add [v1 v2]
  report (map + v1 v2)
end

which works on vectors of any dimension.



来源:https://stackoverflow.com/questions/24962986/using-vectors-in-netlogo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!