我有以下图片:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw [<->,thick] (0,3) node (yaxis) [above] {$P$}
|- (3,0) node (xaxis) [right] {$Y$};
\draw (0,0) coordinate (a_1) -- (2,1.8) coordinate (a_2);
\draw (0,1) coordinate (a_3) -- (2,2.8) coordinate (a_4);
\draw (0,1.5) coordinate (b_1) -- (2.5,0) coordinate (b_2);
\draw (0,2.5) coordinate (b_3) -- (2.5,1) coordinate (b_4);
\coordinate (c) at (intersection of a_1--a_2 and b_1--b_2);
\coordinate (d) at (intersection of a_3--a_4 and b_1--b_2);
\coordinate (e) at (intersection of a_3--a_4 and b_3--b_4);
\coordinate (f) at (intersection of a_1--a_2 and b_3--b_4);
\fill[red] (c) circle (2pt);
\fill[red] (d) circle (2pt);
\fill[red] (e) circle (2pt);
\fill[red] (f) circle (2pt);
\end{tikzpicture}
\end{document}
它看起来像这样:
我想要做的(但我不知道该怎么做)是给这些红色交叉点贴上标签,画出从一个点指向另一个点的箭头,然后在箭头的顶部让它们看起来长度相同,即让它们的末端大致位于同一位置(就像在矩形中一样)。我还想在末端贴上标签(一种情况下是顶端,另一种情况下是上端)
答案1
您可以使用该intersections
库来计算直线(或曲线)对的交点。
要向线条添加标签,只需node
在路径上使用即可。
平均能量损失
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw [<->,thick] (0,3) node (yaxis) [above] {$P$}
|- (3,0) node (xaxis) [right] {$Y$};
\draw[name path=A] (0,0) coordinate (a_1) -- (2,1.8) coordinate (a_2)node[right]{SRAS1};
\draw[name path=B] (0,1) coordinate (a_3) -- (2,2.8) coordinate (a_4)node[right]{SRAS2};
\draw[name path=C] (0,2.5) coordinate (b_3) -- (2.5,1) coordinate (b_4)node[right]{AD2};
\draw[name path=D] (0,1.5) coordinate (b_1) -- (2,.3) coordinate (b_2)node[right]{AD1};
\fill[red,name intersections={of=A and C, by=c}](c)circle[radius=2pt];
\fill[red,name intersections={of=B and C, by=d}](d)circle[radius=2pt];
\fill[red,name intersections={of=B and D, by=e}](e)circle[radius=2pt];
\fill[red,name intersections={of=A and D, by=f}](f)circle[radius=2pt];
\draw[-latex,thick,shorten <=2pt,shorten >=5pt]([yshift=3pt]c)--([yshift=3pt]d);
\draw[-latex,thick,shorten <=7pt,shorten >=2pt]([yshift=-3pt]f)--([yshift=-3pt]c);
\end{tikzpicture}
\end{document}