# Tangent to a circle

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


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


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}}], φ, {0, 0}]}],
{φ, 0, 2 Pi}
]


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

• Thank you. Will checkout both suggestions. Mar 27, 2013 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 π}
]

• Thanks. Never thought of that. Excellent. As i can use this solution in 3D as well. Mar 27, 2013 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}]