用 pgfplots 填充并绘制

用 pgfplots 填充并绘制

我创建了以下多边形:

\tikz
\draw[very thick,name path=A] (0,15) to [out=0,in=270] (15,30);
\draw[very thick, name path=B] (0,15) to [out=0,in=90] (15,0);
\draw[very thick,name path=C] (15,0) to [out=90,in=180] (30,15);
\draw[very thick,name path=D] (30,15) to [out=180,in=270] (15,30);

并且想在不修改多边形绘制方式的情况下填充它。有没有简单的方法可以做到这一点?

谢谢,

答案1

填充,然后绘制:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[scale=0.5]
\fill[green] 
  (0,15) to [out=0,in=90] 
  (15,0) to [out=90,in=180] 
  (30,15) to [out=180,in=270] 
  (15,30) to [out=270,in=0] 
  (0,15);
\draw[very thick,name path=A] (0,15) to [out=0,in=270] (15,30);
\draw[very thick, name path=B] (0,15) to [out=0,in=90] (15,0);
\draw[very thick,name path=C] (15,0) to [out=90,in=180] (30,15);
\draw[very thick,name path=D] (30,15) to [out=180,in=270] (15,30);
\end{tikzpicture}

\end{document}

在此处输入图片描述

如果路径名称不相关,您可以简化为:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[scale=0.5]
\filldraw[very thick,fill=green] 
  (0,15) to [out=0,in=90] (15,0)
  to [out=90,in=180] (30,15)
  to [out=180,in=270] (15,30) 
  to [out=270,in=0] (0,15);
\end{tikzpicture}

\end{document}

但你要求不要改变原始代码,因此这是我的第一个解决方案。

相关内容