在龟的方向计算的线与形状标题不匹配

时间:2015-07-07 22:37:59

标签: netlogo

代码:

;在下面的代码中调用检查

 to-report calculate-line[x y angle]
      let m tan angle
      let A m 
      let B -1 
      let C (- m * x + y) 
      report (list A B C)
    end

    to make-line[a]; a is list containing A, B and C and in that order.
      let x 0
      let y((- item 2 a) / item 1 a)
      let y1 0
      let x1((- item 2 a) / item 0 a)
      hatch 1[
        set size 0.15 setxy x y
        pendown
        facexy x1 y1

            fd 7   
      ]
    end

    to check
      clear-all
      crt 1[
        set size 2
        set shape "arrow"
        setxy -3 3
        set heading 268
        make-line calculate-line xcor ycor heading-to-angle heading
        ]
    end
to-report heading-to-angle [ h ]
  report (90 - h) mod 360
end

输出: enter image description here

问题:

为什么箭头标题和方向不同?我只是从龟的坐标和头部计算一条线并绘制它。我错过了btw代码中发生的一些近似值吗?

1 个答案:

答案 0 :(得分:2)

如果箭头居中于(0,0),它可以正常工作。从您的代码中查看此版本的检查程序:

to check
  clear-all
  crt 1
  [ set size 2
    set shape "arrow"
    setxy 0 0
    set heading random 360
    make-line calculate-line xcor ycor heading
  ]
end

但如果您将setxy 0 0更改为其他位置(例如setxy 3 2),则整个事物会分开。这表明没有近似值,问题是你的线坐标计算。可能在计算A,B和C的列表时,但我实际上无法确定它们应该是什么,变量名称也无济于事。

相关问题