I'd like to draw a piece of "ground line" (picture below), but I don't know, how to make a line style and how to ensure proper localizations of the picture boundary. The solution of achieving an expected line style I found in the following discussion: laser beam drawing - the line having a gradient of colours which is perpendicular in each point to the line axis.
Is there any way of creating a customized line style, that will be executed by the command like \ground (0,0) -- (0.5,1) -- (1,0.25);
or by option (for instance with the name ground
) in the optional argument of \draw
command?
According to @Loop Space answer (tikz: double lines are shifted) the bounding box covers all paths and is extra enlarged with the half of the line width. So by default any line might be placed within the bounding box while line join=round
option is chosen (I prefer miter
style). How to find the line boundaries to avoid unwanted cutting of the line?
In MWE below I applied an extension of lines with the use of point symmetry to solve the problem of vertical line endings (the best other solution given by @Loop Space in vertical line endings leads to not smooth line boundaries - as he demonstrated it).
MWE:
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\newcommand\groundthick{12} % ground thickness
\newcommand\linesamount{30} % number of coaxial gray lines having various hue
\newcommand\groundpath[1]{
\begin{scope}
% start and end point
\path #1 coordinate (rend) -- cycle
-- (current subpath start) coordinate (lend);
\begin{scope}
\clip #1 |- (current bounding box.south) -| cycle;
\foreach \lineno [evaluate=\lineno as \shader using \lineno*100/\linesamount] in {0,...,\linesamount}{
\def\thicker{\groundthick*2-\lineno*\groundthick*2/\linesamount}
% ground line member
\draw [line width=\thicker,color=gray!\shader,
line join=miter] #1;
% left ground line extension
\draw [line width=\thicker,color=gray!\shader,
line join=miter,scale around={-1:(lend)}] #1;
% right ground line extension
\draw [line width=\thicker,color=gray!\shader,
line join=miter,scale around={-1:(rend)}] #1;
}
\end{scope}
\draw #1; % pavement
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\groundpath{
(0,0) -- +(0.5,0.15) -- +(1.0,0.65) -- +(1.5,-0.12)
-- +(2.0,0.56) -- +(2.5,0.58) -- +(3.0,0.65) -- +(3.5,0.6)
-- +(4.0,0.98) -- +(4.5,0.55) -- +(5.0,0.95)
}
\end{tikzpicture}
\end{document}
EDIT:
After @cfr comment and answer I decided to try correct my question. The problem is connected with automatic finding of coordinates of the most external parts of lines. What I am doing in the code is depicted below:
After adding only the line in which the line is drawing with opacity=0
, as proposed by @cfr below, the problem follows from the addition of unwanted margins, as well as from the removing of one line tip (generally of more tips):
And I also would like to ask, if the line:
\groundpath{(A) -- (B) -- (C)}
could be replaced by something like that:
\groundpath (A) -- (B) -- (C);
or like that:
\draw [groundpath] (A) -- (B) -- (C);
too narrow picture boundaries
which is rather a different thing.... – cfr Nov 1 '15 at 19:42