我有两条线;一条是“弯曲”的线,另一条是顶点(参见下面的MWE):
我该如何填充这两条线所围成的区域?即红线和黑线之间的区域?
平均能量损失
\documentclass[tikz]{standalone}
\usepackage{pgf,pgfplots,pgfplotstable,amsmath,amssymb}
\begin{document}
\begin{tikzpicture}
\draw [ultra thick,red] (-19.5,-16) to[out=55,in=228] (-14,-9) to [out=45,in=180] (0,-2) to[out=0,in=135] (14, -9) to[out=318,in=125] (20,-16);
\fill (-14,-9) circle (0.15cm);
\fill (14,-9) circle (0.15cm);
\draw (-14,-9) -- (0,-15) -- (14,-9);
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[green] (-14,-9) to [out=45,in=180] (0,-2) to[out=0,in=135] (14, -9) -- (0,-15) -- cycle;
\draw [ultra thick,red] (-19.5,-16) to[out=55,in=228] (-14,-9) to [out=45,in=180] (0,-2) to[out=0,in=135] (14, -9) to[out=318,in=125] (20,-16);
\fill (-14,-9) circle (0.15cm);
\fill (14,-9) circle (0.15cm);
\draw (-14,-9) -- (0,-15) -- (14,-9);
\end{tikzpicture}
\end{document}
编辑只是为了显示\fillbetween
- 这不是一个好的解决方案。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections, pgfplots.fillbetween}
\begin{document}
\begin{tikzpicture}
\draw [ultra thick, red, name path=A] (-19.5,-16) to[out=55, in=228] (-14,-9) to [out=45, in=180] (0,-2) to[out=0, in=135] (14, -9) to[out=318, in=125] (20,-16);
\fill (-14,-9) circle (0.15cm);
\fill (14,-9) circle (0.15cm);
\draw[name path=B] (-14,-9) -- (0,-15) -- (14,-9);
\tikzfillbetween[of=A and B, split, every segment no 0/.style={fill=none}, every segment no 1/.style={green}, every segment no 2/.style={fill=none}] {};
\end{tikzpicture}
\end{document}
此填充是在路径\draw
n 之后完成的,从而覆盖了部分线条。-这可以解决。