This function computes a numerical approximation of the line integral of a planar vector field along a parametric curve r(t) on the interval from a to b. The derivative of the curve is approximated by finite differences and the integral is evaluated either by an adaptive numerical integrator or by a composite Simpson rule.
line_integral_vector2d(
field,
r,
a,
b,
plot = TRUE,
n_curve = 600,
grid_n = 15,
padding = 0.15,
h = NULL,
method = c("adaptive", "simpson"),
n_simpson = 1000,
arrow_scale = 0.08,
normalize_bias = 1,
field_color = "rgba(0,0,0,0.55)",
field_width = 1.8,
traj_palette = "RdBu",
traj_width = 5,
show_markers = FALSE,
scene = list(aspectmode = "data", xaxis = list(title = "x"), yaxis = list(title = "y"),
zaxis = list(title = "z")),
bg = list(paper = "white", plot = "white")
)A list with components:
value: numeric value of the line integral.
samples: data frame with sampled points, velocities
and power along the trajectory.
fig: plotly object when plot = TRUE,
otherwise NULL.
Vector field in the plane. A function function(x, y) that
returns a numeric vector of length 2 c(Fx, Fy).
Parametric curve in the plane. A function function(t) that
returns a numeric vector of length 2 c(x, y).
Numeric scalar. Left endpoint of the parameter interval.
Numeric scalar. Right endpoint of the parameter interval.
Must satisfy b > a.
Logical. If TRUE, an interactive plotly figure is
created with the field and the curve.
Integer. Number of parameter values used to sample the curve.
Integer. Number of grid points per axis used to draw the vector field arrows.
Numeric scalar. Relative margin added around the bounding box of the curve when building the field grid.
Numeric scalar or NULL. Step size used in the finite
difference approximation of the derivative of the curve. If NULL,
a small step is chosen automatically, based on the length of the interval
b - a.
Character string. Integration method for the line integral.
One of "adaptive" (uses stats::integrate) or
"simpson" (composite Simpson rule).
Integer. Number of subintervals used when
method = "simpson". If it is odd, it is increased by one
internally.
Numeric scalar. Controls the overall length of the field arrows as a fraction of the plot span.
Numeric scalar. Saturation parameter used to avoid extremely long arrows for large field magnitudes.
Character string. Color used for the field arrows.
Numeric scalar. Line width for the field arrows.
Color scale used to represent the power along the trajectory. Passed to plotly as a colorscale name.
Numeric scalar. Line width for the trajectory.
Logical. If TRUE, markers are drawn along the
trajectory in addition to the line.
List with plotly scene options (axis titles, aspect
mode, etc.) passed to plotly::layout().
List with background colors for plotly, with components
paper and plot.
Optionally, the function can build an interactive plotly figure that shows a grid of arrows for the vector field and the curve colored by the local power field(r(t)) * r'(t).
# Simple example:
# field(x, y) = (y, -x), r(t) = (cos t, sin t), t in [0, 2*pi]
line_integral_vector2d(
field = function(x, y) c(y, -x),
r = function(t) c(cos(t), sin(t)),
a = 0, b = 2*pi, plot = FALSE
)
Run the code above in your browser using DataLab