Skip to contents

Calculate fractal dimension using the box counting method

Usage

fd_boxes(data, lvec, keep_data = FALSE, plot = FALSE)

Arguments

data

A data frame in which the first two columns are x and y coordinates, respectively.

lvec

The scales to use for calculation (i.e. box sizes).

keep_data

Logical. Keep calculation data? Default = TRUE.

plot

Logical. Plot the shape with box sizes superimposed? Defaults to FALSE.

Value

A value for fractal dimension, typically between 1 and 2 or a list if keep_data = TRUE.

Details

This function calculates fractal dimension using the box counting method. If lvec is not specified, a default based on resolution and extent will be used. Based on lvec, boxes of different sizes are defined and the function counts boxes that capture the outline of the shape. It is recommended to specify the maximum value of lvec so that the largest box encapsulates the entire object. The smallest scale included in lvec should not be smaller than the resolution of your object.

Examples

mcap_2d <- mesh_to_2d(mcap)

fd_boxes(mcap_2d, plot = TRUE, keep_data = TRUE)

#> $D
#> [1] 1.39879
#> 
#> $lvec
#> [1] 0.39015772 0.19507886 0.09753943 0.04876971 0.02438486 0.01219243
#> 
#> $data
#>            l   n
#> 1 0.39015772   1
#> 2 0.19507886   4
#> 3 0.09753943  11
#> 4 0.04876971  28
#> 5 0.02438486  65
#> 6 0.01219243 138
#> 
#> $method
#> [1] "boxes"
#> 
fd_boxes(mcap_2d, lvec = c(0.05, 0.1, 0.2, 0.4), plot = TRUE)

#> [1] 1.61225