Learn R Programming

vectorialcalculus (version 1.0.5)

solid_cylindrical3d: Cylindrical solid defined by radial and vertical bounds (with optional plot)

Description

Builds and optionally plots, using plotly, a three-dimensional solid described in cylindrical coordinates. The solid is defined by:

  • an angular variable theta in the interval [th_min, th_max],

  • a radial variable r between R1(theta) and R2(theta),

  • and a vertical coordinate z between Z1(r, theta) and Z2(r, theta).

The surface is rendered by sampling a curvilinear grid in the parameters (theta, u, v), where u and v vary in [0, 1] and are used as linear blending variables along the radial and vertical directions, respectively.

When volume computation is requested, the function numerically approximates the triple integral of the form integral theta from th_min to th_max of integral r from R1(theta) to R2(theta) of integral z from Z1(r, theta) to Z2(r, theta) of r dz dr dtheta, which is the standard volume element in cylindrical coordinates.

Usage

solid_cylindrical3d(
  R1,
  R2,
  Z1,
  Z2,
  th_min,
  th_max,
  plot = TRUE,
  n_theta = 160,
  n_u = 70,
  n_v = 70,
  mode = c("faces", "wireframe", "both"),
  colorscale = "Blues",
  opacity = 0.35,
  show_surface_grid = TRUE,
  surface_grid_color = "rgba(60,80,200,0.25)",
  surface_grid_width = 1,
  edge_line = list(color = "black", width = 2),
  wire_line = list(color = "rgba(0,0,0,0.35)", 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"),
  ntheta_vol = 400,
  nr_vol = 400
)

Value

A list with components:

  • theta_seq, u_seq, v_seq: the parameter sequences used for sampling the surface,

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

  • volume: NULL if compute_volume = FALSE, or a list containing the numeric volume estimate and metadata (method and grid parameters) when compute_volume = TRUE.

Arguments

R1, R2

Functions function(theta) giving the inner and outer radius bounds, respectively.

Z1, Z2

Functions function(r, theta) giving the lower and upper z bounds.

th_min, th_max

Angular limits (numeric scalars) with th_max > th_min.

plot

Logical. If TRUE, the solid is plotted using plotly.

n_theta, n_u, n_v

Mesh resolution in theta (angle), u (radial blend) and v (vertical blend).

mode

Character string, one of "faces", "wireframe" or "both", indicating whether to draw only the surface, only a wireframe or both.

colorscale

Plotly colorscale for the surface. It can be a named scale, a single color, or a character vector of colors interpreted as a gradient.

opacity

Surface opacity, a numeric value between 0 and 1.

show_surface_grid

Logical. If TRUE, draws a grid over the surface.

surface_grid_color, surface_grid_width

Color and line width used for the surface grid.

edge_line, wire_line

Line style lists used for the edges and the wireframe lines when those are drawn.

scene, bg

Plotly 3D scene configuration and background colors. The background list typically has entries paper and plot.

compute_volume

Logical. If TRUE, the volume of the solid is approximated numerically.

vol_method

Character string. Either "adaptive", which uses nested stats::integrate, or "grid", which uses the trapezoidal rule over a regular mesh.

ntheta_vol, nr_vol

Mesh sizes in the angular and radial directions used when vol_method = "grid".

Examples

Run this code
# \donttest{
# Example: a quarter-twisted cup
# R in [0, 1 + 0.2*cos(theta)],  z in [0, 1 + 0.5*r]
R1 <- function(theta) 0
R2 <- function(theta) 1 + 0.2*cos(theta)
Z1 <- function(r, theta) 0
Z2 <- function(r, theta) 1 + 0.5*r
solid_cylindrical3d(
  R1, R2, Z1, Z2, th_min = 0, th_max = pi/2,
  plot = FALSE, mode = "both",
  colorscale = c("white", "#2a9d8f"), opacity = 0.35,
  show_surface_grid = TRUE,
  compute_volume = TRUE, vol_method = "adaptive"
)$volume
# }

Run the code above in your browser using DataLab