# Animate a triangle that follows a curve

Given:

r[t_] := {Sin[t], Sin[2 t]}
uT[t_] := Simplify[r'[t]/Norm[r'[t]], t \[Element] Reals]

Animate[Show[ParametricPlot[{r[t]}, {t, -\[Pi], \[Pi]}],
Graphics[{{Line[{{Sin[t], Sin[2 t]}, {-(Cos[t]/Sqrt[Cos[t]^2 + 4 Cos[2 t]^2]) +
Sin[t], -((2 Cos[2 t])/Sqrt[Cos[t]^2 + 4 Cos[2 t]^2]) +
Sin[2 t]}}]}}], PlotRange -> {{-2, 2}, {-2, 2}}], {t, 0, 2 \[Pi]},
AnimationRunning -> False]


How do I replace the line with a triangle, to follow the curve as the picture below shows?

• You changed your problem definition, but you failed to keep a record of that in your question. Now my answer is lingering as if I didn't understand your problem. Please edit the question to reflect that the initial statement has been changed. Thank you. Oct 24, 2013 at 17:38
• @belisarius I suggest you edit the question yourself to include what you were originally answering; IMO this is appropriate such cases. Oct 24, 2013 at 18:24
• @Mr.Wizard The original question didn't have the specification for the triangle orientation. I'm trying to offer the OP the opportunity to be courteous. Oct 24, 2013 at 18:29

<< Polytopes
v = 1/10 Vertices[Triangle];
tri0 = {Translate[Rotate[ Line@ { v, RotateLeft@v}, Pi/2, {0, 0}], {0, 1/2 v[[1, 2]]}]};
tri[tri0_, pos_, angle_] := Translate[Rotate[tri0, angle, {0, 0}], pos]
ang[t_] := If[# === Indeterminate, Pi/2, #] &@ (ArcTan[k'[p][[2]]/k'[p][[1]]] /. p -> t)

k[t_] := {Cos[3 t], Sin[ 2 t ]};
Manipulate[ParametricPlot[k[t], {t, 0, 2 Pi}, Epilog -> tri[tri0, k[m], ang[m]]], {m, 0, 2 Pi}]


One way is to use a custom arrowhead:

plot = ParametricPlot[{r[t]}, {t, -Pi, Pi}];
tri = Graphics[{EdgeForm[Directive[Opacity[1], Purple, Thick]],
Opacity[0], Polygon[{{0, 0}, {-1, 0.5}, {-1, -0.5}}]}];

Animate[Show[
plot,
Graphics[{
Opacity[0], Arrow[{r[t] - 0.1 r'[t], r[t]}]}],
PlotRange -> {{-2, 2}, {-2, 2}}],
{t, 0, 2 Pi}, AnimationRunning -> False]


One could also use a small, finite difference Arrow[{r[t - 0.01], r[t]}] instead of the derivative above.

Given a trajectory {x[t],y[t]}, the velocity vector is tangent D[{x[t],y[t]},t].

To find the angle that the velocity vector makes with the x axis you can use ArcTan. Because of the initial orientation of your triangle definition, we also have to add Pi/2.

Animate[
Show[
Graphics[{Translate[Rotate[
{Line[{{9/2, 7}, {7/2, 7}, {4, 3}, {9/2, 7}}]},
Pi/2 + ArcTan[Cos[t], 2 Cos[2 t]], {4, 3}],{Sin[t], Sin[2 t]}],
PointSize[Large], Red, Point[{Sin[t], Sin[2 t]}+{4,3}]
},PlotRange -> {{-2, 10}, {-2, 10}}],
ParametricPlot[{Sin[x], Sin[2 x]}+{4,3}, {x, 0, 2 Pi}]
], {t, 0, 2 Pi}, AnimationRunning -> False]


Variation on a theme (but using equilateral triangle not arbitrary)

mt[u_] :=
Prepend[Differences[
Join @@ NestList[{#[[2]],
RotationTransform[60 Degree, #[[2]]][#[[1]]]} &, {Normalize@u,
1.1 Normalize@u}, 3]] /. {0., 0.} -> Sequence[], {0, 0}]
fnc[t_] := {Cos[3 t], Sin[2 t]};
tg[u_] := D[fnc[t], t] /. t -> u;
Manipulate[
ParametricPlot[fnc[t], {t, 0, 2 Pi},
Epilog -> Polygon[(fnc[q] + # & /@ mt[tg[q]])],
PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}], {q, 0, 2 Pi}]
`