I would like to modify a bezier curve in tikz
, e.g.
\draw (0,0) .. controls +(87:2.3) and +(50:-0.7) .. (1,1);
in such a way, that a part in the middle is draw with dots (instead of a full solid line), while the start and the end remain solid. This problem I could solve in priciple with the following MWE (see below), but the parameters pre length=
and post length=
have to be defined in absolute coordinates. How can I change this in order to specify relative positions (e.g. from 0.3 to 0.8 of the path's length?
In particular, there is a \pgfdecoratedpathlength
variable (Length of curve in TikZ), but I don't know how to include this in my dotted part of curve
definition without getting errors. Or is there a different, even better approach?
MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,calc}
\begin{document}
\begin{tikzpicture}[scale=1] % <- except of line/dot width drawing should be independent of scaling
\tikzset{
dotted part of curve/.style args={between #1 and #2 with color #3}{
#3,
decorate,
decoration={
markings,
mark=between positions 0 and 1 step 3*\pgflinewidth with{\fill[radius=\pgflinewidth,#3] (0,0) circle;},
pre length=#1,
post length=#2,
pre=curveto,
post=curveto,
%post=moveto, % <-- alternate end: no drawing
}
},
dotted part of curve/.default={between 0.5cm and 0.3cm with color red},
% dotted part of curve/.default={between 0.3 and 0.8 with color red}, % <-- desired: relative positions
}
\draw (0,0) .. controls +(87:2.3) and +(50:-0.7) .. (1,1);
\draw[dotted part of curve] (0,0) .. controls +(87:2.3) and +(50:-0.7) .. (1,1);
\end{tikzpicture}
\end{document}
post=moveto,
instead ofpost=curveto,
such that there is no line drawn after the dotted part.