Skip to contents

compute_hausdorff_distance() is an S7 generic that computes the symmetric Hausdorff distance between streamline objects based on their 3-D coordinate matrices, with methods available for the following classes:

The four dispatch cases are:

  • streamline + streamline: returns a single numeric scalar — the symmetric Hausdorff distance between the two streamlines.

  • bundle + missing: returns a symmetric numeric distance matrix of dimension \(n \times n\), where \(n\) is the number of streamlines in the bundle, giving all pairwise Hausdorff distances.

  • bundle + streamline: returns a numeric vector of length \(n\) giving the Hausdorff distance from y to each streamline in x.

  • bundle + bundle: returns a symmetric numeric distance matrix of dimension \((n_x + n_y) \times (n_x + n_y)\), treating the concatenation of all streamlines from x and y as one collection.

Usage

compute_hausdorff_distance(x, y = NULL)

Arguments

x

A streamline or bundle object.

y

A streamline or bundle object, or NULL (default). When NULL and x is a bundle, the pairwise distance matrix within x is returned.

Value

  • A non-negative numeric scalar when both x and y are streamlines.

  • A dist object of size \(n\) when x is a bundle and y is NULL or a bundle (use as.matrix() to expand to a full \(n \times n\) matrix).

  • A numeric vector of length \(n\) when x is a bundle and y is a streamline.

Examples

pts1 <- matrix(runif(30), ncol = 3)
colnames(pts1) <- c("X", "Y", "Z")
sl1 <- streamline(points = pts1)
pts2 <- matrix(runif(30), ncol = 3)
colnames(pts2) <- c("X", "Y", "Z")
sl2 <- streamline(points = pts2)

# streamline x streamline -> scalar
compute_hausdorff_distance(sl1, sl2)
#> [1] 0.652874

# bundle x missing -> pairwise dist object
b <- bundle(streamlines = list(sl1, sl2))
compute_hausdorff_distance(b)
#>          1
#> 2 0.652874
as.matrix(compute_hausdorff_distance(b))
#>          1        2
#> 1 0.000000 0.652874
#> 2 0.652874 0.000000

# bundle x streamline -> vector
compute_hausdorff_distance(b, sl1)
#> [1] 0.000000 0.652874

# bundle x bundle -> combined pairwise matrix
b2 <- bundle(streamlines = list(sl2))
compute_hausdorff_distance(b, b2)
#>          1        2
#> 2 0.652874         
#> 3 0.652874 0.000000