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.
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
)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.
Function giving the x coordinate of the curve as a function
of the parameter t.
Function giving the y coordinate of the curve as a function
of the parameter t.
Function giving the z coordinate of the curve as a function
of the parameter t.
Lower endpoint of the parameter interval.
Upper endpoint of the parameter interval.
Numeric vector of parameter values at which the principal normal is evaluated and, optionally, plotted.
Step size for the centered finite-difference approximations used to compute derivatives.
Logical; if TRUE, displays a 3D plot of the curve and
the corresponding normal segments using plotly.
Number of points used to sample and draw the curve for plotting purposes.
Base length used for the normal segments. If
NULL, it is estimated as a small fraction of the overall size
of the sampled curve.
Multiplicative factor applied to vec_scale to
control the visual length of the normal segments.
List with plotly style options for the base curve.
List with plotly style options for the normal segments.
Logical; if TRUE, the base curve is drawn.
Logical; if TRUE, the evaluation points are
marked on the curve.
List with plotly marker options for the evaluation points.
List with 3D scene settings for plotly.
Background colors for the figure, given as a list with entries
such as paper and plot.
Numeric tolerance used to detect singular or nearly singular situations in which the normal direction cannot be computed reliably.
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.
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