Learn R Programming

vectorialcalculus (version 1.0.5)

line_integral3d_work: 3D line integral with work visualization

Description

Compute a numerical approximation of the line integral of a vector field along a parametric space curve and optionally draw a three dimensional visualization of the curve together with arrows of the field.

Usage

line_integral3d_work(
  field,
  r,
  a,
  b,
  plot = TRUE,
  n_curve = 600,
  n_field = 7,
  field_ranges = NULL,
  pad = 0.15,
  arrows = c("both", "line", "cone", "none"),
  arrow_scale = 0.1,
  normalize_bias = 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 with components:

  • value: numeric value of the line integral (work).

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

  • field_box: list with numeric ranges used for the field grid, with components x, y and z.

Arguments

field

Function that represents the vector field. It must be a function of three or four numeric arguments. In the three argument form the arguments are x, y and z. In the four argument form the arguments are x, y, z and t. The function must return a numeric vector of length three.

r

Function of one numeric argument t that returns a numeric vector c(x, y, z) of length three with the coordinates of the curve.

a

Numeric scalar with the lower value of the parameter interval.

b

Numeric scalar with the upper value of the parameter interval. It must satisfy b > a.

plot

Logical value. If TRUE, a plotly object with the field arrows and the curve is created.

n_curve

Integer number of sampled points on the curve.

n_field

Integer number of grid points per axis for the field arrows. The total number of arrows is n_field^3.

field_ranges

Optional list with named components x, y and z, each a numeric vector of length two giving the range used to build the field grid. If NULL, the ranges are taken from the bounding box of the curve and expanded by pad.

pad

Numeric fraction used to expand the automatic field ranges.

arrows

Character string that selects which arrow style is drawn. One of "both", "line", "cone" or "none".

arrow_scale

Numeric factor that controls the length of the arrows as a fraction of the size of the domain.

normalize_bias

Numeric value used to regularize the scaling of the field magnitude when computing arrows.

scene

List of plotly scene options passed to plotly::layout().

bg

List with two character elements named paper and plot that control the background colours in the plotly layout.

Details

The parameter t runs from a to b. The curve r(t) must return a numeric vector of length three. The field field(x, y, z) may optionally also depend on t through a fourth argument.

Examples

Run this code
# \donttest{
field <- function(x, y, z) c(-y, x, 0.2*z)
r <- function(t) c(cos(t), sin(t), 0.25*t)
out <- line_integral3d_work(
  field = field, r = r, a = 0, b = 2*pi,
  plot = FALSE, n_curve = 200, n_field = 5
)
out$value
# }

Run the code above in your browser using DataLab