plotConvexHull3D: Plot 3D convex hull

View source: R/convexhull.R

plotConvexHull3DR Documentation

Plot 3D convex hull

Description

Plot a 3D convex hull with rgl.

Usage

plotConvexHull3D(
  hull,
  color = "distinct",
  hue = "random",
  luminosity = "light",
  alpha = 1,
  edgesAsTubes = FALSE,
  tubeRadius,
  tubeColor
)

Arguments

hull

the output of convexhull with 3D points

color

controls the colors of the faces, either FALSE for no color, "random" to use randomColor, "distinct" to use distinctColorPalette, or a single color

hue, luminosity

if color="random", these arguments are passed to randomColor

alpha

opacity, number between 0 and 1

edgesAsTubes

Boolean, whether to plot the edges as tubes

tubeRadius

if edgesAsTubes=TRUE, the radius of the tubes

tubeColor

if edgesAsTubes=TRUE, the color of the tubes

Value

No value, just renders a 3D plot.

Examples

library(RCGAL)
library(rgl)
# blue dodecahedron with edges as tubes ####
dodecahedron <- t(dodecahedron3d()$vb[-4, ])
hull <- convexhull(dodecahedron)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(
  hull, color = "navy", edgesAsTubes = TRUE,
  tubeRadius = 0.03, tubeColor = "gold"
)

# the dodecahedron with multiple colors ####
hull <- convexhull(dodecahedron, faceFamilies = TRUE)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(hull, color = "random", luminosity = "bright")

# a strange convex hull ####
pt <- function(x){
  c(
    sin(x) * cos(2 * x),
    sin(x) * sin(2 * x),
    cos(x)
  )
}
pts <- t(vapply(seq(0, pi, length.out = 50), pt, numeric(3L)))
hull <- convexhull(pts)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(hull, color = "random", hue = "purple", luminosity = "dark")

# Leonardo da Vinci's 72-sided sphere: the `epsilon` parameter ####
# the points of da Vinci's 72 sided sphere:
pts <- rbind(
  c(1.61352, -0.43234, 1.1862),
  c(1.18118, -1.18118, 1.1862),
  c(0.43234, -1.61352, 1.1862),
  c(-0.43234, -1.61352, 1.1862),
  c(-1.18118, -1.18118, 1.1862),
  c(-1.61352, -0.43234, 1.1862),
  c(-1.61352, 0.43234, 1.1862),
  c(-1.18118, 1.18118, 1.1862),
  c(-0.43234, 1.61352, 1.1862),
  c(0.43234, 1.61352, 1.1862),
  c(1.18118, 1.18118, 1.1862),
  c(1.61352, 0.43234, 1.1862),
  c(1.61352, -0.43234, -1.1862),
  c(1.61352, 0.43234, -1.1862),
  c(1.18118, 1.18118, -1.1862),
  c(0.43234, 1.61352, -1.1862),
  c(-0.43234, 1.61352, -1.1862),
  c(-1.18118, 1.18118, -1.1862),
  c(-1.61352, 0.43234, -1.1862),
  c(-1.61352, -0.43234, -1.1862),
  c(-1.18118, -1.18118, -1.1862),
  c(-0.43234, -1.61352, -1.1862),
  c(0.43234, -1.61352, -1.1862),
  c(1.18118, -1.18118, -1.1862),
  c(2.0102, 0.53863, 0),
  c(1.47157, 1.47157, 0),
  c(0.53863, 2.0102, 0),
  c(-0.53863, 2.0102, 0),
  c(-1.47157, 1.47157, 0),
  c(-2.0102, 0.53863, 0),
  c(-2.0102, -0.53863, 0),
  c(-1.47157, -1.47157, 0),
  c(-0.53863, -2.0102, 0),
  c(0.53863, -2.0102, 0),
  c(1.47157, -1.47157, 0),
  c(2.0102, -0.53863, 0),
  c(0.89068, 0.23866, 1.77777),
  c(0.89068, -0.23866, 1.77777),
  c(0.65202, -0.65202, 1.77777),
  c(0.23866, -0.89068, 1.77777),
  c(-0.23866, -0.89068, 1.77777),
  c(-0.65202, -0.65202, 1.77777),
  c(-0.89068, -0.23866, 1.77777),
  c(-0.89068, 0.23866, 1.77777),
  c(-0.65202, 0.65202, 1.77777),
  c(-0.23866, 0.89068, 1.77777),
  c(0.23866, 0.89068, 1.77777),
  c(0.65202, 0.65202, 1.77777),
  c(0.65202, -0.65202, -1.77777),
  c(0.89068, -0.23866, -1.77777),
  c(0.89068, 0.23866, -1.77777),
  c(0.65202, 0.65202, -1.77777),
  c(0.23866, 0.89068, -1.77777),
  c(-0.23866, 0.89068, -1.77777),
  c(-0.65202, 0.65202, -1.77777),
  c(-0.89068, 0.23866, -1.77777),
  c(-0.89068, -0.23866, -1.77777),
  c(-0.65202, -0.65202, -1.77777),
  c(-0.23866, -0.89068, -1.77777),
  c(0.23866, -0.89068, -1.77777),
  c(0, 0, 2.04922),
  c(0, 0, -2.04922)
)

# with the default `epsilon`, some triangular faces are not merged:
hull <- convexhull(pts, faceFamilies = TRUE)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(hull, color = "random", hue = "pink")

# so one has to increase `epsilon`:
hull <- convexhull(pts, faceFamilies = TRUE, epsilon = 1e-5)
open3d(windowRect = c(50, 50, 562, 562))
plotConvexHull3D(hull, color = "random", hue = "orange", luminosity = "bright")

stla/RCGAL documentation built on June 15, 2022, 6:45 a.m.