segments_to_vertices: Transform segments to vertices

View source: R/s.R

segments_to_verticesR Documentation

Transform segments to vertices

Description

This function takes a data frame of arcs (segments) and constructs an ordered sequence of vertices to outline a connected, non-intersecting polygon.

Usage

segments_to_vertices(arcs_df)

Arguments

arcs_df

A data frame containing arc information with columns:

  • x1, y1: Starting coordinates of each segment

  • x2, y2: Ending coordinates of each segment

  • idx: An identifier for each segment

Details

This function iteratively selects arcs that connect to form a polygon. If an arc’s endpoint does not match any available arc’s start or endpoint, it selects the nearest arc using a nearest-neighbor search. Segments that would cause intersections are removed. If the constructed polygon closes on itself, it terminates the process.

Value

A data frame (outline_df) containing the vertices (x, y coordinates and idx) that form the ordered outline of the polygon.

Examples


# Sample data frame of arcs

arcs_df <- data.frame(
  x1 = c(0, 1, 2),
  y1 = c(0, 1, 0),
  x2 = c(1, 2, 0),
  y2 = c(1, 0, 0),
  idx = c(1, 2, 3)
)
segments_to_vertices(arcs_df)



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