Skip to contents

Calculate the angle of each edge relative to the x-axis.

Usage

get_angle_tangent(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 edge from point i to point i+1, calculates the angle relative to the x-axis. Returns angles in radians (-pi, pi). This is a vector, not a scalar, so cannot be used with measure().

Examples

get_angle_tangent(shapes$cat)
#>   [1] -2.1587989  0.0000000 -0.3217506 -1.1071487 -2.2455373  3.1415927
#>   [7] -2.9764440  3.1415927  3.1415927  2.9764440  3.1415927  3.1415927
#>  [13]  3.1415927  3.1415927  2.9764440 -2.3561945 -1.7681919 -1.1071487
#>  [19] -0.7853982 -0.3217506 -0.3217506 -0.1651487 -0.1651487  0.0000000
#>  [25]  0.1651487  0.1651487  0.1651487  0.0000000 -0.5404195 -2.5535901
#>  [31] -2.8198421 -2.8198421 -2.9764440 -2.9764440  3.1415927  3.1415927
#>  [37]  2.9764440  2.9764440  2.7610863  2.6779450  2.4468544  2.1587989
#>  [43]  2.0344439  1.5707963  1.5707963  1.2490458  1.1071487  1.4056476
#>  [49]  1.5707963  1.7681919  1.7359450  1.5707963  1.7359450  1.5707963
#>  [55]  1.5707963  1.4056476  1.5707963  1.2490458  1.1071487  1.1071487
#>  [61]  1.1902899  0.9827937  0.8760581  0.7853982  0.4636476  0.3217506
#>  [67]  0.4636476  0.6947383  0.8760581  1.1071487  1.5707963  1.4056476
#>  [73]  1.2490458  1.1071487  0.6947383  0.5880026  1.1071487  0.9827937
#>  [79]  0.7853982 -0.8960554 -1.4056476 -1.5707963 -1.1071487 -0.4636476
#>  [85] -0.6747409 -0.7853982 -0.6747409 -1.7359450 -2.1587989 -2.4468544
#>  [91] -2.1112158 -1.5707963 -1.3734008 -1.4056476 -1.5707963 -1.5707963
#>  [97] -1.5707963 -1.8925469 -2.1587989 -2.1587989 -2.0344439 -1.8925469
#> [103] -1.7359450 -1.5707963 -1.5707963 -1.5707963 -1.5707963 -1.5707963
#> [109] -1.4056476 -1.1902899 -0.3217506 -1.1902899 -1.8925469 -2.5535901
#> [115]  3.1415927  2.8198421  2.2655346  2.1587989  1.8925469 -2.1587989
get_angle_tangent(shapes)
#> $cat
#>   [1] -2.1587989  0.0000000 -0.3217506 -1.1071487 -2.2455373  3.1415927
#>   [7] -2.9764440  3.1415927  3.1415927  2.9764440  3.1415927  3.1415927
#>  [13]  3.1415927  3.1415927  2.9764440 -2.3561945 -1.7681919 -1.1071487
#>  [19] -0.7853982 -0.3217506 -0.3217506 -0.1651487 -0.1651487  0.0000000
#>  [25]  0.1651487  0.1651487  0.1651487  0.0000000 -0.5404195 -2.5535901
#>  [31] -2.8198421 -2.8198421 -2.9764440 -2.9764440  3.1415927  3.1415927
#>  [37]  2.9764440  2.9764440  2.7610863  2.6779450  2.4468544  2.1587989
#>  [43]  2.0344439  1.5707963  1.5707963  1.2490458  1.1071487  1.4056476
#>  [49]  1.5707963  1.7681919  1.7359450  1.5707963  1.7359450  1.5707963
#>  [55]  1.5707963  1.4056476  1.5707963  1.2490458  1.1071487  1.1071487
#>  [61]  1.1902899  0.9827937  0.8760581  0.7853982  0.4636476  0.3217506
#>  [67]  0.4636476  0.6947383  0.8760581  1.1071487  1.5707963  1.4056476
#>  [73]  1.2490458  1.1071487  0.6947383  0.5880026  1.1071487  0.9827937
#>  [79]  0.7853982 -0.8960554 -1.4056476 -1.5707963 -1.1071487 -0.4636476
#>  [85] -0.6747409 -0.7853982 -0.6747409 -1.7359450 -2.1587989 -2.4468544
#>  [91] -2.1112158 -1.5707963 -1.3734008 -1.4056476 -1.5707963 -1.5707963
#>  [97] -1.5707963 -1.8925469 -2.1587989 -2.1587989 -2.0344439 -1.8925469
#> [103] -1.7359450 -1.5707963 -1.5707963 -1.5707963 -1.5707963 -1.5707963
#> [109] -1.4056476 -1.1902899 -0.3217506 -1.1902899 -1.8925469 -2.5535901
#> [115]  3.1415927  2.8198421  2.2655346  2.1587989  1.8925469 -2.1587989
#> 
#> $dog
#>   [1] -2.9764440  2.9996956  3.1415927  2.9996956  2.9764440 -2.9764440
#>   [7] -2.2794226 -2.1587989 -2.3561945 -2.5535901 -2.4468544 -2.2794226
#>  [13] -2.0344439 -1.8925469 -1.0516502 -1.1902899 -2.8632930  3.1415927
#>  [19]  2.4668517  1.7126934  1.5707963  1.5707963  1.5707963  1.1071487
#>  [25]  0.7853982  0.8760581  1.2924967 -2.1112158 -2.3561945 -2.5213432
#>  [31] -2.6779450  1.1659045  0.8760581  1.4056476  1.2924967  1.5707963
#>  [37]  1.4056476  1.7126934  1.4056476  1.4288993  1.1071487  0.9827937
#>  [43]  0.7853982  0.4636476  0.2782997  0.1651487  0.0000000  0.1418971
#>  [49]  0.0000000  0.0000000  0.0000000  0.0000000 -0.1418971  0.0000000
#>  [55]  0.1418971  0.0000000  0.3217506  0.2782997  0.5880026  0.7853982
#>  [61]  0.9505468  0.9827937  1.0516502  1.2490458  1.1071487  1.2924967
#>  [67]  0.7853982  0.4048918  0.0000000  0.0000000 -0.6202495 -0.8760581
#>  [73] -0.2782997  0.0000000  0.0000000 -1.2924967 -1.5707963 -1.7126934
#>  [79] -2.4668517 -2.8198421  3.1415927 -2.8198421 -1.8490960 -2.0344439
#>  [85] -1.8925469 -1.9756881 -1.8925469 -1.8925469 -1.5707963 -1.8925469
#>  [91] -1.7126934 -1.7359450 -2.0344439 -1.9756881 -1.7359450 -1.5707963
#>  [97] -1.5707963 -1.5707963 -1.4288993 -1.5707963 -1.4288993 -0.5880026
#> [103] -1.0303768 -2.6224465 -2.9764440  2.3561945  1.7359450  1.7359450
#> [109]  1.8490960  2.0344439  1.8925469  1.9756881  2.0344439  2.4468544
#> [115]  2.9764440  3.1415927  3.1415927  2.9764440  3.1415927  3.1415927
#> 
#> $heart
#>   [1]  2.3561945  1.8925469  2.2455373  2.2142974  2.3561945  2.3561945
#>   [7]  2.3561945  2.4668517  2.4980915  2.4668517  2.6011732  2.4980915
#>  [13]  2.6011732  2.6011732  2.6779450  2.6011732  2.4980915  2.4668517
#>  [19]  2.4668517  2.3561945  2.3561945  2.2142974  2.1112158  1.9513027
#>  [25]  2.0344439  1.7681919  1.8157750  1.5707963  1.5707963  1.5707963
#>  [31]  1.5707963  1.5707963  1.3734008  1.1902899  1.3258177  1.1902899
#>  [37]  1.0303768  0.9272952  1.0303768  0.7853982  0.6747409  0.5404195
#>  [43]  0.4636476  0.3805064  0.2449787  0.1973956  0.0000000  0.0000000
#>  [49] -0.1973956 -0.2449787 -0.3805064 -0.3805064 -0.6435011 -0.6747409
#>  [55] -0.6435011 -0.8960554 -0.8960554 -0.9272952 -1.1902899 -0.9827937
#>  [61]  1.1071487  1.0303768  0.9272952  0.8960554  0.7853982  0.7853982
#>  [67]  0.5404195  0.4636476  0.3805064  0.3805064  0.0000000  0.1973956
#>  [73]  0.0000000  0.0000000 -0.1973956 -0.2449787 -0.5404195 -0.4636476
#>  [79] -0.5404195 -0.7853982 -0.7853982 -0.8960554 -1.1071487 -1.1902899
#>  [85] -1.1902899 -1.3258177 -1.3734008 -1.3734008 -1.3258177 -1.7681919
#>  [91] -1.5707963 -1.5707963 -1.5707963 -2.0344439 -1.7681919 -2.0344439
#>  [97] -2.1112158 -2.2455373 -2.3561945 -2.3561945 -2.4980915 -2.4668517
#> [103] -2.4668517 -2.6779450 -2.6011732 -2.4980915 -2.6011732 -2.6011732
#> [109] -2.4980915 -2.4668517 -2.4668517 -2.3561945 -2.4668517 -2.3561945
#> [115] -2.3561945 -2.2455373 -2.2142974 -2.1112158 -2.0344439  2.3561945
#> 
#> $leaf2
#>   [1] -1.5707963 -1.7359450 -1.8490960 -1.7359450 -1.8490960 -2.0899424
#>   [7] -2.8198421  2.4668517  0.9827937  1.0516502  1.2924967  1.4056476
#>  [13]  1.4288993  1.4056476  1.5707963 -2.8198421 -2.8632930 -2.9996956
#>  [19]  3.1415927  2.9996956  3.1415927  2.8632930  2.8632930  2.8198421
#>  [25]  2.7367009  1.3734008  0.8621701  0.7853982  1.1902899  2.6224465
#>  [31]  2.5535901  2.5213432  2.3561945  1.3734008  0.4048918  0.4636476
#>  [37]  2.1910458  2.2655346  2.0899424  2.0899424  1.5707963  0.0000000
#>  [43] -0.1651487 -0.1418971  0.2449787  1.4056476  0.6747409 -0.4636476
#>  [49] -0.6202495 -0.6202495 -0.7853982  0.7853982  1.8925469  1.8490960
#>  [55]  1.8490960  1.7359450  1.5707963  1.2490458 -0.1418971 -0.3217506
#>  [61] -0.2782997  1.5707963  1.4056476  1.2924967  1.2490458  1.0516502
#>  [67]  0.7853982 -0.6947383 -1.0516502 -1.2490458 -1.2924967 -1.5707963
#>  [73] -1.4056476  0.1651487  0.3217506  0.1418971 -1.1071487 -1.5707963
#>  [79] -1.7126934 -1.7359450 -1.8490960 -1.9756881 -1.5707963  0.7853982
#>  [85]  0.6947383  0.6202495  0.4636476 -0.4636476 -1.4288993 -0.5880026
#>  [91]  0.2782997  0.1651487  0.0000000 -1.5707963 -1.8925469 -2.1910458
#>  [97] -2.1587989 -2.1910458 -0.7853982 -0.3217506 -1.4056476 -2.2655346
#> [103] -2.4329664 -2.6224465 -2.5535901 -1.3734008 -0.7853982 -0.8621701
#> [109] -1.1071487 -2.7367009 -2.8632930 -2.8198421 -2.8632930  3.1415927
#> [115] -2.9996956  3.1415927  2.9764440  2.8632930  2.9764440 -1.7126934
#>