contourLines3d draws contour lines on a surface;
filledContour3d draws filled contours on it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
contourLines3d(obj, ...) ## S3 method for class 'rglId' contourLines3d(obj, ...) ## S3 method for class 'mesh3d' contourLines3d(obj, fn = "z", nlevels = 10, levels = NULL, minVertices = 0, plot = TRUE, ... ) filledContour3d(obj, ...) ## S3 method for class 'rglId' filledContour3d(obj, plot = TRUE, replace = plot, ...) ## S3 method for class '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
Specified contour values.
See Details below.
Whether to draw the lines or return them in a dataframe.
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
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.
"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).
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.
The misc3d package contains the function
to draw contour surfaces in space instead of contour lines
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
# 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) # Draw longitude and latitude lines on a globe lat <- matrix(seq(90, -90, len = 50)*pi/180, 50, 50, byrow = TRUE) long <- matrix(seq(-180, 180, len = 50)*pi/180, 50, 50) r <- 6378.1 # radius of Earth in km x <- r*cos(lat)*cos(long) y <- r*cos(lat)*sin(long) z <- r*sin(lat) open3d() ids <- persp3d(x, y, z, col = "white", texture = system.file("textures/worldsmall.png", package = "rgl"), specular = "black", axes = FALSE, box = FALSE, xlab = "", ylab = "", zlab = "", normal_x = x, normal_y = y, normal_z = z, polygon_offset = 1) contourLines3d(ids, list(latitude = function(x, y, z) asin(z/sqrt(x^2+y^2+z^2))*180/pi, longitude = function(x, y, z) atan2(y, x)*180/pi))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.