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.

I am trying to show vector of fixed length which is the tangent to a circle which rotates. Any suggestions on how to simplify this ? My question is not about using Manipulate etc but more is there an easier way to compute and draw the tangent ?

x[t_] := Cos[t];
y[t_] := Sin[t];
d[x_, y_] := If[y == 0, 0, -x/y];
tangent[1, 0] = Arrow[{{1, 0}, {1, 1}}];
tangent[-1, 0] = Arrow[{{-1, 0}, {-1, -1}}];
tangent[0, -1] = Arrow[{{0, -1}, {1, -1}}];
tangent[0, 1] = Arrow[{{0, 1}, {1, 1}}];
tangent[x_, y_] = 
  If[y > 0, 
   Arrow[{{x, y}, {x - Cos[ArcTan[d[x, y]]], 
      y - Sin[ArcTan[ d[x, y]]]}}],
   Arrow[{{x, y}, {x + Cos[ArcTan[d[x, y]]], 
      y + Sin[ArcTan[ d[x, y]]]}}]];
Manipulate[
 p = ParametricPlot[{x[t], y[t]}, {t, 0, 2 \[Pi]}, 
   PlotRange -> {-2, 2}];
 g = Graphics[{{Blue, Line[{{0, 0}, {x[a], y[a]}}]}, {Red, 
     tangent[x[a], y[a]]}}];
 Show[{p, g}],
 {a, 0, 2 \[Pi]}]

Moving tangent

I extended my example above to include a 3D solution using suggested solutions -

Module[{x,y,z,tangent},
x[t_]:=Cos[t];
y[t_]:=Sin[t];
z[t_]:=0;
r ={{-2,2},{-2,2},{-2,2}};
p=ParametricPlot3D[{x[t],y[t],z[t]},{t,0,2\[Pi]},PlotRange->r,BoxRatios->1];
tangent[x_,y_,z_]:={Red,Arrow[{{x,y,z},{x-y,x+y,z}}]};
Manipulate[
g :=Graphics3D[{Sphere[{x[t],y[t],z[t]},0.2],
{Green,Arrow[{{x[t],y[t],z[t]},{x[t],y[t],1}}]},
{Blue,Arrow[{{0,0,0},{x[t],y[t],z[t]}}]},
tangent[x[t],y[t],0]
},PlotRange->r,BoxRatios->1];
Show[p,g],
{t,0,4\[Pi]}
]
]

3D

share|improve this question
2  
This question, as a special case of finding unit tangent ... vectors, finds many (excellent) answers there. –  whuber Mar 27 '13 at 18:11

3 Answers 3

If all you need is a tangent to a circle, and not a tangent to an arbitrary curve, you can just rotate an arrow:

Manipulate[
 Graphics[{Circle[], Rotate[Arrow[{{1, 0}, {1, 1}}], \[CurlyPhi], {0, 0}]}],
 {\[CurlyPhi], 0, 2 Pi}
]

You may also be interested in the two-argument form of ArcTan[x,y] (look it up in the docs).

share|improve this answer
    
Thank you. Will checkout both suggestions. –  David McHarg Mar 27 '13 at 17:26

Without Rotate:

ctangent[x_, y_] := Arrow[{{x, y}, {x - y, x + y}}]
Manipulate[
 Graphics[{Circle[], {Blue, Line[{{0, 0}, {x[a], y[a]}}]}, {Red, 
    ctangent[x[a], y[a]]}}, 
    PlotRange -> {{-2, 2}, {-2, 2}}, 
    Axes -> True], {a, 0, 2 \[Pi]} 
]
share|improve this answer
    
Thanks. Never thought of that. Excellent. As i can use this solution in 3D as well. –  David McHarg Mar 27 '13 at 17:43
a = {{0, 0}, {1, 0}, {1, 1}}; 
Manipulate[
 Graphics[{Circle[], 
           Rotate[{Line@a[[;;2]], Arrow[a[[2;;]]]}, x, {0, 0}]}, 
           PlotRange -> {{-2, 2}, {-2, 2}}, Axes -> True], 
{x, 0, 2 Pi}]
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.