The
Polygon is a complex class. It is defined in 2-D only. It is composed of a set of closed polygonal lines, called
Polysets. This Polygon can be used for example to check if a some data information belongs to the polygon or not.
What about holes?
In order to create hole within a Polygon, it suffices to create a the outer part of the polygon and the inner part of the polygon and to join them with a two-way line.
The following example is the proof.
Let us imagine the following polygon whose vertex coordinates are given next:
0.1 0.1
0.7 0.5
0.1 0.9
0.1 0.5
0.2 0.5
0.2 0.4
0.4 0.4
0.4 0.6
0.2 0.6
0.2 0.5
0.1 0.5
0.1 0.1
We can check that the polygon defined above contains 12 vertices and corresponds to a square included within a triangle. The two-way line exists between vertices (0.1, 0.5) and (0.2, 0.5).
To check the shape and impact of the polygon, let us load it in the R object called
poly.
We also create the data base
db with 500 samples generated randomly in a [0,1] square. This high density is meant so as to ensure that there will be some samples contained in the square.
db = db.create(x1=runif(500),x2=runif(500))
We overlay the two objects:
plot(db)
plot(poly,add=T)
We now use the polygon to reject the samples. Then the samples within the triangle are masked off, whereas those contained in the square (a hole in the triangle) are kept:
plot(db.polygon(db,poly,flag.out=TRUE)
plot(poly,add=T)
Hope you are convinced.