Calculate rectilinearity - a measure of how well a shape fits a rectangle after optimal rotation.
Value
If
xis a single matrix: returns a numeric scalarIf
xis a list: returns a numeric vectorIf
xis a tibble: returns a numeric vector extracted from coo column
Details
Rectilinearity measures how rectangular a shape is by testing multiple rotations and finding the orientation that best fits a rectangle.
Algorithm from Zunic & Rosin (2003). Higher values indicate more rectangular shapes. Computationally intensive - tests 4n rotations where n is the number of points.
References
Zunic, J., & Rosin, P. L. (2003). Rectilinearity measurements for polygons. IEEE Transactions on Pattern Analysis and Machine Intelligence.
Examples
get_rectilinearity(shapes$cat)
#> [1] 0.1343944
# Use in measure() on mini bot for the sake of speed
bot[1:2, ] %>% measure("rectilinearity")
#> # A tibble: 2 × 6
#> id coo type fake price coo_rectilinearity
#> <chr> <out> <fct> <fct> <dbl> <dbl>
#> 1 brahma (138 x 2) whisky a 3 0.430
#> 2 caney (168 x 2) whisky a 1.2 0.459
