cgalPolygonWithHoles | R Documentation |
R6 class to represent a CGAL polygon with holes.
new()
Creates a new cgalpolygonWithHoles
object.
cgalPolygonWithHoles$new(outerVertices, holes = list())
outerVertices
a numeric matrix with two columns, the vertices of the outer polygon
holes
a list of numeric matrices, each representing the vertices of a hole; an empty list is allowed
A cgalPolygonWithHoles
object.
library(cgalPolygons) pwh <- cgalPolygonWithHoles$new( squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]]) ) pwh
area()
Area of the polygon with holes.
cgalPolygonWithHoles$area()
A positive number, the area of the polygon.
library(cgalPolygons) pwh <- cgalPolygonWithHoles$new( squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]]) ) pwh$area() # should be 12
boundingBox()
Bounding box of the polygon with holes.
cgalPolygonWithHoles$boundingBox()
A 2x2 matrix giving the lower corner of the bounding box in its first row and the upper corner in its second row.
library(cgalPolygons) pwh <- cgalPolygonWithHoles$new( squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]]) ) pwh$boundingBox()
convexParts()
Decomposition into convex parts of the polygon with holes. The outer polygon as well as the holes must be simple.
cgalPolygonWithHoles$convexParts(method = "triangle")
method
the method used: "triangle"
or "vertical"
A list of matrices; each matrix has two columns and represents a convex polygon.
library(cgalPolygons) pwh <- cgalPolygonWithHoles$new( squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]]) ) cxparts <- pwh$convexParts() pwh$plot(list(), density = 10) invisible( lapply(cxparts, function(cxpart) { polygon(cxpart, lwd = 2) }) )
getVertices()
Get the vertices of the polygon.
cgalPolygonWithHoles$getVertices()
A named list with two fields: "outer"
, the vertices of
the outer polygon in a matrix, and "holes"
, the vertices of
the holes in a list of matrices.
intersection()
Intersection of the polygon with another polygon.
cgalPolygonWithHoles$intersection(plg2)
plg2
a cgalPolygon
object or a cgalPolygonWithHoles
object
A list whose each element is either a cgalPolygon
object
or a cgalPolygonWithHoles
object.
library(cgalPolygons) # function creating a circle circle <- function(x, y, r) { t <- seq(0, 2, length.out = 100)[-1L] t(c(x, y) + r * rbind(cospi(t), sinpi(t))) } # take two circles with a hole plg1 <- cgalPolygonWithHoles$new( circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8)) ) plg2 <- cgalPolygonWithHoles$new( circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8)) ) # intersection plgList <- plg1$intersection(plg2) plg <- plgList[[1]] # plot opar <- par(mar = c(0, 0, 0, 0)) plot( NULL, xlim = c(-2.6, 2.6), ylim = c(-1.6, 1.6), asp = 1, xlab = NA, ylab = NA, axes = FALSE ) plg1$plot(list(lwd = 2), lwd = 2, density = 10, new = FALSE) plg2$plot(list(lwd = 2), lwd = 2, density = 10, new = FALSE) plg$plot(lwd = 4, col = "red", new = FALSE) par(opar)
minkowskiSum()
Minkowski sum of the polygon and another polygon.
cgalPolygonWithHoles$minkowskiSum(plg2, method = "convolution")
plg2
a cgalPolygon
object or a cgalPolygonWithHoles
object, the polygon to add to the reference polygon
method
the method used: "convolution"
, "triangle"
,
"vertical"
or "optimal"
(the method should not change
the result)
Either a cgalPolygonWithHoles
object, or, in the case if
there is no hole in the Minkowski sum, a cgalPolygon
object.
library(cgalPolygons) plg1 <- cgalPolygonWithHoles$new(decagram) plg2 <- cgalPolygonWithHoles$new(star) minko <- plg1$minkowskiSum(plg2) minko$plot(lwd = 2, col = "limegreen")
plot()
Plot the polygon with holes.
cgalPolygonWithHoles$plot( outerpars = list(), ..., new = TRUE, outerfirst = TRUE )
outerpars
named list of arguments passed to
polygon
for the outer polygon
...
arguments passed to polygon
for the
holes
new
Boolean, whether to create a new plot
outerfirst
Boolean, whether to print the outer polygon first
No returned value, called for side-effect.
library(cgalPolygons) pwh <- cgalPolygonWithHoles$new( squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]]) ) pwh$plot( outerpars = list(lwd = 2), density = 10 )
print()
Print the cgalPolygonWithHoles
object.
cgalPolygonWithHoles$print(...)
...
ignored
No value, just prints some information about the polygon.
subtract()
Difference between the polygon and another polygon.
cgalPolygonWithHoles$subtract(plg2)
plg2
a cgalPolygon
object or a cgalPolygonWithHoles
object
A list whose each element is either a cgalPolygon
object
or a cgalPolygonWithHoles
object.
library(cgalPolygons) # function creating a circle circle <- function(x, y, r) { t <- seq(0, 2, length.out = 100)[-1L] t(c(x, y) + r * rbind(cospi(t), sinpi(t))) } # take two circles with a hole plg1 <- cgalPolygonWithHoles$new( circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8)) ) plg2 <- cgalPolygonWithHoles$new( circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8)) ) # difference plgList <- plg1$subtract(plg2) # plot opar <- par(mar = c(0, 0, 0, 0)) plot( NULL, xlim = c(-2.6, 2.6), ylim = c(-1.6, 1.6), asp = 1, xlab = NA, ylab = NA, axes = FALSE ) plgList[[1]]$plot(lwd = 4, col = "red", new = FALSE) plgList[[2]]$plot(lwd = 4, col = "red", new = FALSE) par(opar)
symdiff()
Symmetric difference of the polygon and another polygon.
cgalPolygonWithHoles$symdiff(plg2)
plg2
a cgalPolygon
object or a cgalPolygonWithHoles
object
A list whose each element is either a cgalPolygon
object
or a cgalPolygonWithHoles
object.
library(cgalPolygons) # function creating a circle circle <- function(x, y, r) { t <- seq(0, 2, length.out = 100)[-1L] t(c(x, y) + r * rbind(cospi(t), sinpi(t))) } # take two circles with a hole plg1 <- cgalPolygonWithHoles$new( circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8)) ) plg2 <- cgalPolygonWithHoles$new( circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8)) ) # symmetric difference plgList <- plg1$symdiff(plg2) plg <- plgList[[1L]] # plot opar <- par(mar = c(0, 0, 0, 0)) plg$plot(list(lwd = 4, col = "red"), lwd = 4, col = "white") par(opar)
union()
Union of the polygon with another polygon.
cgalPolygonWithHoles$union(plg2)
plg2
a cgalPolygon
object or a cgalPolygonWithHoles
object
A list whose each element is either a cgalPolygon
object
or a cgalPolygonWithHoles
object.
library(cgalPolygons) # function creating a circle circle <- function(x, y, r) { t <- seq(0, 2, length.out = 100)[-1L] t(c(x, y) + r * rbind(cospi(t), sinpi(t))) } # take two circles with a hole plg1 <- cgalPolygonWithHoles$new( circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8)) ) plg2 <- cgalPolygonWithHoles$new( circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8)) ) # union plgList <- plg1$union(plg2) plg <- plgList[[1]] # plot opar <- par(mar = c(0, 0, 0, 0)) plg$plot(list(lwd = 4, col = "red"), lwd = 4, col = "white") par(opar)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$new`
## ------------------------------------------------
library(cgalPolygons)
pwh <- cgalPolygonWithHoles$new(
squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]])
)
pwh
## ------------------------------------------------
## Method `cgalPolygonWithHoles$area`
## ------------------------------------------------
library(cgalPolygons)
pwh <- cgalPolygonWithHoles$new(
squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]])
)
pwh$area() # should be 12
## ------------------------------------------------
## Method `cgalPolygonWithHoles$boundingBox`
## ------------------------------------------------
library(cgalPolygons)
pwh <- cgalPolygonWithHoles$new(
squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]])
)
pwh$boundingBox()
## ------------------------------------------------
## Method `cgalPolygonWithHoles$convexParts`
## ------------------------------------------------
library(cgalPolygons)
pwh <- cgalPolygonWithHoles$new(
squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]])
)
cxparts <- pwh$convexParts()
pwh$plot(list(), density = 10)
invisible(
lapply(cxparts, function(cxpart) {
polygon(cxpart, lwd = 2)
})
)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$intersection`
## ------------------------------------------------
library(cgalPolygons)
# function creating a circle
circle <- function(x, y, r) {
t <- seq(0, 2, length.out = 100)[-1L]
t(c(x, y) + r * rbind(cospi(t), sinpi(t)))
}
# take two circles with a hole
plg1 <- cgalPolygonWithHoles$new(
circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8))
)
plg2 <- cgalPolygonWithHoles$new(
circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8))
)
# intersection
plgList <- plg1$intersection(plg2)
plg <- plgList[[1]]
# plot
opar <- par(mar = c(0, 0, 0, 0))
plot(
NULL, xlim = c(-2.6, 2.6), ylim = c(-1.6, 1.6), asp = 1,
xlab = NA, ylab = NA, axes = FALSE
)
plg1$plot(list(lwd = 2), lwd = 2, density = 10, new = FALSE)
plg2$plot(list(lwd = 2), lwd = 2, density = 10, new = FALSE)
plg$plot(lwd = 4, col = "red", new = FALSE)
par(opar)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$minkowskiSum`
## ------------------------------------------------
library(cgalPolygons)
plg1 <- cgalPolygonWithHoles$new(decagram)
plg2 <- cgalPolygonWithHoles$new(star)
minko <- plg1$minkowskiSum(plg2)
minko$plot(lwd = 2, col = "limegreen")
## ------------------------------------------------
## Method `cgalPolygonWithHoles$plot`
## ------------------------------------------------
library(cgalPolygons)
pwh <- cgalPolygonWithHoles$new(
squareWithHole[["outerSquare"]], list(squareWithHole[["innerSquare"]])
)
pwh$plot(
outerpars = list(lwd = 2), density = 10
)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$subtract`
## ------------------------------------------------
library(cgalPolygons)
# function creating a circle
circle <- function(x, y, r) {
t <- seq(0, 2, length.out = 100)[-1L]
t(c(x, y) + r * rbind(cospi(t), sinpi(t)))
}
# take two circles with a hole
plg1 <- cgalPolygonWithHoles$new(
circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8))
)
plg2 <- cgalPolygonWithHoles$new(
circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8))
)
# difference
plgList <- plg1$subtract(plg2)
# plot
opar <- par(mar = c(0, 0, 0, 0))
plot(
NULL, xlim = c(-2.6, 2.6), ylim = c(-1.6, 1.6), asp = 1,
xlab = NA, ylab = NA, axes = FALSE
)
plgList[[1]]$plot(lwd = 4, col = "red", new = FALSE)
plgList[[2]]$plot(lwd = 4, col = "red", new = FALSE)
par(opar)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$symdiff`
## ------------------------------------------------
library(cgalPolygons)
# function creating a circle
circle <- function(x, y, r) {
t <- seq(0, 2, length.out = 100)[-1L]
t(c(x, y) + r * rbind(cospi(t), sinpi(t)))
}
# take two circles with a hole
plg1 <- cgalPolygonWithHoles$new(
circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8))
)
plg2 <- cgalPolygonWithHoles$new(
circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8))
)
# symmetric difference
plgList <- plg1$symdiff(plg2)
plg <- plgList[[1L]]
# plot
opar <- par(mar = c(0, 0, 0, 0))
plg$plot(list(lwd = 4, col = "red"), lwd = 4, col = "white")
par(opar)
## ------------------------------------------------
## Method `cgalPolygonWithHoles$union`
## ------------------------------------------------
library(cgalPolygons)
# function creating a circle
circle <- function(x, y, r) {
t <- seq(0, 2, length.out = 100)[-1L]
t(c(x, y) + r * rbind(cospi(t), sinpi(t)))
}
# take two circles with a hole
plg1 <- cgalPolygonWithHoles$new(
circle(-1, 0, 1.5), holes = list(circle(-1, 0, 0.8))
)
plg2 <- cgalPolygonWithHoles$new(
circle(1, 0, 1.5), holes = list(circle(1, 0, 0.8))
)
# union
plgList <- plg1$union(plg2)
plg <- plgList[[1]]
# plot
opar <- par(mar = c(0, 0, 0, 0))
plg$plot(list(lwd = 4, col = "red"), lwd = 4, col = "white")
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.