Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]

enter image description here

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

enter image description here

share|improve this question
    
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. –  belisarius Oct 24 '13 at 17:38
    
@belisarius I suggest you edit the question yourself to include what you were originally answering; IMO this is appropriate such cases. –  Mr.Wizard Oct 24 '13 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. –  belisarius Oct 24 '13 at 18:29
add comment

4 Answers 4

up vote 10 down vote accepted
<< 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}]

enter image description here

share|improve this answer
add comment

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[{
    Arrowheads[{{Automatic, Automatic, tri}}], 
    Opacity[0], Arrow[{r[t] - 0.1 r'[t], r[t]}]}],
  PlotRange -> {{-2, 2}, {-2, 2}}],
 {t, 0, 2 Pi}, AnimationRunning -> False]

Mathematica graphics

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

share|improve this answer
add comment

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]
share|improve this answer
add comment

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}]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.