sort_into_components: Sort edges into components

sort_into_componentsR Documentation

Sort edges into components

Description

This function sorts a set of edges into separate connected components. Each component represents a distinct outline or polygon in the form of connected edges.

Usage

sort_into_components(edges_df)

Arguments

edges_df

A data frame representing edges, with columns:

  • x1, y1: starting coordinates of each edge

  • x2, y2: ending coordinates of each edge

(E.g. the output of alphahull::ahull()$ashape.obj$edges).

Details

The function identifies unique connected components in an undirected graph built from the edges. It first creates unique identifiers for the start and end points of each edge and constructs an undirected graph using these points. Connected components are then determined, and each component is assigned to a separate element in the output list.

Value

A named list of data frames, where each data frame contains the edges belonging to a separate connected component. The names of the list elements are "c1", "c2", etc., representing each unique component.

Examples

# Sample data frame of edges
edges_df <- data.frame(
  x1 = c(0, 1, 2, 3),
  y1 = c(0, 1, 2, 3),
  x2 = c(1, 2, 3, 0),
  y2 = c(1, 2, 3, 0)
)
sort_into_components(edges_df)

theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.