I'm trying to write a generic module that will take a vector-valued function of a space curve and show the animation of a unit tangent vector traversing the curve. I found a really nice example from Artes in an answer to another question. His answer isn't generic, so I tried to generalize it in the form of a module:
UnitTangentParametricPlot3D[vfunction_, intvl_] :=
Module[{p, v, vu},
p[t_] := vfunction;
v[h_] := D[p[t],t];
vu[g_] := Simplify[v[h]/Norm[v[h]]];
Animate[
Show[
ParametricPlot3D[{p[t]}, intvl, Mesh -> Full],
Graphics3D[
Thick, Darker @ Red, Arrow[{p[s], p[s] + vu[s]}]],
PlotRange -> Full,
ViewPoint -> {4, 8, 0},
ImageSize -> 600],
{s, -1, 1}]]
I'm having trouble working with generic functions in the following ways:
- Take a function as module argument a, find its derivative and evaluate it through the animated value s.
- Animate an arrow graphics object
Sorry for missing anything obvious, I'm new to Mathematica.
Updated working code thanks to Henrick's suggestions :
SetAttributes[UnitAnimateParametricPlot3D, HoldAll];
UnitAnimateParametricPlot3D[vfunction_, {x_, a_, b_}, scale_, size_] := Module[{p, v, uT},
Block[{t,k},
p[t_] := Evaluate[vfunction /. {x -> t}];
v[k_] := D[p[t],t]/.{x -> k};
uT[t_]:= Simplify[v[t]/Norm[v[t]]];
];
Animate[
Show[
ParametricPlot3D[ {p[t]}, {x, a, b}, PlotRange -> Automatic, AspectRatio-> 1, Mesh -> Full, ImageSize->size],
Graphics3D[
{Thick, Darker @ Red, Arrow[{p[s], (p[s] + scale*uT[s])}]}],
ViewPoint -> Front,
PerformanceGoal -> "Quality",
ImageSize -> size],
{s,a,b}, AnimationRunning->True, AnimationDirection->ForwardBackward, AnimationRepetitions->3]
]
The new scale_ parameter allows for the user to scale the arrow so they can see it traverse the curve.
The new plot-range now only takes the plot-range of the curve, instead of include the animated vector's range.
PlotRangeofbackgroundand widened it by1. – Henrik Schumacher Mar 01 '18 at 23:28