Learn R Programming

vectorialcalculus (version 1.0.5)

xy_region: Planar region between two curves y = H1(x) and y = H2(x)

Description

Constructs a numerical representation of the planar region bounded by two functions of one variable. The region consists of all points whose horizontal coordinate lies between a and b, and whose vertical coordinate lies between the values returned by H1(x) and H2(x). Optionally, the region can be displayed either as a two-dimensional filled subset of the plane or as a thin surface in three dimensions using plotly.

Usage

xy_region(
  H1,
  H2,
  a,
  b,
  D,
  plot = TRUE,
  n_curve = 800,
  fill = FALSE,
  fillcolor = "rgba(49,130,189,0.25)",
  boundary_line = list(color = "blue", width = 2),
  partition_line = list(color = "blue", width = 1),
  show_end_edges = TRUE,
  axis_equal = TRUE,
  as_3d = FALSE,
  plane_z = 0,
  n_u = 30,
  surface_colorscale = "Blues",
  surface_opacity = 0.3,
  show_surface_grid = TRUE,
  surface_grid_color = "rgba(60,80,200,0.25)",
  surface_grid_width = 1,
  scene = list(aspectmode = "data", xaxis = list(title = "x"), yaxis = list(title = "y"),
    zaxis = list(title = "z")),
  bg = list(paper = "white", plot = "white")
)

Value

A list containing:

  • x: the sample points along the horizontal axis,

  • y1, y2: the sampled boundary values,

  • y_low, y_high: the lower and upper envelopes pmin(H1,H2) and pmax(H1,H2),

  • x_part: the partition points used in the horizontal direction,

  • fig: a plotly object for visualization if plot = TRUE and plotly is available; otherwise NULL.

Arguments

H1, H2

Functions of one variable returning the lower and upper vertical bounds at each value of x.

a, b

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

D

Integer giving the number of subdivisions in the horizontal direction (number of vertical strips).

plot

Logical; if TRUE, produces a visualization using plotly.

n_curve

Integer giving the number of points for sampling the boundary curves.

fill

Logical; if TRUE, fills the two-dimensional region.

fillcolor

Character string defining the fill color in 2D mode.

boundary_line

List with plotly style options for drawing the boundary curves.

partition_line

List with style parameters for vertical partition lines.

show_end_edges

Logical; if TRUE, draws boundary segments at the endpoints x = a and x = b.

axis_equal

Logical; if TRUE, enforces equal scaling on both axes in two dimensions.

as_3d

Logical; if TRUE, draws the region as a thin three-dimensional plate.

plane_z

Numeric height at which to draw the region when as_3d = TRUE.

n_u

Integer number of internal subdivisions used for discretization of the region in the cross-section (between lower and upper boundary).

surface_colorscale

Character string specifying a plotly colorscale for the three-dimensional mode.

surface_opacity

Numeric value between 0 and 1 controlling the transparency of the surface in 3D mode.

show_surface_grid

Logical; if TRUE, overlays grid lines on the plotted surface in 3D mode.

surface_grid_color

Character string giving the color of the grid lines in 3D mode.

surface_grid_width

Numeric width of the grid lines in 3D mode.

scene

Optional list of plotly scene parameters for three-dimensional rendering.

bg

Optional list defining the background colors of the figure, typically with components paper and plot.

Details

The function samples the interval [a, b] at n_curve points to represent the boundary curves. The interval [a, b] is also subdivided into D vertical strips. For each strip, the values H1(x) and H2(x) are evaluated to define the vertical bounds of the region.

Depending on the arguments, the function can:

  • build a data grid suitable for numerical integration or visualization,

  • draw a two-dimensional depiction of the region, possibly filled with a selected color,

  • generate a simple three-dimensional visualization where the region is drawn as a thin plate at a chosen height.

Additional options allow drawing grid lines, showing the boundary curves, controlling colors and transparency, and adjusting the aspect ratio.

Examples

Run this code
H1 <- function(x) 0
H2 <- function(x) 1 - x
xy_region(H1, H2, a = 0, b = 1, D = 20, plot = FALSE)

Run the code above in your browser using DataLab