略有变化

略有变化

我正在学习如何用 绘制图表,tikzpicture并寻求一些帮助来动态计算一些点。我制作了下面的图表,但我很难动态计算点 U^*(0,-4)和。以及和 处的(6, -4)弧的定义。我最初的灵感是这个(0:45:2)(0:-34:2)图表. MWE 如下

图表

\documentclass[tikz,convert=false]{standalone}
\begin{document}

\begin{tikzpicture}[scale=0.22]
\coordinate (origo) at (0,0);
\coordinate (gs) at (12,12);
\coordinate (gi11) at (0,4);
\coordinate (gi12) at (12,8);
\coordinate (u) at (12,-8);

\scriptsize
% Draw the axis
\draw[help lines,->] (origo) -- (12,0) node  (raxis)  [right] {$r$};
\draw[help lines,->] (origo) -- (0,12) node  (gaxis)  [above] {$g$};
\draw[help lines,->] (origo) -- (0,-12) node  (uaxis)  [below] {$u$};

% Draw the two intersecting lines of g^s and g^i
\draw(origo) coordinate (gs_1) -- (gs) coordinate (gs_2)  node[right]{$g^s$};
\draw(gi11) coordinate (gi_1) node[left, font=\tiny]{}--(gi12) coordinate (gi_2) node[above right]{$g^i$};
% Draw u
\draw(origo) coordinate (u_1)--(u) coordinate (u_1) node[above right]{$u$};

% Calculate the intersection of the lines gi_1--gi_2 and gs_1--gs_2% and store the coordinate in c.
\coordinate (c) at (intersection of gi_1--gi_2 and gs_1--gs_2);

% Draw dashed equilibrium line
\draw[gray, dashed] (0,-4) node[left] {$u^{*}$}--(6, -4) coordinate--(c |- raxis)   node[below right] {$r^{*}$}--(c |- c)--(gaxis |- c) node[left]{$g^{*}$}; 

% Draw arc and label
\draw (0,0) ++(0:2) arc(0:45:2); % that the 45 is dynamically created 
\node [right, font=\tiny] at (1.5,1.1) {$s_\pi$};
\draw (0,0) ++(0:2) arc(0:-34:2); % that the -34 is dynamically created 
\node [right, font=\tiny] at (1.5,-.8) {$\frac{v}{\pi}$};
\end{tikzpicture}

\end{document}

答案1

为了计算交点,我使用了intersections库的语法,而不是您使用的旧语法。您的版本仍然有效,但我认为手册中没有记录。

我向下画一条路径c并计算该路径与线的交点u以帮助绘制虚线。

为了绘制角度,我使用了angle pic来自angles库的,以及quotes来自同名库的语法。

在此处输入图片描述

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{intersections,quotes,angles}
\begin{document}
\begin{tikzpicture}[scale=0.22]
\coordinate (origo) at (0,0);
\coordinate (gs) at (12,12);
\coordinate (gi11) at (0,4);
\coordinate (gi12) at (12,8);
\coordinate (u) at (12,-8);

\scriptsize
% Draw the axis
\draw[help lines,->] (origo) -- (12,0) node  (raxis)  [right] {$r$};
\draw[help lines,->] (origo) -- (0,12) node  (gaxis)  [above] {$g$};
\draw[help lines,->] (origo) -- (0,-12) node  (uaxis)  [below] {$u$};

% Draw the two intersecting lines of g^s and g^i
\draw [name path=gs] (origo) -- (gs) node[right]{$g^s$};
\draw [name path=gi] (gi11) -- (gi12) node[above right]{$g^i$};

% Draw u
\draw [name path=u] (origo) -- (u) node[above right] {$u$};

% Calculate the intersection of the lines gi_1--gi_2 and gs_1--gs_2% and store the coordinate in c.
\path [name intersections={of=gs and gi}] (intersection-1) coordinate (c);
\path [name path=downfromc] (c) -- (c|-uaxis) coordinate (belowc);
\path [name intersections={of=downfromc and u}] (intersection-1) coordinate (c2);

% Draw dashed equilibrium line
\draw [gray,dashed] (c-|origo) node[left]{$g^{*}$} -| (c2) -- (c2-|origo) node[left] {$u^{*}$};
\node [below right,gray] at (origo -| c)  {$r^{*}$};

% Draw arc and label
\pic [draw,"$s_\pi$"{font=\tiny,shift={(1.2em,.5em)}}] {angle=raxis--origo--gs};
\pic [draw,"$\frac{v}{\pi}$"{font=\tiny,shift={(1.2em,-.4em)}}] {angle=u--origo--raxis};
\end{tikzpicture}

\end{document}

略有变化

在宏中保存轴的尺寸,以便更容易更改。

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{intersections,quotes,angles}
\begin{document}
\begin{tikzpicture}[every node/.append style={font=\scriptsize}]
\pgfmathsetmacro{\EFyext}{12*0.22}
\pgfmathsetmacro{\EFxext}{\EFyext*1.2}
\coordinate (origo) at (0,0);
\coordinate (gs) at (\EFxext,\EFyext);
\coordinate (gi11) at (0,\EFyext/3);
\coordinate (gi12) at (\EFxext,\EFyext*2/3);
\coordinate (u) at (\EFxext,-\EFyext*2/3);

% Draw the axis
\draw[help lines,->] (origo) -- (\EFxext,0) node  (raxis)  [right] {$r$};
\draw[help lines,<->] (0,-\EFyext) node (uaxis)  [below] {$u$} -- (0,\EFyext) node  (gaxis)  [above] {$g$};

% Draw the two intersecting lines of g^s and g^i
\draw [name path=gs] (origo) -- (gs) node[right]{$g^s$};
\draw [name path=gi] (gi11) -- (gi12) node[above right]{$g^i$};

% Draw u
\draw [name path=u] (origo) -- (u) node[above right] {$u$};

% Calculate the intersection of the lines gi_1--gi_2 and gs_1--gs_2% and store the coordinate in c.
\path [name intersections={of=gs and gi}] (intersection-1) coordinate (c);

% calculate 
\path [name path=downfromc] (c) -- (c|-uaxis) coordinate (belowc);
\path [name intersections={of=downfromc and u}] (intersection-1) coordinate (c2);

% Draw dashed equilibrium line
\draw [gray,dashed] (c-|origo) node[left]{$g^{*}$} -| (c2) -- (c2-|origo) node[left] {$u^{*}$};
\node [below right,gray] at (origo -| c)  {$r^{*}$};

% Draw arc and label
\pic [draw,"$s_\pi$"{font=\tiny,shift={(1.2em,.5em)}}] {angle=raxis--origo--gs};
\pic [draw,"$\frac{v}{\pi}$"{font=\tiny,shift={(1.2em,-.4em)}}] {angle=u--origo--raxis};
\end{tikzpicture}
\end{document}

相关内容