Learn R Programming

vectorialcalculus (version 1.0.5)

normal3d: Principal normal vectors along a 3D curve

Description

Computes numerical principal normal vectors of a three-dimensional parametric curve at several parameter values. The curve is described by three coordinate functions X, Y and Z. At each evaluation point, the function approximates the first and second derivatives of the curve, builds the unit tangent and binormal vectors, and then obtains the principal normal as the unit vector orthogonal to both of them.

Usage

normal3d(
  X,
  Y,
  Z,
  a,
  b,
  t_points,
  h = 1e-04,
  plot = FALSE,
  n_samples = 400,
  vec_scale = NULL,
  vec_factor = 1,
  curve_line = list(color = "blue", width = 2, dash = "solid"),
  N_line = list(color = "green", width = 5, dash = "solid"),
  show_curve = TRUE,
  show_points = TRUE,
  point_marker = list(color = "black", size = 3, symbol = "circle"),
  scene = list(aspectmode = "data", xaxis = list(title = "x(t)"), yaxis = list(title =
    "y(t)"), zaxis = list(title = "z(t)")),
  bg = list(paper = "white", plot = "white"),
  tol = 1e-10
)

Value

A tibble with columns t, x, y, z, Nx, Ny and Nz, where the last three columns contain the components of the principal normal vector at each parameter value.

Arguments

X

Function giving the x coordinate of the curve as a function of the parameter t.

Y

Function giving the y coordinate of the curve as a function of the parameter t.

Z

Function giving the z coordinate of the curve as a function of the parameter t.

a

Lower endpoint of the parameter interval.

b

Upper endpoint of the parameter interval.

t_points

Numeric vector of parameter values at which the principal normal is evaluated and, optionally, plotted.

h

Step size for the centered finite-difference approximations used to compute derivatives.

plot

Logical; if TRUE, displays a 3D plot of the curve and the corresponding normal segments using plotly.

n_samples

Number of points used to sample and draw the curve for plotting purposes.

vec_scale

Base length used for the normal segments. If NULL, it is estimated as a small fraction of the overall size of the sampled curve.

vec_factor

Multiplicative factor applied to vec_scale to control the visual length of the normal segments.

curve_line

List with plotly style options for the base curve.

N_line

List with plotly style options for the normal segments.

show_curve

Logical; if TRUE, the base curve is drawn.

show_points

Logical; if TRUE, the evaluation points are marked on the curve.

point_marker

List with plotly marker options for the evaluation points.

scene

List with 3D scene settings for plotly.

bg

Background colors for the figure, given as a list with entries such as paper and plot.

tol

Numeric tolerance used to detect singular or nearly singular situations in which the normal direction cannot be computed reliably.

Details

For every parameter value in t_points, the function:

  • approximates the first derivative of the curve with respect to the parameter,

  • normalizes this derivative to obtain a unit tangent direction,

  • uses the first and second derivative vectors to construct a direction orthogonal to the tangent and interprets it as a binormal direction,

  • builds the principal normal direction as a unit vector orthogonal to both the tangent and the binormal.

When the curvature of the curve at a given parameter value is extremely small, the normal direction becomes poorly defined from a numerical point of view. In such situations, the function marks the corresponding components of the normal vector as NA.

Optionally, the function can display the curve and the associated normal segments in a 3D interactive plot using plotly. The base curve, the evaluation points and the normal segments can be shown or hidden independently.

Examples

Run this code
X <- function(t) t*cos(t)
Y <- function(t) t*sin(3*t)
Z <- function(t) t
normal3d(X, Y, Z, a = 0, b = 2*pi, t_points = c(pi/3, pi, 5*pi/3))

Run the code above in your browser using DataLab