contourLines3d draws contour lines on a surface;
filledContour3d draws filled contours on it.
contourLines3d(obj, ...) # S3 method for rglId contourLines3d(obj, ...) # S3 method for mesh3d contourLines3d(obj, fn = "z", nlevels = 10, levels = NULL, minVertices = 0, plot = TRUE, ... ) filledContour3d(obj, ...) # S3 method for rglId filledContour3d(obj, plot = TRUE, replace = plot, ...) # S3 method for mesh3d filledContour3d(obj, fn = "z", nlevels = 20, levels = pretty(range(values), nlevels), color.palette = function(n) hcl.colors(n, "YlOrRd", rev = TRUE), col = color.palette(length(levels) - 1), minVertices = 0, plot = TRUE, keepValues = FALSE, ... )
The object(s) on which to draw contour lines.
The function(s) to be contoured. See Details.
Suggested number of contour levels if
levels is not given.
Specified contour values.
See Details below.
Whether to draw the lines or return them in a dataframe.
"mesh3d" methods, additional parameters to pass to
when drawing the contour lines or to
when drawing the filled contours. For the
methods, additional parameters to pass to the
Whether to delete the objects that are being contoured.
a color palette function to assign colors in the plot
the actual colors to use in the plot.
whether to save the function values at
each vertex when
plot = FALSE
fn argument can be any
of the following:
a character vector naming one or more functions
a numeric vector with one value per vertex
NULL, indicating that the numeric values
are saved in
a list containing any of the above.
filledContour3d, only one function can be specified.
The special names
"x", "y", "z" may be used in
fn to specify functions returning one of those
coordinates. (If you have existing functions
z() they will be masked by this choice; specify
such functions by value rather than name, e.g.
fn = x
fn = "x".)
fn with formal arguments
z will receive the coordinates of
vertices in those arguments, otherwise they will receive
the coordinates in a single n x 3 matrix. They should
be vectorized and return one value per vertex.
Each of the functions will be evaluated at each vertex
of the surface specified by
obj, and contours will
be drawn assuming the function is linear between vertices.
If contours of a nonlinear function are needed, you may
want to increase
minVertices as described below.
levels is not specified, values will be set
separately for each entry in
pretty(range(values, na.rm = TRUE), nlevels) where
values are the values on the vertices.
minVertices argument is used to improve the
approximation to the contour when the function is non-linear.
In that case, the interpolation between vertices
can be inaccurate. If
minVertices is set to a
10000), then the mesh is modified
by subdivision to have at least that number of vertices,
so that pieces are smaller and the linear interpolation
is more accurate.
To draw contours on a surface, the surface should be drawn
with material property
polygon_offset = 1 (or perhaps
some larger positive value) so that the lines of the contour are not
obscured by the surface.
In R versions prior to 3.6.0, the default
"rglId" method converts the given id values to
a mesh, and calls the
"mesh3d" method returns an object of class
"rglId" corresponding to what was
contourLines3d returns a dataframe containing
c("x", "y", "z", "fn", "level") giving
the coordinates of the endpoints of each line segment,
the name (or index) of the function for this contour, and the
level of the contour.
"mesh3d" object holding the result.
TRUE, the mesh
will contain the values corresponding to each vertex
(with linear approximations at the boundaries).
The misc3d package contains the function
to draw contour surfaces in space instead of contour lines
# Add contourlines in "z" to a persp plot z <- 2 * volcano # Exaggerate the relief x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N) y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W) open3d() id <- persp3d(x, y, z, aspect = "iso", axes = FALSE, box = FALSE, polygon_offset = 1) contourLines3d(id) # "z" is the default function filledContour3d(id, polygon_offset = 1, nlevels = 10, replace = TRUE)