Drawing a short directional arrow, lying parallel to a straight line A-B, is pretty trivial to accomplish using Tikz;
\documentclass{article}
\usepackage{tikz} \usetikzlibrary{calc} \tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$A$}}] (A) {};
\draw (1,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$B$}}] (B) {};
\draw (A) to (B);
\draw ($(A)!0.15!(B) + (0,0.02)$) node (a) {};
\draw ($(A)!0.35!(B) + (0,0.02)$) node (b) {};
\draw[->>] (a) to (b);
\end{tikzpicture}
\end{document}
However, drawing a short curved directional arrow, lying parallel to a curved line C-D, seems to be far more complicated, since the directional arrow's curvature and end points need to be shifted relative to the shape of the curved line;
\documentclass{article}
\usepackage{tikz} \usetikzlibrary{calc} \tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$C$}}] (C) {};
\draw (1,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$D$}}] (D) {};
\draw (C) to [bend left=45] (D);
\draw ($(C)!0.15!(D) + (0,0.02)$) node (c) {};
\draw ($(C)!0.35!(D) + (0,0.02)$) node (d) {};
\draw[->>] (c) to [bend left=45] (d);
\end{tikzpicture}
\end{document}
I realise that the problem lies with the fact that the short directional arrow's endpoints are defined differently to those of the curved line C-D, and thus, using the [bend left=45]
angle option within both curved arrow/line definitions plots the incorrect tikzpicture
above.
The answered question 2 arrows at same distance successfully tackles the problem for lines/directional arrows of equal length, but I ran into difficulties when trying to modify its answer for plotting short arrows lying alongside long lines; my main problem was defining and positioning two "extra" thick white lines with which to cover/shorten the directional arrow. Has anyone managed to modify the above answer to answer my question?
I also guessed that [bend left=45]
curves were mathematically defined in Tikz using a parabola equation, which then allowed me to produce the desired curved directional arrow/curved line E-F plot below;
\documentclass{article}
\usepackage{tikz} \usetikzlibrary{calc} \tikzset{>=latex}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$E$}}] (E) {};
\draw (1,0) node[circle, inner sep=0.8pt, fill=black, label={below:{$F$}}] (F) {};
\draw[domain=0:1, samples=100, black] plot ({\x},{\x*(1-\x)*tan(45)});
\draw[domain=0.15:0.35, samples=100, black, ->>] plot ({\x},{\x*(1-\x)*tan(45) + 0.02});
\end{tikzpicture}
\end{document}
However, after further investigation, it seems the [bend left=45]
curve shown in red below seems to suggests my guess wasn't completely correct, and [bend left=45]
is not given by a parabola equation. Does anyone know what the underlying bend
curve equation is? Is it possible to redefine the equation used to plot these curved lines? Or am I missing an easy way of plotting parallel curved lines?
Best Answer
The curve drawn by a
to[bend left]
is probably a bezier curve, and thus is not an arc nor a parabola. Unfortunately this syntas hides the control points used.Even if the control points were known, they won't be useful for your problem, since basically you want to get another bezier curve parallel to a "segment" or portion of another given bezier curve. I have no idea of the equations that should be solved to find those control points.
But not all hope is lost. I had a crazy idea. Once a bezier path is computed by tikz, any of its intermediate points are available via
[pos]
key, so it is possible to find a number of those points, between the desired start and end point, and connect all of them via straight lines. If the points are close enough, the straight segments will not be visible and they will look like a curve.So this is the proof of concept:
This is the result:
Update
A little refinement can be done in above code. Instead of specifying the
foreach
loop as from0.15
to0.55
in steps of0.1
, it looks more natural to simply specify the desired number of inner points (i.e: the "resolution" of the parallel curve), and let to some other expression to compute thepos
for each of those points. This is done like this:So, in this example, 40 intermediate points are computed, and the formula for the
pos
key specifies 0.15 and 0.55 as the extremes of the parallel curve.However, this approach does not use a "true" parallel line. The curve used to compute the points is simply the same orginal curve, only shifted in the Y axis. This could work for smooth arcs which are mostly horizontal, but it will fail for parts of the curve where the tangent is not so horizontal. Consider for example:
This produces:
It can be seen that the distance between the red and blue lines is not constant. How can this be solved?
The following idea works: instead of shifting the curve, compute the sequence of points
(p1)
,(p2)
etc. on the original curve. But then, when drawing the parallel line, do not use those points, but points which are at a fixed distance (eg: 0.2cm) from each of these points in the direction perpendicular to the curve. This direction can be computed as the vector from current point(p_i)
to next point(p_j)
, rotated 90 degrees.Fortunately, tikz has the interpolated coordinates expression which allows for this with a simple formula:
($(p\i)!0.2cm!90:(p\j)$)
.So, using this idea:
And this gives a perfect result!