This function attempts to remove self-intersections and duplicated vertices from the given polygon.
Data specifying a polygon or polygons. See Details.
Spatial resolution for coordinates.
Spatial origin for coordinates.
Polygon-filling rule. See Details.
This is an interface to the function
C++ library Clipper.
It tries to remove self-intersections from the supplied polygon,
by performing a boolean union operation using the nominated
filltype. The result may be one or several polygons.
A should be either
a list containing two components
giving 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.
filltype determines the polygon fill type.
The default rule is even-odd filling, in which every polygon edge demarcates a boundary between the inside and outside of the region. It does not matter whether a polygon is traversed in clockwise or anticlockwise order. Holes are determined simply by their locations relative to other polygons such that outers contain holes and holes contain outers.
Under the nonzero filling rule, an outer boundary must be traversed in clockwise order, while a hole must be traversed in anticlockwise order.
positive filling rule, the filled region
consists of all points with positive winding number.
negative filling rule, the filled region
consists of all points with negative winding number.
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
Angus Johnson. Ported to R by Adrian Baddeley [email protected].
Clipper Website: http://www.angusj.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
theta <- 2 * pi * (0:5) * 2/5 A <- list(list(x=sin(theta), y=cos(theta))) B <- polysimplify(A, filltype="nonzero") opa <- par(mfrow=c(1,2)) plot(c(-1,1),c(-1,1), type="n", axes=FALSE, xlab="", ylab="") with(A[], segments(x[-6], y[-6], x[-1], y[-1], col="red")) points(A[], col="red") with(A[], text(x[1:5], y[1:5], labels=1:5, cex=2)) plot(c(-1,1),c(-1,1), type="n", axes=FALSE, xlab="", ylab="") polygon(B[], lwd=3, col="green") with(B[], text(x,y,labels=seq_along(x), cex=2)) par(opa)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.