Computes numerical unit tangent vectors of a three-dimensional parametric curve at selected values of the parameter. The curve is defined by three functions that give its coordinate components. For each evaluation point, the first derivative of the curve is approximated numerically and then normalized to obtain a unit tangent direction.
tangent3d(
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"),
T_line = list(color = "red", 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,
Tx, Ty and Tz, where the last three columns contain
the components of the unit tangent vector at each evaluation point.
Function returning the x coordinate of the curve as a
function of the parameter t.
Function returning the y coordinate of the curve as a
function of the parameter t.
Function returning 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 tangent direction is evaluated and optionally plotted.
Step size for centered finite-difference approximations.
Logical; if TRUE, shows a 3D plotly visualization
of the curve and tangent segments.
Number of points used to sample and display the curve in the 3D plot.
Base length used for the tangent 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 size of the tangent segments.
List with plotly style options for drawing the base curve.
List with plotly style options for the tangent segments.
Logical; if TRUE, the base curve is included in
the plot.
Logical; if TRUE, the evaluation points are
marked in the plot.
List with plotly marker options for the evaluation points.
List with 3D scene settings for plotly.
Background colors for the figure, usually a list with entries
such as paper and plot.
Numeric tolerance for detecting situations in which the first derivative is too small to define a stable tangent direction.
For every element of t_points, the function:
computes a centered finite-difference approximation of the first derivative of the curve,
evaluates the magnitude of that derivative,
divides the derivative by its magnitude to obtain a unit vector pointing in the direction of motion of the curve at that point.
If the magnitude of the first derivative is extremely small at a given
parameter value, the tangent direction becomes numerically unstable; in
such cases, the function returns NA for the corresponding
components and may emit a diagnostic message.
Optionally, the curve and the associated tangent directions can be shown in an interactive 3D plot using plotly. Short line segments representing the tangent direction can be anchored at each evaluation point. The sampled curve, the reference points and the tangent segments may be displayed or hidden independently.
X <- function(t) t*cos(t)
Y <- function(t) t*sin(3*t)
Z <- function(t) t
tangent3d(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