![使用 TikZ 绘制特定曲线](https://linux22.com/image/463276/%E4%BD%BF%E7%94%A8%20TikZ%20%E7%BB%98%E5%88%B6%E7%89%B9%E5%AE%9A%E6%9B%B2%E7%BA%BF.png)
我写了这段代码:
\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}