为抛物线图创建填充图案

为抛物线图创建填充图案

对于下面 MWE 中显示的抛物线图。我需要用指向黑线的箭头替换填充图案(用蓝线表示)。

\documentclass{article}
\usepackage{amsmath} 
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,24);
\draw[thick,color=black] (0,12) -- (12,12);
\begin{scope}[shift={(0,12)}]
\draw[pattern=vertical lines,pattern color=blue, domain=0:12] plot (\x, {(0.075*2)*(4*\x/12)*(12-\x)});
\draw[thick,color=red, domain=0:12] plot (\x, {(0.075*2)*(4*\x/12)*(12-\x)});
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}

编译输出

其他包提供与我上面提到的类似的阴影图案,但它们处理的是线性图而不是抛物线图,我从这些包中提取了宏并将其放在下面:

1- stanli 包:


    %------------------------------------------------
%       lineload
%------------------------------------------------
%           \lineload{type}{initial point}{end point}[initial force value][end force value][force interval]
%               [initial force value][end force value][force interval] are optional
%
%           and accordingly for type 3      
%
%           \lineload{type}{initial point}{end point}[initial force value][end force value][lineload distance from inital point][force interval]
%               [initial force value][end force value][lineload distance from inital point][force interval] are optional
%
%           and accordingly for type 4      
%
%           \lineload{type}{initial point}{end point}[force interval][force length]
%               [force interval][force length] are optional

