tikzpicture dynamically calculate points

I'm learning how to draw diagrams with tikzpicture and I am looking for some help to dynamically calculate some points. I've made the diagram below, but I am struggling to calculate the point U^* (0,-4) and (6, -4) dynamically. Along with the definition of the arcs at (0:45:2) and at (0:-34:2). My initial inspiration was this diagram. MWE below \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}


To calculate the intersection I used the syntax of the intersections library instead of the old syntax you use. Your version still works, but I don't think it's documented in the manual.

I draw a path down from c and calculate the intersection of this and the u line to help in drawing the dashed line.

To draw the angles I use the angle pic from the angles library, and the quotes syntax from the library of the same name. \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}


A slight variation

Saving the dimensions of the axes in macros, so it's easier to change.

\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}

• Thank you for responding to my question. I tried running your code changing the angle of u by changing \coordinate (u) at (12,-8); to \coordinate (u) at (12,-10); when it failed to draw the [gray,dashed] I tried fixing it by changing 0,-10, but got stuck again with your new code. Could you possible give me a hint to solve this? – Eric Fail Dec 19 '15 at 21:36
• @EricFail I modified that part a bit, drawing the line down from c to the y-level of uaxis. Works for u down to about (12,-25). – Torbjørn T. Dec 19 '15 at 21:48
• Thanks, super helpful. What's with the slight variation version? I don't understand what you did there and why. You did however answer my question! – Eric Fail Dec 19 '15 at 21:55
• @EricFail The difference is just that the lengths of the axes (and some other things) are all calculated based on one macro. Perhaps not a big deal here, but if you have numbers that are repeated a lot in a drawing then saving those to a macro makes it easier to change an image, as you don't have to modify every occurrence of the value, you just change the definition of the macro. – Torbjørn T. Dec 19 '15 at 22:02