使用 TikZ 绘制特定曲线

使用 TikZ 绘制特定曲线

我尝试画出这个图: 在此处输入图片描述

我写了这段代码:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usepackage{siunitx}
\usetikzlibrary{quotes}
\usetikzlibrary{angles}
\usetikzlibrary{arrows}
\usetikzlibrary{automata}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}

\usepackage{amsmath,amsfonts,amssymb}


\begin{document}

\begin{tikzpicture}[line cap=round]

  % First, define nodes
\node[inner sep=0pt] (O1) at (0, 0) {};
\node[inner sep=0pt] (O2) at (0, 5) {};
\node[inner sep=0pt] (O3) at (5, 5) {};
\node[inner sep=0pt] (O4) at (5, 0) {};
\node[inner sep=0pt, label=$\boldsymbol{2}$] (A) at (1, 4) {};
\node[inner sep=0pt, label=$\boldsymbol{4}$] (A) at (2, 4) {};
\node[inner sep=0pt, label=$\boldsymbol{11}$] (A) at (3, 4) {};
\node[inner sep=0pt, label=$\boldsymbol{9}$] (A) at (4, 4) {};
\node[inner sep=0pt, label=$\boldsymbol{6}$] (A) at (1, 2.5) {};
\node[inner sep=0pt, label=$\boldsymbol{7}$] (A) at (2.5, 2.5) {};
\node[inner sep=0pt, label=$\boldsymbol{-1}$] (A) at (4, 2.5) {};
\node[inner sep=0pt, label=$\boldsymbol{-10}$] (A) at (1, 1) {};
\node[inner sep=0pt, label=$\boldsymbol{22}$] (A) at (2.5, 1) {};
\node[inner sep=0pt, label=$\boldsymbol{14}$] (A) at (4, 1) {};

\draw [line width=2pt, -] (O1) -- (O2);
\draw [line width=2pt, -] (O2) -- (O3);
\draw [line width=2pt, -] (O3) -- (O4);
\draw [line width=2pt, -] (O4) -- (O1);


%south east
%north west

\end{tikzpicture}

\end{document}

但我不知道如何在其中绘制曲线。

答案1

类似的东西?您可以添加更多坐标以使曲线更精确,并且可以根据需要更改坐标以获得所需的最佳曲线形状。您还可以使用该选项tension使曲线更“松散”或更“拉伸”。

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usepackage{siunitx}
\usetikzlibrary{quotes}
\usetikzlibrary{angles}
\usetikzlibrary{arrows}
\usetikzlibrary{automata}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}

\usepackage{amsmath,amsfonts,amssymb}


\begin{document}
    
    \begin{tikzpicture}[line cap=round]
        
        % First, define nodes
        \node[inner sep=0pt] (O1) at (0, 0) {};
        \node[inner sep=0pt] (O2) at (0, 5) {};
        \node[inner sep=0pt] (O3) at (5, 5) {};
        \node[inner sep=0pt] (O4) at (5, 0) {};
        \node[inner sep=0pt, label=$\boldsymbol{2}$] (A) at (1, 4) {};
        \node[inner sep=0pt, label=$\boldsymbol{4}$] (A) at (2, 4) {};
        \node[inner sep=0pt, label=$\boldsymbol{11}$] (A) at (3, 4) {};
        \node[inner sep=0pt, label=$\boldsymbol{9}$] (A) at (4, 4) {};
        \node[inner sep=0pt, label=$\boldsymbol{6}$] (A) at (1, 2.5) {};
        \node[inner sep=0pt, label=$\boldsymbol{7}$] (A) at (2.5, 2.5) {};
        \node[inner sep=0pt, label=$\boldsymbol{-1}$] (A) at (4, 2.5) {};
        \node[inner sep=0pt, label=$\boldsymbol{-10}$] (A) at (1, 1) {};
        \node[inner sep=0pt, label=$\boldsymbol{22}$] (A) at (2.5, 1) {};
        \node[inner sep=0pt, label=$\boldsymbol{14}$] (A) at (4, 1) {};
        
        \draw [line width=2pt, -] (O1) -- (O2);
        \draw [line width=2pt, -] (O2) -- (O3);
        \draw [line width=2pt, -] (O3) -- (O4);
        \draw [line width=2pt, -] (O4) -- (O1);
        
        
        %south east
        %north west
        
        \draw plot [smooth] coordinates {(2.5,0.8) (0.8,2.2) (0.9,3) (1.8,4.6) (3.3,4.4) (3.5,3.7) (3,1) (2.5,0.8)}; % <<<<<< 
        % this is the curve you can change it as you like by changing the coordinates.
        
    \end{tikzpicture}

在此处输入图片描述

相关内容