\newcommandx{\lineload}[7][4=1,5=1,6=\lineloadInterval,7=\lineloadInterval]{
    \ifthenelse{\equal{#1}{1}}{     %
        \coordinate (lineloadVarA1) at ($ (#2)!\lineloadDistance!90:(#3) $);
        \coordinate (lineloadVarB1) at ($ (#3)!\lineloadDistance!-90:(#2) $);
        \coordinate (lineloadVarA2) at ($ (#2)!{\lineloadDistance +#4cm}!90:(#3) $);
        \coordinate (lineloadVarB2) at ($ (#3)!{\lineloadDistance+#5cm}!-90:(#2) $);
        \ifthenelse{\equal{#4}{0}}{}
        {
            \draw [force,->] (lineloadVarA2) -- (lineloadVarA1);
        }
        \ifthenelse{\equal{#5}{0}}{}
        {
            \draw [force,->] (lineloadVarB2) -- (lineloadVarB1);
        }
        \draw [smallLine] (lineloadVarA1) -- (lineloadVarB1) node(xline)[right] {};
        \draw [normalLine] (lineloadVarA2) -- (lineloadVarB2);
        \fill (lineloadVarA2) circle (\normalLineWidth/2);
        \fill (lineloadVarB2) circle (\normalLineWidth/2);
            \pgfmathsetmacro{\lineloadIntervalBegin}{#6/\scalingParameter}
            \pgfmathsetmacro{\lineloadIntervalStep}{#6/\scalingParameter*2}
            \pgfmathsetmacro{\lineloadIntervalEnd}{1-#6/\scalingParameter}
        \foreach \i in {\lineloadIntervalBegin,\lineloadIntervalStep,...,\lineloadIntervalEnd}
        \draw [force,->] ($(lineloadVarA2)!\i!(lineloadVarB2)$)-- ($(lineloadVarA1)!\i!(lineloadVarB1)$);
    }{}
    
    \ifthenelse{\equal{#1}{2}}{     %
        \coordinate (lineloadVarA1) at ($ (#2)+1*(0,\lineloadDistance) $);
        \coordinate (lineloadVarB1) at ($ (#3)+1*(0,\lineloadDistance) $);
        \coordinate (lineloadVarA2) at ($ (#2)+1*(0,\lineloadDistance+#4cm) $);
        \coordinate (lineloadVarB2) at ($ (#3)+1*(0,\lineloadDistance+#5cm) $);
        \ifthenelse{\equal{#4}{0}}{}
        {
            \draw [force,->] (lineloadVarA2) -- (lineloadVarA1);
        }
        \ifthenelse{\equal{#5}{0}}{}
        {
            \draw [force,->] (lineloadVarB2) -- (lineloadVarB1);
        }
        \draw [smallLine] (lineloadVarA1) -- (lineloadVarB1) node(xline)[right] {};
        \draw [normalLine] (lineloadVarA2) -- (lineloadVarB2);
        \fill (lineloadVarA2) circle (\normalLineWidth/2);
        \fill (lineloadVarB2) circle (\normalLineWidth/2);
            \pgfmathsetmacro{\lineloadIntervalBegin}{#6}
            \pgfmathsetmacro{\lineloadIntervalStep}{#6*2}
            \pgfmathsetmacro{\lineloadIntervalEnd}{1-#6}
        \foreach \i in {\lineloadIntervalBegin,\lineloadIntervalStep,...,\lineloadIntervalEnd}
        \draw [force,->] ($(lineloadVarA2)!\i!(lineloadVarB2)$)-- ($(lineloadVarA1)!\i!(lineloadVarB1)$);
    }{}

    \ifthenelse{\equal{#1}{3}}{     %
        \ifthenelse{\equal{#6}{\lineloadInterval}}
            {\renewcommand{\helpVarA}{0cm}}
            {\renewcommand{\helpVarA}{#6cm}}
        \path
            let
                \p1 = (#2),
                \p2 = (#3)
            in
                coordinate (lineloadVarA1) at ($(\p1)+1*(0,\lineloadDistance+\helpVarA)$)
                coordinate (lineloadVarB1) at ($(\x2,\y1)+1*(0,\lineloadDistance+\helpVarA)$)
                coordinate (lineloadVarA2) at ($ (\p1)+1*(0,\lineloadDistance+\helpVarA+#4cm)$)
                coordinate (lineloadVarB2) at ($ (\x2,\y1)+1*(0,\lineloadDistance+\helpVarA+#5cm)$);
        \draw [tinyLine,loosely dotted] (lineloadVarA1)--($(#2)+1*(0,\hingeRadius)$);
        \draw [tinyLine,loosely dotted] (lineloadVarB1)--($(#3)+1*(0,\hingeRadius)$);
        \ifthenelse{\equal{#4}{0}}{}
        {
            \draw [force,->] (lineloadVarA2) -- (lineloadVarA1);
        }
        \ifthenelse{\equal{#5}{0}}{}
        {
            \draw [force,->] (lineloadVarB2) -- (lineloadVarB1);
        }
        \draw [smallLine] (lineloadVarA1) -- (lineloadVarB1) node(xline)[right] {};
        \draw [normalLine] (lineloadVarA2) -- (lineloadVarB2);
        \fill (lineloadVarA2) circle (\normalLineWidth/2);
        \fill (lineloadVarB2) circle (\normalLineWidth/2);
            \pgfmathsetmacro{\lineloadIntervalBegin}{#7}
            \pgfmathsetmacro{\lineloadIntervalStep}{#7*2}
            \pgfmathsetmacro{\lineloadIntervalEnd}{1-#7}
        \foreach \i in {\lineloadIntervalBegin,\lineloadIntervalStep,...,\lineloadIntervalEnd}
        \draw [force,->] ($(lineloadVarA2)!\i!(lineloadVarB2)$)-- ($(lineloadVarA1)!\i!(lineloadVarB1)$);
    }{}
    
    \ifthenelse{\equal{#1}{4}}{     %
        \coordinate (lineloadVarA1) at ($ (#2)+1*(0,\lineloadDistance) $);
        \coordinate (lineloadVarB1) at ($ (#3)+1*(0,\lineloadDistance) $);
        \ifthenelse{\equal{#4}{1}}
            {\pgfmathsetmacro{\lineloadIntervalStep}{\lineloadInterval}
            \pgfmathsetmacro{\lineloadIntervalEnd}{1-\lineloadInterval/2}}  
            {\pgfmathsetmacro{\lineloadIntervalStep}{#4}
            \pgfmathsetmacro{\lineloadIntervalEnd}{1-#4/2}}
        \ifthenelse{\equal{#5}{1}}
            {\pgfmathsetmacro{\lineloadForceLength}{\lineloadForce}}    
            {\pgfmathsetmacro{\lineloadForceLength}{#5}}
        \foreach \i in {0,\lineloadIntervalStep,...,\lineloadIntervalEnd}
        \draw [force,->] ($(lineloadVarA1)!\i!(lineloadVarB1)$) -- ($(lineloadVarA1)!\i+\lineloadForceLength!(lineloadVarB1)$);
    }{}

}

2- structmech 包

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     Command 4: UDL
% \UDL[1]{2}{3}[4]{5}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\NewDocumentCommand{\UDL}{O{N} m m O{} G{1}}{
\IfEq{#1}{F}{\def\FAC{-1}}{\def\FAC{1}}
\coordinate(A)at(#2);
\coordinate(B)at(#3);
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{B}{center}}
\let\Angle\pgfmathresult
\pgfpointdiff{\pgfpointanchor{A}{center}}{\pgfpointanchor{B}{center}}
\pgfmathparse{veclen(\pgf@x,\pgf@y)/28.45274}
\let\Length\pgfmathresult
\draw[\fillColor,fill=\fillColor,fill opacity=\fillOpacity](#2)--(#3)--($(#3)+(\Angle+\FAC*90:#5)$)--($(#2)+(\Angle+\FAC*90:#5)$)--cycle;
\IfNoValueTF{#4}
    {}
    {\IfStrEq{\convention}{sign}
        {\node[NOFILL]at($(#2)!.5!(#3)+(\Angle+\FAC*90:1.2*#5)$)[rotate=\Angle]{$#4$};}
        {\StrLeft{#4}{1}[\SS]\IfStrEq{\SS}{-}
            {\node[NOFILL]at($(#2)!.5!(#3)+(\Angle+\FAC*90:1.2*#5)$)[rotate=\Angle]{$\StrDel[1]{#4}{-}$};}
            {\node[NOFILL]at($(#2)!.5!(#3)+(\Angle+\FAC*90:1.2*#5)$)[rotate=\Angle]{$#4$};}
        }
    }
\foreach\x in{0,.1,.2,...,1}{
\coordinate(C)at($(#2)!\x!(#3)$);
\IfNoValueTF{#4}
    {\draw[<-](C)--++($(\Angle+\FAC*90:#5)$);}
    {\IfStrEq{\convention}{sign}
        {\draw[<-](C)--++($(\Angle+\FAC*90:#5)$);}
        {\StrLeft{#4}{1}[\SS]\IfStrEq{\SS}{-}
            {\draw[->](C)--++($(\Angle+\FAC*90:#5)$);}
            {\draw[<-](C)--++($(\Angle+\FAC*90:#5)$);}
        }
    }
};
}
\makeatother

3-至于 pst stru 包/库,我认为在这种情况下不推荐

答案1

我认为如果不操作 PGF 代码,您就无法获得箭头模式。为什么不自己画箭头呢? - 像这样:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,24);
\draw[thick,color=black] (0,12) -- (12,12);
\begin{scope}[shift={(0,12)}]
\foreach \x in {0.2 ,0.4 , ...,11.8}
   \draw[thick, blue, ->] (\x, {(0.075*2)*(4*\x/12)*(12-\x)}) -- (\x,0);
\draw[thick,color=red, domain=0:12] plot (\x, {(0.075*2)*(4*\x/12)*(12-\x)});
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}

带有箭头的图案

答案2

如果使用path picture,则无需了解边界的参数化。线之间的距离存储在 中,在下面的代码中vline pars/d设置为,箭头样式只是此处添加的样式的参数。3mmvlines

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\tikzset{vlines/.style={path picture={
\path let \p1=($(path picture bounding box.east)-(path picture bounding box.west)$),
\p2=(path picture bounding box.north east),
\n1={int(scalar(\x1/\pgfkeysvalueof{/tikz/vline pars/d}))},
\n2={0.5*(\x1-\n1*\pgfkeysvalueof{/tikz/vline pars/d})} in
foreach \xyz in {0,...,\n1} {
([xshift=\n2+\xyz*\x1/\n1]path picture bounding box.north west) edge[#1]
([xshift=\n2+\xyz*\x1/\n1]path picture bounding box.south west)
}
;
}},vline pars/.cd,d/.initial=3mm}
\begin{document}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,24);
\draw[thick,color=black] (0,12) -- (12,12);
\begin{scope}[shift={(0,12)}]
\draw[domain=0:12] 
plot (\x, {(0.075*2)*(4*\x/12)*(12-\x)});
\draw[vlines={blue,-latex},thick,color=red, domain=0:12] plot (\x, {(0.075*2)*(4*\x/12)*(12-\x)});
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容