问题
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