在 Tikz 中制作连接两点的特定虚线抛物线曲线

在 Tikz 中制作连接两点的特定虚线抛物线曲线

我有这个图形的 tex 代码,即正方形 1-2-3-4,其中有一条虚线通过中间点 p23 连接 p2 和 p3。

我们如何才能制作一条(弯曲的)虚线抛物线(或者任何更平滑的曲线)连接 p2、p23 和 p3?谢谢,请简短回答。

在此处输入图片描述

\begin{tikzpicture}[scale=1,baseline]

\coordinate (p1) at (0,0);

\coordinate (p2) at (0,1);

\coordinate (p3) at (1,0);

\coordinate (p4) at (1,1);

\coordinate (p23) at (.7,.7);

\draw [-,>=latex,line width=0.5pt] (p2) -- (p1);

\draw [-,>=latex,line width=0.5pt] (p4) -- (p3);

\draw [-,>=latex,line width=0.5pt] (p3) -- (p1);

\draw [-,>=latex,line width=0.5pt] (p4) -- (p2);

\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p2);

\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p3);

\node at (-0.15,-0.15) {1};

\node at (-0.15,1.15) {3};

\node at (1.15,-0.15) {2};

\node at (1.15,1.15) {4};

\end{tikzpicture}
}

答案1

这里有三个选项。

\draw [densely dashed, line width=0.5pt] (p2) edge[bend left=40,looseness=1.5] (p3);
\draw [red,densely dashed, line width=0.5pt] (p2) edge[bend left=40,distance=1cm] (p3);
\draw [blue,densely dashed, line width=0.5pt] (p2) edge[controls=+(0:1) and +(90:1)] (p3);

调整参数以满足您的需求。有关更多详细信息,请阅读pgfmanual第 70.3 节第 753 页及以后的内容。

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1,baseline]

\coordinate (p1) at (0,0);

\coordinate (p2) at (0,1);

\coordinate (p3) at (1,0);

\coordinate (p4) at (1,1);

\coordinate (p23) at (.7,.7);

\draw [-,>=latex,line width=0.5pt] (p2) -- (p1);

\draw [-,>=latex,line width=0.5pt] (p4) -- (p3);

\draw [-,>=latex,line width=0.5pt] (p3) -- (p1);

\draw [-,>=latex,line width=0.5pt] (p4) -- (p2);

%\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p2);
%
%\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p3);
\draw [densely dashed, line width=0.5pt] (p2) edge[bend left=40,looseness=1.5] (p3);
\draw [red,densely dashed, line width=0.5pt] (p2) edge[bend left=40,distance=1cm] (p3);
\draw [blue,densely dashed, line width=0.5pt] (p2) edge[controls=+(0:1) and +(90:1)] (p3);

\node at (-0.15,-0.15) {1};

\node at (-0.15,1.15) {3};

\node at (1.15,-0.15) {2};

\node at (1.15,1.15) {4};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\node只需将命令上方的这两行更改为

\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p2);
\draw [-,>=latex, dashed, line width=0.5pt] (p23) -- (p3);

进入

\draw [-,>=latex, dashed, line width=0.5pt] (p2) .. controls (p23) .. (p3);

在此处输入图片描述

相关内容