Description Usage Arguments Details Note Examples

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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
## 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, ...)
``` |

`x` |
A |

`z` |
z coordinate values corresponding to each of the nodes in |

`add` |
Whether to add surface to existing plot ( |

`col` |
Colors to apply to each vertex in the triangulation. Will be recycled as needed. |

`coords` |
See Details below. |

`smooth` |
Whether to average normals at vertices for a smooth appearance. |

`normals` |
User-specified normals at each vertex. Requires |

`texcoords` |
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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ```
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")
}
if (haveinterp) {
open3d()
# Do it without smoothing and with a different orientation.
persp3d(dxy, z, col = col, coords = c("z", "x", "y"), smooth = FALSE)
}
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, len = 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)
}
options(save)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.