Skip to contents

A polyline set is a collections of interior disjoint x-monotone polylines. As with polygon_set they are used as containers for the result of boolean operations on polylines. As they are made up of disjoint polylines any overlapping polylines will be cut at their intersection. The requirement for x-monotonicity also means that a polyline may be split into several even if it doesn't (self)intersect. polyline sets may give rise to polygons if they have closed interior. These faces of the set can be extracted as polygons using as_polygon(). Further, a polyline set can be thought of as a graph structure with the end vertices of the polylines being nodes, and the polylines being edges. The number of connections each node has can be extracted with vert_degree() and its neighbors with vert_neighbors(). Further the vertices that each polyline is associated with can be obtained with polyline_verts().

Usage

polyline_set(polylines)

is_polyline_set(x)

as_polyline_set(x, ...)

n_polylines(x, simplify = FALSE)

Arguments

polylines

A polyclid_polygon vector or a list of these. In the latter case the union of the polygons in each vector is used for the set.

x

A polyclid_polyline_set vector

...

Arguments passed on

simplify

Should the extracted polylines be simplified by joining lines where possible

Value

a polyclid_polygon_set vector

See also

To get a complete overview of the boolean operations possible with polyline sets see the dedicated help page on the topic

Other polylines: polyline()

Other sets: polygon_set()

Examples

sine <- polyline(
  seq(0, 2*pi, length.out = 20),
  sin(seq(0, 2*pi, length.out = 20))
)
loop <- polyline(
  c(0, 5, 6, 5, 0),
  c(-1, 1, 0, -1, 1)
)
ps <- polyline_set(c(sine, loop))

# Vertices are only defined for end points - not points interior to the
# polylines
euclid_plot(vert(ps))
#> Error in plot.xy(xy.coords(x, y), type = type, ...): plot.new has not been called yet

# You can get back the polylines as they are represented or simplified by
# joining lines that meet at vertices with a degree of 2
plot(
  as_polyline(ps[2]),
  col = c("black", "red", "green", "blue")
)
plot(
  as_polyline(ps[2], simplify = TRUE),
  col = c("black", "red", "green", "blue")
)

# If a polyline_set defines a closed area, that can be extracted as a polygon
n_faces(ps)
#> [1] 0 1
as_polygon(ps)
#> <2D polyclid_polygons [1]>
#> [1] [Boundary: 4, Range: <<2.5, -1>, <6, 1>>, Holes: 0]

# A polyline set can be seen as a graph and the relevant info can be obtained
vert_degree(ps[2])
#> [1] 1 2 4 1
vert_neighbors(ps[2])
#> [[1]]
#> [1] 3
#> 
#> [[2]]
#> [1] 3 3
#> 
#> [[3]]
#> [1] 2 2 1 4
#> 
#> [[4]]
#> [1] 3
#> 
polyline_verts(ps[2])
#> [[1]]
#> [1] 3 1
#> 
#> [[2]]
#> [1] 3 2
#> 
#> [[3]]
#> [1] 4 3
#> 
#> [[4]]
#> [1] 2 3
#>