我想画在平滑线和平滑线或其他。
\documentclass[dvipdfmx]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,3.5);
\coordinate (A) at (1,2);
\coordinate (B) at (2,3);
\coordinate (C) at (3,1.5);
\coordinate (D) at (4,2);
\draw[name path=AA,thick,red]plot[smooth,tension=0.7] coordinates {(O)(A)(B)(C)(D)};
\draw[name path=AB,thick,dashed](0,2.5)--(4,2.5);
\path[name intersections={of=AA and AB}];
\fill[gray](intersection-1)--plot[smooth,tension=0.7] coordinates {(O)(A)(B)(C)(D)}--(intersection-2);
\end{tikzpicture}
\end{document}
答案1
这是基本方法:在填充区域之前进行剪切。
该backgrounds
库及其键on background layer
用于将填充放置在已绘制的路径后面,这样我们就不必再次使用它们了。为了不必重复(并重新计算)弯曲路径,我使用save path
将路径保存在宏中。可以使用 来检索它use path
。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds, intersections}
\begin{document}
\begin{tikzpicture}[thick]
\coordinate (O) at (0, 3.5);
\coordinate (A) at (1, 2 );
\coordinate (B) at (2, 3 );
\coordinate (C) at (3, 1.5);
\coordinate (D) at (4, 2 );
\draw[red, name path=curve, save path=\curve]
plot[smooth, tension=0.7, samples at ={O, A, B, C, D}](\x);
\draw[dashed, name path=line] (0,2.5) -- (4, 2.5);
\begin{scope}[on background layer, name intersections={of=curve and line, sort by=line}]
\clip (intersection-1) rectangle (intersection-2 |- C); % C is lowest point
\fill[gray, use path=\curve];
\end{scope}
\end{tikzpicture}
\end{document}