# How can I draw a vector field on a curve?

For didactic purposes (a line integral of a vector field) I'd like to plot a vector field along a curve in 2D and 3D, like in this picture:

Mathematica is able to vizualize vector fields.

Here is my unsuccessful attempt

VectorPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},
RegionFunction -> Function[{x, y}, 1 <= x^2 + y^2 <= 1]]


I know this and this application to this end, but those are not it. An analog of the PlotPositionVector command of Maple is required.

• for 3D see this Q/A
– kglr
Mar 24 at 7:27
• @kglr: I need not TNB, but a field plot along a curve, not along a knot. Thank you anyway. Mar 24 at 7:32
• field[{x_, y_}] = {-1 - x^2 + y, 1 + x - y^2}; Show[VectorPlot[Evaluate[field[{x, y}]], {x, -4, 4}, {y, -4, 4}, VectorScaling -> True, VectorPoints -> Table[{Cos[t], Sin[t]}, {t, 0, 2 \[Pi], .1}]], Graphics[Circle[{0, 0}, {1, 1}]], AspectRatio -> Automatic] /. Arrow[{{x_, y_}, {z_, w_}}] :> Arrow[{{(x + z)/2, (y + w)/2}, {z, w}}] Mar 24 at 8:35
• field[{x_, y_}] = {-1 - x^2 + y, 1 + x - y^2}; Show[ VectorPlot[Evaluate[field[{x, y}]], {x, -4, 4}, {y, -4, 4}, VectorScaling -> True, VectorPoints -> Table[{Sin[u], Sin[2 u]}, {u, 0, 2 \[Pi], .1}]] /. Arrow[{{x_, y_}, {z_, w_}}] :> Arrow[{{(x + z)/2, (y + w)/2}, {z, w}}], ParametricPlot[{Sin[u], Sin[2 u]}, {u, 0, 2 Pi}], AspectRatio -> Automatic] Mar 24 at 8:39
• @cvgmt: Thank you. Can you present this as an answer, adding 3d case? TIA. Mar 24 at 9:06

vf[{x_, y_}] = {-1 - x^2 + y, 1 + x - y^2};

curve[t_] := Sqrt[t] {Cos[t], Sin[t]};


Using ParametricPlot:

scale = .2;

ParametricPlot[curve[t], {t, 0, 3 Pi}, PlotStyle -> Thick,
Epilog -> {Red, Thick,
Arrow[{curve @ #, curve @ # + (scale Norm[#] Normalize[#] & @ vf[curve@#])}] & /@
Rest[Subdivide[0, 3 Pi, 50]]}, PlotRange -> {-5, 5}]


Using VectorPlot:

VectorPlot[Evaluate @ vf[{x, y}], {x, -5, 5}, {y, -5, 5},
VectorSizes -> {0, .5}, VectorMarkers -> Placed["Arrow", "Start"],
VectorPoints -> (curve /@ Subdivide[0, 3 Pi, 60]),
Epilog -> {Red, First@ParametricPlot[curve[t], {t, 0, 3 Pi}]},
PlotRange -> {-5, 5}]


ParametricPlot3D:

vf3D[{x_, y_, z_}] = {-1 - x^2 + y, 1 + x - y^2, Sqrt[z] };
curve3D[t_] := Sqrt[t] {Cos[t], Sin[t], t/5};

Show[ParametricPlot3D[curve3D[t], {t, 0, 3 Pi}, PlotStyle -> Thick],
Graphics3D @ {Red, Thick,
Arrow[{curve3D @ #, curve3D @ # + (scale Norm[#] Normalize[#] &@
vf3D[curve3D@ #])}] & /@ Rest[Subdivide[0, 3 Pi, 50]]},
PlotRange -> All]


• +1. As usually, your answer is very well. However, I will be waiting some time for other answers. Mar 24 at 9:29

Edition

r[u_] = {Sin[u], Cos[u], u/10};
curve = ParametricPlot3D[{Sin[u], Cos[u], u/10}, {u, 0, 20}];
Show[VectorPlot3D[{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
VectorScaling -> True, VectorMarkers -> "Arrow",
VectorPoints -> Table[r[u], {u, 0, 20, .1}]] /.
Arrow[{p1_, p2_}] :> Arrow[{(p1 + p2)/2, p2}], curve]


Or use the approach Placed["Arrow", "Start"] by @kglr

r[u_] = {Sin[u], Cos[u], u/10};
curve = ParametricPlot3D[{Sin[u], Cos[u], u/10}, {u, 0, 20}];
Show[VectorPlot3D[{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
VectorScaling -> True, VectorMarkers -> Placed["Arrow", "Start"],
VectorPoints -> Table[r[u], {u, 0, 20, .1}]], curve]


r[u_] = {Sin[u], Cos[u], u/10};
curve = ParametricPlot3D[{Sin[u], Cos[u], u/10}, {u, 0, 20}];
vectorfield =
VectorPlot3D[{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2},
VectorScaling -> True,
VectorPoints -> Table[r[u], {u, 0, 20, .1}]] /.
Arrow[Tube[{p1_, p2_}, t_]] :> Arrow[Tube[{(p1 + p2)/2, p2}, t]];
Show[vectorfield, curve, PlotRange -> All, Boxed -> False]


• cvgmt (@ does not work.):+1. Arrows are not nice for me. Mar 24 at 9:32
• VectorMarkers -> Placed["Arrow", "Start"], VectorStyle -> Red, VectorColorFunction -> None Mar 24 at 11:08

A 2D example:

field[{x_, y_}] = {-y^2, x  y};
curve[t_] = {t, t^3} + 0.3;
Show[
ParametricPlot[curve[t], {t, -1 , 1}, PlotRange -> {{-1, 1}, {-1, 1}}],
Graphics[{Arrowheads[{{Automatic, 1}}], Table[Arrow[{curve[t], curve[t] + field[curve[t]]}], {t, -1, 1, .1}]}
]
]


And a 3D example:

field[{x_, y_, z_}] = 0.5 {-y^2, x  y, Sqrt[z y]};
curve[t_] = {t, t^3, Sqrt[t]};
Show[
ParametricPlot3D[curve[t], {t, 0 , 1},  PlotRange -> {{0, 1}, {0, 1.5}, {0, 2}}],