persp3d.tri.Rd
The tri.mesh()
functions in the
interp and tripack packages compute a Delaunay triangulation of a set
of points. These functions display it as a surface.
# S3 method for class 'triSht'
plot3d(x, z, ...)
# S3 method for class 'triSht'
persp3d(x, z, ..., add = FALSE)
# S3 method for class 'triSht'
as.mesh3d(x, z, col = "gray", coords = c("x", "y", "z"),
smooth = TRUE, normals = NULL, texcoords = NULL, ...)
# S3 method for class 'tri'
plot3d(x, z, ...)
# S3 method for class 'tri'
persp3d(x, z, ..., add = FALSE)
# S3 method for class 'tri'
as.mesh3d(x, z, col = "gray", coords = c("x", "y", "z"),
smooth = TRUE, normals = NULL, texcoords = NULL, ...)
A "triSht"
or "tri"
object, produced by the tri.mesh()
function in the interp or tripack packages respectively.
z coordinate values corresponding to each of the nodes in x
.
Whether to add surface to existing plot (add = TRUE
)
or create a new plot (add = FALSE
, the default).
Colors to apply to each vertex in the triangulation. Will be recycled as needed.
See Details below.
Whether to average normals at vertices for a smooth appearance.
User-specified normals at each vertex. Requires smooth = FALSE
.
Texture coordinates at each vertex.
See Details below.
These functions construct a mesh3d
object
corresponding to the triangulation in x
. The
plot3d
and persp3d
methods plot it.
The coords
parameter allows surfaces to be
plotted over any coordinate plane. It should be
a permutation of the column names c("x", "y", "z")
.
The first will be used
as the x coordinate, the second as the y coordinate,
and the third as the z coordinate.
The ...
parameters in plot3d.triSht
and plot3d.tri
are passed to persp3d
; in persp3d.triSht
and persp3d.tri
they are
passed to both as.mesh3d
and persp3d.mesh3d
;
in as.mesh3d.triSht
and as.mesh3d.tri
they are used as material parameters
in a tmesh3d
call.
"tri"
objects may contain constraints. These appear
internally as extra nodes, representing either the inside
or outside of boundaries on the region being triangulated.
Each of these nodes should also have a z
value, but
triangles corresponding entirely to constraint nodes will not
be drawn. In this way complex, non-convex regions can
be triangulated. See the second example below.
If there are duplicate points, the tri.mesh()
functions
will optionally delete some of them. If you choose this option,
the z
values must correspond to the nodes after
deletion, not before.
x <- rnorm(200, sd = 5)
y <- rnorm(200, sd = 5)
r <- sqrt(x^2 + y^2)
z <- 10 * sin(r)/r
col <- cm.colors(20)[1 + round(19*(z - min(z))/diff(range(z)))]
save <- NULL
if ((haveinterp <- requireNamespace("interp", quietly = TRUE))) {
save <- options(rgl.meshColorWarning = FALSE)
dxy <- interp::tri.mesh(x, y)
open3d()
persp3d(dxy, z, col = col, meshColor = "vertices")
}
3D plot
if (haveinterp) {
open3d()
# Do it without smoothing and with a different orientation.
persp3d(dxy, z, col = col, coords = c("z", "x", "y"), smooth = FALSE)
}
3D plot
if (requireNamespace("tripack", quietly = TRUE)) {
if (is.null(save))
save <- options(rgl.meshColorWarning = FALSE)
# Leave a circular hole around (3, 0)
theta <- seq(0, 2*pi, length.out = 30)[-1]
cx <- 2*cos(theta) + 3
cy <- 2*sin(theta)
keep <- (x - 3)^2 + y^2 > 4
dxy2 <- tripack::tri.mesh(x[keep], y[keep])
dxy2 <- tripack::add.constraint(dxy2, cx, cy)
z <- dxy2$x^2 - dxy2$y^2
col <- terrain.colors(20)[1 + round(19*(z - min(z))/diff(range(z)))]
open3d()
persp3d(dxy2, z, col = col)
}
#> Registered S3 methods overwritten by 'tripack':
#> method from
#> plot.voronoi interp
#> plot.voronoi.polygons interp
#> print.voronoi interp
#> print.summary.voronoi interp
#> summary.voronoi interp
3D plot
options(save)