Learn R Programming

vectorialcalculus (version 1.0.5)

solid_xyz3d: Solid defined by bounds in x, y and z

Description

Constructs a three-dimensional solid defined by bounds in the variables x, y y z, and optionally renders it using plotly. The solid is described by:

  • an interval for x between a y b,

  • lower and upper functions in the y direction,

  • lower and upper functions in the z direction that may depend on both x y y.

The function uses a curvilinear-prism parametrization to build meshes for the six faces of the solid. It supports different display modes (faces, wireframe, or both), optional numerical volume computation, and internal slices on coordinate planes (slice arguments are reserved for future extensions and are currently ignored).

Usage

solid_xyz3d(
  H1,
  H2,
  G1,
  G2,
  a,
  b,
  plot = TRUE,
  n_x = 120,
  n_u = 60,
  n_v = 60,
  mode = c("faces", "wireframe", "both"),
  show_faces = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
  colorscales = c("Blues", "Blues", "Greens", "Greens", "Reds", "Reds"),
  opacities = 0.35,
  show_surface_grid = TRUE,
  surface_grid_color = "rgba(60,80,200,0.25)",
  surface_grid_width = 1,
  show_edges = TRUE,
  edge_line = list(color = "black", width = 2),
  wire_step = 6,
  wire_line = list(color = "black", width = 1),
  scene = list(aspectmode = "data", xaxis = list(title = "x"), yaxis = list(title = "y"),
    zaxis = list(title = "z")),
  bg = list(paper = "white", plot = "white"),
  compute_volume = FALSE,
  vol_method = c("adaptive", "grid"),
  nx_vol = 300,
  ny_vol = 300,
  slice = list(x = NULL, y = NULL, z = NULL),
  slice_mode = c("surface", "wireframe", "both"),
  slice_nx = 200,
  slice_nu = 120,
  slice_nv = 120,
  slice_colorscales = list(x = "Oranges", y = "Purples", z = "Greens"),
  slice_opacity = 0.55,
  slice_show_grid = TRUE,
  slice_grid_color = "rgba(80,80,80,0.25)",
  slice_grid_width = 1,
  slice_wire_step = 8,
  slice_wire_line = list(color = "black", width = 2, dash = "dot")
)

Value

A list with:

  • x_seq, u_seq, v_seq: the parameter sequences used to build the mesh,

  • fig: a plotly object when plot = TRUE, otherwise NULL,

  • volume: either NULL or a list with an approximate volume estimate and related metadata when compute_volume = TRUE.

Arguments

H1, H2

Functions of one variable x giving the lower and upper bounds in the y direction.

G1, G2

Functions of two variables x y y giving the lower and upper bounds in the z direction.

a, b

Numeric endpoints of the interval for x. It is assumed that b > a.

plot

Logical; if TRUE, the solid is rendered with plotly.

n_x, n_u, n_v

Integers giving the mesh resolution in the principal parameter along x and in the two internal parameters of the face meshes.

mode

Character string; one of "faces", "wireframe" or "both", indicating whether to draw surfaces, wireframe, or a combination of both.

show_faces

Logical vector indicating which of the six faces to display. The order is c("x=a","x=b","y=H1","y=H2","z=G1","z=G2"). A single logical value is also allowed and will be recycled.

colorscales

Color specification for faces. It can be:

  • a single plotly colorscale name applied to all faces,

  • a single flat color (R color name, hexadecimal code, or "rgba(...)"),

  • a vector of colors that define a gradient,

  • or a list or vector of length six, assigning a scale or color specification to each face separately.

opacities

Numeric values controlling face opacity; may be a single value or a vector of length six.

show_surface_grid

Logical; if TRUE, draws grid lines on the faces.

surface_grid_color, surface_grid_width

Color and width for surface grid lines.

show_edges

Logical; if TRUE, draws the edges of each face.

edge_line

List with style options for edges (for example, color, width and dash pattern).

wire_step

Integer greater or equal to one; controls how many mesh lines are skipped between wireframe lines.

wire_line

List with style options for wireframe lines.

scene

List with 3D scene options for plotly. By default, an aspect ratio based on the data is used.

bg

List specifying background colors for the figure, typically with entries paper and plot.

compute_volume

Logical; if TRUE, computes an approximate volume of the solid.

vol_method

Character string selecting the volume integration method: "adaptive" for nested calls to stats::integrate, or "grid" for a trapezoidal rule on a regular grid.

nx_vol, ny_vol

Integer grid sizes used when vol_method = "grid".

slice

List describing slices to be drawn, with components x, y y z. Each component can be NULL, a single numeric value or a numeric vector of slice positions. (Reserved for future use; currently ignored.)

slice_mode

Character string indicating how to render slices: "surface", "wireframe" or "both". (Reserved for future use; currently ignored.)

slice_nx, slice_nu, slice_nv

Mesh resolutions used to build the slices. (Reserved for future use; currently ignored.)

slice_colorscales

List with color scales for slices in the x, y y z directions, in the same formats accepted by colorscales. (Reserved for future use; currently ignored.)

slice_opacity

Numeric opacity for slices, between 0 and 1. (Reserved for future use; currently ignored.)

slice_show_grid

Logical; if TRUE, draws grid lines on the slices. (Reserved for future use; currently ignored.)

slice_grid_color, slice_grid_width

Color and width for slice grid lines. (Reserved for future use; currently ignored.)

slice_wire_step

Integer controlling the spacing of wireframe lines on slices. (Reserved for future use; currently ignored.)

slice_wire_line

List with style options for slice wireframe lines. (Reserved for future use; currently ignored.)

Details

The solid is sampled on a three-parameter grid. Two of the parameters describe the position on the base region in the x-y plane, and the third parameter interpolates between the lower and upper z bounds. From this parametrization the function constructs the six bounding faces, corresponding to the two extreme values of x, the two extreme values of y, and the two extreme values of z.

Rendering options allow:

  • drawing only the faces of the solid,

  • drawing only a wireframe of the mesh,

  • combining both faces and wireframe,

  • assigning individual color scales and opacities to each face,

  • showing or hiding surface grids and edges.

When internal slices are requested, the intention is to intersect the solid with planes of the form x = constant, y = constant o z = constant. The corresponding slice arguments are reserved for future versions of the function and are not yet implemented.

If compute_volume = TRUE, the function also computes an approximate volume of the solid using either:

  • a nested adaptive integration based on stats::integrate,

  • or a trapezoidal rule on a regular grid in the x y y directions.

Examples

Run this code
# Note: examples avoid plotting for CRAN checks
H1 <- function(x) -1 - x
H2 <- function(x)  1 - x^2
G1 <- function(x, y) y
G2 <- function(x, y) y + 1
s <- solid_xyz3d(
  H1, H2, G1, G2,
  a = -1, b = 1,
  plot = FALSE,
  compute_volume = TRUE,
  vol_method = "grid",
  nx_vol = 50, ny_vol = 50
)
s$volume$estimate

Run the code above in your browser using DataLab