【问题标题】:How do I make turtles circle around a point如何让乌龟绕着一个点转
【发布时间】:2018-04-29 17:00:08
【问题描述】:

所以我的乌龟必须绕着一个点转。我最初的方法是让它们旋转每个刻度,垂直于它们必须旋转的点,并使它们向前移动。然而,这导致它们被吸引到具有固定半径的同一个圆上。那么如何解决这个问题呢?

【问题讨论】:

标签: rotation netlogo


【解决方案1】:
; move in a circle
; by
; Jose M Vidal

to setup
  clear-all
  create-n-turtles num-turtles
  reset-ticks
end

to create-n-turtles [n]
  crt n [
    fd random 20
    shake]
end

to update
  if (count turtles < num-turtles)[
    create-n-turtles num-turtles - count turtles]
  while [count turtles > num-turtles][
    ask one-of turtles [die]]
  ask turtles [move]
  tick
end

;
to move
  let cx 0
  let cy 0

  set cx mean [xcor] of turtles
  set cy mean [ycor] of turtles
  set heading towardsxy cx cy
  if (distancexy cx cy < radius) [
    set heading heading + 180]
  if (abs distancexy cx cy - radius > 1)[
    fd speed / 1.414]
  set heading towardsxy cx cy
  ifelse (clockwise) [
    set heading heading - 90]
  [
    set heading heading + 90]
  fd speed / 1.414
end

to shake
  set heading heading + (random 10) - 5
  set xcor xcor + random 10 - 5
  set ycor ycor + random 10 - 5
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多