Learn R Programming

vectorialcalculus (version 1.0.5)

surface_parametric_area: Plot a parametric surface and estimate its area

Description

This function plots a smooth parametric surface defined by functions x(u,v), y(u,v), and z(u,v). It also estimates the surface area using a trapezoidal approximation based on the magnitudes of partial-derivative cross products.

Usage

surface_parametric_area(
  xfun,
  yfun,
  zfun,
  urange = c(0, 2 * pi),
  vrange = c(0, 2 * pi),
  nu = 160,
  nv = 160,
  h_u = NULL,
  h_v = NULL,
  title_prefix = "r(u,v)"
)

Value

A list with:

  • plot: a plotly surface object showing the parametric surface.

  • area: numeric estimate of the surface area.

  • grid: list with elements U, V, X, Y, and Z, representing the parameter values and evaluated surface.

Arguments

xfun

Function of two arguments (u, v) returning the x-coordinate of the surface.

yfun

Function of two arguments (u, v) returning the y-coordinate of the surface.

zfun

Function of two arguments (u, v) returning the z-coordinate of the surface.

urange

Numeric vector of length 2 giving the interval for the parameter u, c(u_min, u_max) with u_max > u_min.

vrange

Numeric vector of length 2 giving the interval for the parameter v, c(v_min, v_max) with v_max > v_min.

nu

Integer, number of grid points along u (recommended: at least 20 for a reasonable surface).

nv

Integer, number of grid points along v (recommended: at least 20).

h_u

Numeric step size for finite differences in u. If NULL, a default based on the grid spacing is used.

h_v

Numeric step size for finite differences in v. If NULL, a default based on the grid spacing is used.

title_prefix

Character string used in the plot title.

Details

The parametric domain is given by ranges for u and v, and the surface is evaluated on a regular grid with sizes specified by nu and nv. Finite differences are used to approximate partial derivatives with respect to u and v.

Examples

Run this code
if (interactive()) {
# Example: torus-like parametric surface
xfun <- function(u, v) (2 + cos(v)) * cos(u)
yfun <- function(u, v) (2 + cos(v)) * sin(u)
zfun <- function(u, v) sin(v)
result <- surface_parametric_area(
  xfun, yfun, zfun,
  urange = c(0, 2*pi),
  vrange = c(0, 2*pi),
  nu = 80, nv = 80
)
result$area
}

Run the code above in your browser using DataLab