I have two almost parallel hobby
paths (red and blue curves) and want to fill a percent of the path between these two lines, starting from the bottom left.
I think this may require a center path from which to compute ther percent of the path and have drawn that dotted
and included markings
at the 30%, 60% and 100% points.
What is the recommened way to fill this path?
Hack:
One way to hack this is to mark more points along the center path with circle, but the result is not that good and will be problamatic when the width of the curve grows. So using
\draw [gray, thin, dotted, Fill Points on Path={0.02}{0.2}{0.01}]
(C-1)
to [curve through={(C-2) (C-3) (C-4)}]
(C-5);
yields:
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}
\usetikzlibrary{decorations.markings}
\tikzset{Label Points on Path/.style n args={3}{
decoration={
markings,
mark=
between positions #1 and #2 step #3
with
{
\draw [fill=blue] (0,0) circle (2pt);
}
},
postaction=decorate,
}}
\tikzset{Fill Points on Path/.style n args={3}{%% <-- Needed for hack solution
decoration={
markings,
mark=
between positions #1 and #2 step #3
with
{
\draw [fill=cyan] (0,0) circle (7pt);% large circle
}
},
postaction=decorate,
}}
\begin{document}
\begin{tikzpicture}
\coordinate (A-1) at (0, 0); \coordinate (B-1) at (0.5, 0);
\coordinate (A-2) at (1, 1); \coordinate (B-2) at (1, 0.5);
\coordinate (A-3) at (3, 1); \coordinate (B-3) at (3, 0.5);
\coordinate (A-4) at (4, 3); \coordinate (B-4) at (4, 2.5);
\coordinate (A-5) at (7, 3); \coordinate (B-5) at (A-5);
\coordinate (C-1) at (0.25, 0);
\coordinate (C-2) at (1, 0.75);
\coordinate (C-3) at (3, 0.75);
\coordinate (C-4) at (4, 2.75);
\coordinate (C-5) at (A-5);
\draw [black, fill=yellow!15]
(A-5)
to[out=-90, in=0, distance=5.0cm]
(A-1)
to [curve through={(A-2) (A-3) (A-4)}]
(A-5);
\draw [ultra thick, red]
(A-1)
to [curve through={(A-2) (A-3) (A-4)}]
(A-5);
\draw [thin, blue] (B-1)
to [curve through={(B-2) (B-3) (B-4)}]
(B-5);
\draw [gray, thick, dotted, Label Points on Path={0.2}{1}{0.4}]
(C-1)
to [curve through={(C-2) (C-3) (C-4)}]
(C-5);
%% Hack solution
%\draw [gray, thin, dotted, Fill Points on Path={0.02}{0.2}{0.01}]
% (C-1)
% to [curve through={(C-2) (C-3) (C-4)}]
% (C-5);
\end{tikzpicture}
\end{document}
Symbol 1's Solution (Packaged Version):
This is an attempt to package Symbol 1's solution.
It seems to have issue filling in the initial portion and the end potions of the curve. The image is after drawing over the curve following the fill.
Also, I would prefer the end of the fill to be a circular-ish bulge (end of a circle as I showed in the blue fill example). If it adds much complexity to the solution, I can live without this, and atetmpt to remedy that by placing a circle of an appropriate size near the end of the fill.
Besides the glitches, I can't seem to fill beyond the 93% point (which is what is shown in the image). Similarly, below 5% has issues.
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}
\usetikzlibrary{decorations}
\def\PercentOfPath{93}
\pgfmathsetmacro\PotionOfFill{1.0 - \PercentOfPath/100}
\pgfdeclaredecoration{CurveToDesiredPoint}{initial}{%
\state{initial}[
width=\pgfdecoratedinputsegmentlength/5,
% replace 5 by larger number to improve resolution
switch if less than=\PotionOfFill*\pgfdecoratedpathlength to final
]{
\pgfpathlineto{\pgfpointorigin}
}%
\state{final}{}%
}
\newcommand\DrawPath[1][]{%
\draw [red, thick, #1] (A-1) to [curve through={(A-2) (A-3) (A-4)}] (A-5);
\draw [blue, thick, #1] (B-1) to [curve through={(B-2) (B-3) (B-4)}] (B-5);
}
\begin{document}
\begin{tikzpicture}
\coordinate (A-1) at (0, 0); \coordinate (B-1) at (0.5, 0);
\coordinate (A-2) at (1, 1); \coordinate (B-2) at (1, 0.5);
\coordinate (A-3) at (3, 1); \coordinate (B-3) at (3, 0.5);
\coordinate (A-4) at (4, 3); \coordinate (B-4) at (4, 2.5);
\coordinate (A-5) at (7, 3); \coordinate (B-5) at (A-5);
\coordinate (C-1) at (0.25, 0);
\coordinate (C-2) at (1, 0.75);
\coordinate (C-3) at (3, 0.75);
\coordinate (C-4) at (4, 2.75);
\coordinate (C-5) at (A-5);
\DrawPath
\tikzset{decoration={CurveToDesiredPoint}}
\DrawPath[decorate, draw=none]
\path [red, decorate, save path=\redpanda]
(A-1) to [curve through={(A-2) (A-3) (A-4)}] (A-5);
\path[use path=\redpanda, red];
\path[use path=\redpanda, red!80, transform canvas={yshift=-5}];
\path[use path=\redpanda, red!60, transform canvas={yshift=-10}];
\path[use path=\redpanda, red!40, transform canvas={yshift=-15}];
\path[use path=\redpanda, red!20, transform canvas={yshift=-20}];
\tikzset{decoration={CurveToDesiredPoint} }
\path [blue, decorate, save path=\bluewhale]
(B-1) to [curve through={(B-2) (B-3) (B-4)}] (B-5);
\makeatletter{
\def\orangeshark{}
\def\pgfsyssoftpath@undeadtoken{\noexpand\pgfsyssoftpath@undeadtoken} % expand is futile
\def\pgfsyssoftpath@linetotoken#1#2{
\xdef\orangeshark{
\pgfsyssoftpath@undeadtoken{#1}{#2}
\orangeshark
}
}
\let\pgfsyssoftpath@movetotoken=\pgfsyssoftpath@linetotoken
\bluewhale
{\advance\rightskip0ptplus1fil\ttfamily\meaning\orangeshark\par}
}
\def\pgfsyssoftpath@undeadtoken{\pgfsyssoftpath@linetotoken}
\def\zoo{\redpanda\orangeshark}
\fill[yellow]\pgfextra{\pgfsetpath\zoo};
\path \pgfextra{\pgfsetpath\redpanda};
\path \pgfextra{\pgfsetpath\bluewhale};
\DrawPath% To cover up any glitches
\end{tikzpicture}%
\end{document}