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

Line computed in turtle's direction doesn't match shape heading

代码:

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

 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

输出:

问题:

为什么箭头和线的方向不一致?我只是根据乌龟的坐标和航向计算出一条线并绘制出来。我是否错过了代码中发生的一些近似值?

如果您将箭头以 (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 的列表时,但我实际上无法计算出它们应该是什么,变量名也没有帮助。