如何解释 'shape' 包的矢量角度?

How to interpret vector angles for the 'shape' package?

我想弄清楚我使用的某些矢量角度是否计算正确。

我有一个模拟粒子轨迹,数据如下:

   track_id       track_length frame          x         y         dx           dy steplength   direction
     <fctr>             <fctr> <dbl>      <dbl>     <dbl>      <dbl>        <dbl>      <dbl>       <dbl>
 1  Track 1 Track length:  464     0 -0.2779444 0.6532534  0.0000000  0.000000000  0.0000000   0.0000000
 2  Track 1 Track length:  464     1  0.9527568 1.6890017  1.2307012  1.035748375  1.6085398  40.0836991
 3  Track 1 Track length:  464     2  3.1617740 1.5406508  2.2090172 -0.148350899  2.2139930  -3.8420418
 4  Track 1 Track length:  464     3  3.4791213 1.1602548  0.3173472 -0.380396044  0.4953892 -50.1632825
 5  Track 1 Track length:  464     4  3.0130556 1.7207842 -0.4660657  0.560529394  0.7289790 129.7426481
 6  Track 1 Track length:  464     5  4.1270750 1.7163850  1.1140194 -0.004399235  1.1140281  -0.2262584
 7  Track 1 Track length:  464     6  3.5344773 2.2045875 -0.5925977  0.488202537  0.7677980 140.5171189
 8  Track 1 Track length:  464     7  1.8244100 2.3753219 -1.7100673  0.170734431  1.7185693 174.2984400
 9  Track 1 Track length:  464     8  3.2462738 1.7072696  1.4218637 -0.668052374  1.5709839 -25.1661450
10  Track 1 Track length:  464     9  2.0981822 2.1773816 -1.1480916  0.470112097  1.2406126 157.7322425

direction 列的计算方式如下:

direction = (180/pi)*(atan2(dy, dx)))

这为我提供了 [-180, 180] 度格式的每个点的矢量角度。我检查了 ggplot 的箭头功能,角度似乎是正确的。到目前为止一切顺利。

现在,我想使用 rastershape 包的组合为每个 xy-bin 绘制矢量方向。特别是,我在解释 Arrowhead() 函数的文档时遇到了问题,它说:

angle: angle of arrowhead (anti-clockwise, relative to x-axis), in degrees [0,360]; either one value or a vector.

虽然它需要我的 "unconverted" 值。这是否意味着他们是正确的?还是需要格式化?如何从 [-180, 180] 变为 [0, 360]?

像这样改变角度域:

if (angle < 0)
    angle = angle + 360