Skip to contents

Plot a polygon.

Usage

plotPolygon3D(
  pts,
  useShade = TRUE,
  useLines = FALSE,
  usePoints = FALSE,
  useFrame = TRUE,
  ...
)

Arguments

pts

Vertices.

useShade

Plot shade of the polygon.

useLines

Plot lines inside the polygon.

usePoints

Plot point shapes inside the polygon.

useFrame

Plot a frame around the polygon.

...

Further arguments passed on the RGL plotting functions. This must be done as lists (see examples). Currently the following arguments are supported:

  • argsShade: A list of arguments for rgl::polygon3d (n > 4 vertices), rgl::triangles3d() (n = 3 vertices) and rgl::quads3d() (n = 4 vertices) if useShade = TRUE.

  • argsFrame: A list of arguments for rgl::lines3d if useFrame = TRUE.

  • argsPoints: A list of arguments for rgl::shade3d if usePoints = TRUE. It is important to give a texture using texture. A texture can be set using getTexture().

  • argsLines: A list of arguments for rgl::persp3d() when useLines = TRUE. Moreover, the list may contain lines: number of lines.

Value

Object ids (invisible).

Examples

# \donttest{
pts <- data.frame(x = c(1,0,0,0.4), y = c(0,1,0,0.3), z = c(0,0,1,0.3))
pts <- data.frame(x = c(1,0,0), y = c(0,1,0), z = c(0,0,1))

ini3D()
plotPolygon3D(pts)
finalize3D()



ini3D()
plotPolygon3D(pts, argsShade = list(color = "red", alpha = 1))
finalize3D()



ini3D()
plotPolygon3D(pts, useFrame = TRUE, argsShade = list(color = "red", alpha = 0.5),
              argsFrame = list(color = "green"))
finalize3D()



ini3D()
plotPolygon3D(pts, useFrame = TRUE, useLines = TRUE, useShade = TRUE,
              argsShade = list(color = "red", alpha = 0.2),
              argsLines = list(color = "blue"))
finalize3D()



ini3D()
ids <- plotPolygon3D(pts, usePoints = TRUE, useFrame = TRUE,
              argsPoints = list(texture = getTexture(pch = 16, cex = 20)))
finalize3D()


# pop3d(id = ids) # remove object again

# In general you have to finetune size and numbers when you use textures
# Different pch
for (i in 0:3) {
  fname <- getTexture(pch = 15+i, cex = 30)
  ini3D(TRUE)
  plotPolygon3D(pts, usePoints = TRUE, argsPoints = list(texture = fname))
  finalize3D()
}

# Size of pch
for (i in 1:4) {
  fname <- getTexture(pch = 15+i, cex = 10 * i)
  ini3D(TRUE)
  plotPolygon3D(pts, usePoints = TRUE, argsPoints = list(texture = fname))
  finalize3D()
}

# Number of pch
fname <- getTexture(pch = 16, cex = 20)
for (i in 1:4) {
  ini3D(TRUE)
  plotPolygon3D(pts, usePoints = TRUE,
                argsPoints = list(texture = fname, texcoords = rbind(pts$x, pts$y, pts$z)*5*i))
  finalize3D()
}
# }