% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mesh-patch.R
\name{vcg_mesh_patch}
\alias{vcg_mesh_patch}
\title{Split a mesh into two patches along a geodesic boundary}
\usage{
vcg_mesh_patch(mesh, waypoints, seed_vertex = NULL, max_edge_length = NA)
}
\arguments{
\item{mesh}{triangular mesh of class \code{'mesh3d'}.}

\item{waypoints}{numeric matrix with exactly 3 columns (\code{x}, \code{y},
\code{z}) and at least 3 rows; each row is a 3-D coordinate defining a
boundary corner. After any mesh subdivision, each coordinate is snapped to
the nearest vertex in the (possibly refined) mesh. Consecutive snapped
vertices are joined by geodesic paths to form the closed boundary loop.}

\item{seed_vertex}{integer (optional, 1-based). A vertex known to be inside
the desired first patch. When \code{NULL} (default) the smaller of the
two regions is returned first.}

\item{max_edge_length}{numeric (optional). When positive and finite, the mesh
is refined before patching so that no edge exceeds this length. Global
edge subdivision (\code{\link{vcg_subdivision}}) is applied repeatedly
until the average edge length falls below the threshold (fast), then
\code{\link{vcg_subdivide_max_edge_length}} handles any remaining outlier
edges. \verb{Waypoint} coordinates are snapped to vertices after
refinement, so finer vertices improve boundary accuracy.
Default \code{NA} (no refinement).}
}
\value{
A length-2 list of \code{mesh3d} objects. Each contains:
\describe{
  \item{\code{$orig_vertex}}{1-based integer vector: new vertex index \code{i}
    corresponds to column \code{orig_vertex[i]} of the original \code{mesh$vb}.}
}
The first element is the patch whose centroid is closest to the mean
\verb{waypoint} position; the second is the complementary connected patch.
On a multi-manifold mesh, disconnected components not adjacent to the
boundary loop appear in neither patch. When the boundary loop does not
divide the mesh (degenerate \verb{waypoints}), the second element is
\code{NULL}.
}
\description{
Connects a set of surface \verb{waypoints} with geodesic paths to form a
closed boundary loop, then splits the mesh into the two regions created by
that loop.

Consecutive \verb{waypoints} are joined by the geodesic (Dijkstra) shortest
path along the mesh surface; the last \verb{waypoint} connects back to the
first.
}
\note{
All \verb{waypoints} must lie on the same connected component of the mesh.
  The mesh should be manifold; run \code{\link{vcg_fix_defects}} first
  if needed.
}
\examples{

mesh <- vcg_sphere()
mesh <- vcg_uniform_remesh(mesh)

waypoints <- diag(1, 3)
patches <- vcg_mesh_patch(mesh, waypoints)

plot_mesh_polygon(
  patches,
  col = list("red", 'gray'),
  alpha = list(1, 0.5),
  eye = c(10, 10, 10)
)


}
\seealso{
\code{\link{dijkstras_surface_distance}}, \code{\link{surface_path}},
  \code{\link{vcg_fix_defects}}
}
