Skip to contents

Calculate the angle at each point formed by the previous, current, and next points.

Usage

get_angle_edges(x, ..., .cols = NULL)

Arguments

x

A matrix (nx2), list of matrices, or tibble with coo columns.

...

Additional arguments (reserved for future use).

.cols

Column name(s) to process when x is a tibble. If NULL, automatically detects columns containing coo objects.

Value

  • If x is a single matrix: returns a numeric vector of angles (in radians)

  • If x is a list: returns a list of numeric vectors

  • If x is a tibble: returns a list of numeric vectors extracted from coo column

Details

For each point i, calculates the angle formed by points i-1, i, and i+1. Returns angles in radians. Wraps around at endpoints. This is a vector, not a scalar, so cannot be used with measure().

Examples

get_angle_edges(shapes$cat)
#>   [1] -3.1415927 -0.9827937  2.8198421  2.3561945  2.0032041  2.2455373
#>   [7] -2.9764440  2.9764440  3.1415927  2.9764440 -2.9764440  3.1415927
#>  [13]  3.1415927  3.1415927  2.9764440 -2.1910458 -2.5535901 -2.4805495
#>  [19] -2.8198421 -2.6779450 -3.1415927 -2.9849908 -3.1415927 -2.9764440
#>  [25] -2.9764440  3.1415927  3.1415927  2.9764440  2.6011732  1.1284221
#>  [31]  2.8753406 -3.1415927  2.9849908 -3.1415927  2.9764440  3.1415927
#>  [37]  2.9764440  3.1415927  2.9262350  3.0584514  2.9105020  2.8535372
#>  [43]  3.0172377  2.6779450  3.1415927  2.8198421  2.9996956 -2.8430937
#>  [49] -2.9764440 -2.9441971  3.1093458  2.9764440 -2.9764440  2.9764440
#>  [55]  3.1415927  2.9764440 -2.9764440  2.8198421  2.9996956  3.1415927
#>  [61] -3.0584514  2.9340964  3.0348570  3.0509328  2.8198421  2.9996956
#>  [67] -2.9996956 -2.9105020 -2.9602729 -2.9105020 -2.6779450  2.9764440
#>  [73]  2.9849908  2.9996956  2.7291822  3.0348570 -2.6224465  3.0172377
#>  [79]  2.9441971  1.4601391  2.6320004  2.9764440 -2.6779450 -2.4980915
#>  [85]  2.9304993  3.0309354 -3.0309354  2.0803886  2.7187387  2.8535372
#>  [91] -2.8059541 -2.6011732 -2.9441971  3.1093458  2.9764440 -3.1415927
#>  [97] -3.1415927  2.8198421  2.8753406 -3.1415927 -3.0172377 -2.9996956
#> [103] -2.9849908 -2.9764440 -3.1415927 -3.1415927 -3.1415927 -3.1415927
#> [109] -2.9764440 -2.9262350 -2.2730533  2.2730533  2.4393357  2.4805495
#> [115]  2.5535901  2.8198421  2.5872852  3.0348570  2.8753406 -0.9097532
get_angle_edges(shapes)
#> $cat
#>   [1] -3.1415927 -0.9827937  2.8198421  2.3561945  2.0032041  2.2455373
#>   [7] -2.9764440  2.9764440  3.1415927  2.9764440 -2.9764440  3.1415927
#>  [13]  3.1415927  3.1415927  2.9764440 -2.1910458 -2.5535901 -2.4805495
#>  [19] -2.8198421 -2.6779450 -3.1415927 -2.9849908 -3.1415927 -2.9764440
#>  [25] -2.9764440  3.1415927  3.1415927  2.9764440  2.6011732  1.1284221
#>  [31]  2.8753406 -3.1415927  2.9849908 -3.1415927  2.9764440  3.1415927
#>  [37]  2.9764440  3.1415927  2.9262350  3.0584514  2.9105020  2.8535372
#>  [43]  3.0172377  2.6779450  3.1415927  2.8198421  2.9996956 -2.8430937
#>  [49] -2.9764440 -2.9441971  3.1093458  2.9764440 -2.9764440  2.9764440
#>  [55]  3.1415927  2.9764440 -2.9764440  2.8198421  2.9996956  3.1415927
#>  [61] -3.0584514  2.9340964  3.0348570  3.0509328  2.8198421  2.9996956
#>  [67] -2.9996956 -2.9105020 -2.9602729 -2.9105020 -2.6779450  2.9764440
#>  [73]  2.9849908  2.9996956  2.7291822  3.0348570 -2.6224465  3.0172377
#>  [79]  2.9441971  1.4601391  2.6320004  2.9764440 -2.6779450 -2.4980915
#>  [85]  2.9304993  3.0309354 -3.0309354  2.0803886  2.7187387  2.8535372
#>  [91] -2.8059541 -2.6011732 -2.9441971  3.1093458  2.9764440 -3.1415927
#>  [97] -3.1415927  2.8198421  2.8753406 -3.1415927 -3.0172377 -2.9996956
#> [103] -2.9849908 -2.9764440 -3.1415927 -3.1415927 -3.1415927 -3.1415927
#> [109] -2.9764440 -2.9262350 -2.2730533  2.2730533  2.4393357  2.4805495
#> [115]  2.5535901  2.8198421  2.5872852  3.0348570  2.8753406 -0.9097532
#> 
#> $dog
#>   [1] -2.9764440  2.8345469 -2.9996956  2.9996956  3.1183410 -2.8112953
#>   [7] -2.4445713 -3.0209690  2.9441971  2.9441971 -3.0348570 -2.9741609
#>  [13] -2.8966140 -2.9996956 -2.3006960  3.0029529  1.4685896  2.8632930
#>  [19]  2.4668517  2.3874343  2.9996956  3.1415927  3.1415927  2.6779450
#>  [25]  2.8198421 -3.0509328 -2.7251540 -0.2621198  2.8966140  2.9764440
#>  [31]  2.9849908  0.7022569  2.8517462 -2.6120031  3.0284417 -2.8632930
#>  [37]  2.9764440 -2.8345469  2.8345469 -3.1183410  2.8198421  3.0172377
#>  [43]  2.9441971  2.8198421  2.9562447  3.0284417  2.9764440 -2.9996956
#>  [49]  2.9996956 -3.1415927 -3.1415927 -3.1415927  2.9996956 -2.9996956
#>  [55] -2.9996956  2.9996956 -2.8198421  3.0981418 -2.8318897 -2.9441971
#>  [61] -2.9764440 -3.1093458 -3.0727362 -2.9441971  2.9996956 -2.9562447
#>  [67]  2.6344941  2.7610863  2.7367009 -3.1415927  2.5213432  2.8857841
#>  [73] -2.5438343 -2.8632930 -3.1415927  1.8490960  2.8632930  2.9996956
#>  [79]  2.3874343  2.7886023  2.8198421 -2.8198421 -2.1708465  2.9562447
#>  [85] -2.9996956  3.0584514 -3.0584514 -3.1415927 -2.8198421  2.8198421
#>  [91] -2.9617392  3.1183410  2.8430937 -3.0828368 -2.9018495 -2.9764440
#>  [97] -3.1415927 -3.1415927 -2.9996956  2.9996956 -2.9996956 -2.3006960
#> [103]  2.6992184  1.5495229  2.7875952  2.1910458  2.5213432  3.1415927
#> [109] -3.0284417 -2.9562447  2.9996956 -3.0584514 -3.0828368 -2.7291822
#> [115] -2.6120031 -2.9764440  3.1415927  2.9764440 -2.9764440  3.1415927
#> 
#> $heart
#>   [1]  3.141593  2.677945 -2.788602  3.110353 -2.999696  3.141593  3.141593
#>   [8] -3.030935 -3.110353  3.110353 -3.007271  3.038511 -3.038511  3.141593
#>  [15] -3.064821  3.064821  3.038511  3.110353  3.141593  3.030935  3.141593
#>  [22]  2.999696  3.038511  2.981680 -3.058451  2.875341 -3.094010  2.896614
#>  [29]  3.141593  3.141593  3.141593  3.141593  2.944197  2.958482 -3.006065
#>  [36]  3.006065  2.981680  3.038511 -3.038511  2.896614  3.030935  3.007271
#>  [43]  3.064821  3.058451  3.006065  3.094010  2.944197 -3.141593  2.944197
#>  [50]  3.094010  3.006065 -3.141593  2.878598  3.110353 -3.110353  2.889038
#>  [57] -3.141593  3.110353  2.878598 -2.934096 -1.051650  3.064821  3.038511
#>  [64]  3.110353  3.030935  3.141593  2.896614  3.064821  3.058451  3.141593
#>  [71]  2.761086 -2.944197  2.944197 -3.141593  2.944197  3.094010  2.846152
#>  [78] -3.064821  3.064821  2.896614 -3.141593  3.030935  2.930499  3.058451
#>  [85] -3.141593  3.006065  3.094010 -3.141593 -3.094010  2.699218 -2.944197
#>  [92] -3.141593 -3.141593  2.677945 -2.875341  2.875341  3.064821  3.007271
#>  [99]  3.030935 -3.141593  2.999696 -3.110353 -3.141593  2.930499 -3.064821
#> [106] -3.038511  3.038511 -3.141593 -3.038511 -3.110353 -3.141593 -3.030935
#> [113]  3.030935 -3.030935 -3.141593 -3.030935 -3.110353 -3.038511 -3.064821
#> [120]  1.249046
#> 
#> $leaf2
#>   [1] -2.9996956  2.9764440  3.0284417 -3.0284417  3.0284417  2.9007462
#>   [7]  2.4116930  2.1451012  1.6575347 -3.0727362 -2.9007462 -3.0284417
#>  [13] -3.1183410  3.1183410 -2.9764440 -1.2490458  3.0981418  3.0051900
#>  [19]  2.9996956  2.9996956 -2.9996956  2.8632930  3.1415927  3.0981418
#>  [25]  3.0584514  1.7782926  2.6303619  3.0648208 -2.7367009 -1.7094361
#>  [31]  3.0727362  3.1093458  2.9764440  2.1587989  2.1730837 -3.0828368
#>  [37] -1.4141944 -3.0671039  2.9660005  3.1415927  2.6224465  1.5707963
#>  [43]  2.9764440 -3.1183410 -2.7547169 -1.9809237  2.4106859  2.0032041
#>  [49]  2.9849908 -3.1415927  2.9764440 -1.5707963 -2.0344439  3.0981418
#>  [55]  3.1415927  3.0284417  2.9764440  2.8198421  1.7506498  2.9617392
#>  [61] -3.0981418 -1.2924967  2.9764440  3.0284417  3.0981418  2.9441971
#>  [67]  2.8753406  1.6614562  2.7846807  2.9441971  3.0981418  2.8632930
#>  [73] -2.9764440 -1.5707963 -2.9849908  2.9617392  1.8925469  2.6779450
#>  [79]  2.9996956  3.1183410  3.0284417  3.0150005 -2.7367009 -0.7853982
#>  [85]  3.0509328  3.0671039  2.9849908  2.2142974  2.1763410 -2.3006960
#>  [91] -2.2752904  3.0284417  2.9764440  1.5707963  2.8198421  2.8430937
#>  [97] -3.1093458  3.1093458 -1.7359450 -2.6779450  2.0576956  2.2817057
#> [103]  2.9741609  2.9521125 -3.0727362 -1.9614034 -2.5535901  3.0648208
#> [109]  2.8966140  1.5120405  3.0150005 -3.0981418  3.0981418  2.8632930
#> [115] -2.9996956  2.9996956  2.9764440  3.0284417 -3.0284417 -1.5475447
#>