Find intersection, union or set difference of two polygonal regions.
polyclip(A, B, op=c("intersection", "union", "minus", "xor"), ..., eps, x0, y0, fillA=c("evenodd", "nonzero", "positive", "negative"), fillB=c("evenodd", "nonzero", "positive", "negative"))
- Data specifying polygons. See Details.
- Set operation to be performed to combine
- Spatial resolution for coordinates.
- Spatial origin for coordinates.
- Polygon-filling rule for
This is an interface to the polygon-clipping library
Clipper written by Angus Johnson.
Given two polygonal regions
polyclip performs one of the following
op="intersection": set intersection of
op="union": set union of
op="minus": set subtraction (sometimes called set difference): the region covered by
Athat is not covered by
op="xor": exclusive set difference (sometimes called exclusive-or): the region covered by exactly one of the sets
Each of the arguments
B represents a region in the
Euclidean plane bounded by closed polygons. The format of these
arguments is either
- a list containing two components
ygiving the coordinates of the vertices of a single polygon. The last vertex should not repeat the first vertex.
list(x,y)structures giving the coordinates of the vertices of several polygons.
Bthat is specified by the arguments
fillBrespectively. [object Object],[object Object],[object Object],[object Object]
Calculations are performed in integer arithmetic
x0,y0 from the coordinates,
eps, and rounding to the nearest integer.
eps is the effective spatial resolution.
The default values ensure reasonable accuracy.
- Data specifying polygons, in the same format as
Vatti, B. (1992) A generic solution to polygon clipping.
Communications of the ACM 35 (7) 56--63.
Agoston, M.K. (2005)
Computer graphics and geometric modeling:
implementation and algorithms.
Chen, X. and McMains, S. (2005)
Polygon Offsetting by Computing Winding Numbers.
Paper no. DETC2005-85513 in Proceedings of IDETC/CIE 2005
(ASME 2005 International Design Engineering Technical Conferences
and Computers and Information in Engineering Conference),
A <- list(list(x=1:10, y=c(1:5,5:1))) B <- list(list(x=c(2,8,8,2),y=c(0,0,10,10))) plot(c(0,10),c(0,10), type="n", axes=FALSE) polygon(A[]) polygon(B[]) C <- polyclip(A, B) polygon(C[], lwd=3, col=3)