![在 tikz 上做曲线平滑](https://linux22.com/image/406627/%E5%9C%A8%20tikz%20%E4%B8%8A%E5%81%9A%E6%9B%B2%E7%BA%BF%E5%B9%B3%E6%BB%91.png)
我正在尝试制作这张图片:
但是我在做“圆圈”时遇到了问题,我尝试了不同的方法,我最好的尝试是:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\draw[black] plot[smooth,tension=.8]
coordinates{(0,0) (0,1) (1,1.8) (2,2) (5,2) (7,0) (6,-2) (4,-2.5) (2,-2.1) (1,-1.6) (0,0) };
\end{tikzpicture}
\end{figure}
\end{document}
但不如我需要的那么顺利。任何想法都会有帮助。
答案1
您可能希望使用更少的坐标,和smooth cycle
。
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=2pt}]
\draw[black] plot[smooth cycle,tension=.8]
coordinates{(0,1) (2,2.5) (5,2) (6.5,0) (5,-2.5) (1,-1.6)};
\draw[thick] (1,-0.5) node[bullet,label=left:$q$]{} to[out=40,in=175]
(4.8,0.5) node[bullet,label=right:$p$]{};
\end{tikzpicture}
\end{figure}
\end{document}
或者用箭头。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,arrows.meta,bending}
\tikzset{%
attach arrow/.style={
decoration={
markings,
mark=at position 0 with {\pgfextra{%
\pgfmathsetmacro{\tmpArrowTime}{\pgfkeysvalueof{/tikz/arc arrow/length}/(\pgfdecoratedpathlength)}%
\xdef\tmpArrowTime{\tmpArrowTime}}},
mark=at position {#1-3*\tmpArrowTime} with {\coordinate(@1);},
mark=at position {#1-2*\tmpArrowTime} with {\coordinate(@2);},
mark=at position {#1-1*\tmpArrowTime} with {\coordinate(@3);},
mark=at position {#1+\tmpArrowTime/2} with {\coordinate(@4);
\draw[-{Stealth[length=\pgfkeysvalueof{/tikz/arc arrow/length},bend]}] plot[smooth]
coordinates {(@1) (@2) (@3) (@4)};},
},
postaction=decorate,
},
attach arrow/.default=0.5,
arc arrow/.cd,length/.initial=2mm,
}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=2pt}]
\draw[black] plot[smooth cycle,tension=0.75]
coordinates{(0,1) (2,2.5) (5,2) (6.5,0) (5,-2.5) (1,-1.6)};
\draw[thick,attach arrow=0.4] (1,-0.5) node[bullet,label=left:$q$]{} to[out=40,in=175]
node[pos=0.4,above] {$f$} (4.8,0.5) node[bullet,label=right:$p$]{};
\end{tikzpicture}
\end{figure}
\end{document}