本文介绍了在加速粒子系统方面需要帮助(或如何让海龟不向其他海龟求助.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为玩具,它可以很好地工作,但显然,当它放大时,它会陷入泥潭.我如何在不要求海龟询问其他海龟的情况下执行此系统?代码就是这样.

As a toy, it works well but obviously, when It scales up it bogs down.How can I do this system without asking turtles to ask the other turtles?the code is thus.

to go
 ask turtles
  [
  ask other turtles [
                     set heading towards myself
                     let D distance myself
                     let C  .1 / D - 1 / (D ^ 2)
                     if C > 1 [set C 1]
                     fd C
                    ]
  ]

tick

结束

我应该知道该怎么做,但大脑无法正常工作.我会全力以赴,如果我先得到答案,就会发表我自己的答案.

I should know how to do this but the brain is not working. I will race y'all to the answer and post my own if I get it first.

推荐答案

您在考虑吗?

turtles-own [m]

 to setup
  ca
  crt 1000 [
      setxy random-xcor random-ycor
      set shape "dot"
      set color white
      set m random-float 5
      set size 2 * (m / pi) ^ .5
      ]
end

to go
ask turtles
 [
  set heading weighted-mean-heading other turtles
  let mv sum [m / (distance myself ^ 2) / [m] of myself ] of other turtles
  if mv > .1 [set mv 1]
  if mv < -.1 [ set mv -1]
  bk mv
 ]

 ask turtles
  [
   ask other turtles in-radius (size / 4) [ask myself [set m m + [m] of myself] die ]
   set size 2 * (m / pi) ^ .5
 ]
end

to-report weighted-mean-heading [turts]
  let mean-x sum [sin towards myself * m / (distance myself ^ 2)] of turts / sum [m / distance myself ^ 2] of turts / m
  let mean-y sum [cos towards myself * m / (distance myself ^ 2)] of turts / sum [m / distance myself ^ 2] of turts / m
  report atan mean-x mean-y
  end

这篇关于在加速粒子系统方面需要帮助(或如何让海龟不向其他海龟求助.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 20:13