1

I am aiming to produce the following diagram: enter image description here

Here's an MWE which almost does that:

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds,matrix,patterns}

\begin{document}

    \begin{tikzpicture}[scale=0.5]
    \footnotesize

    \draw[<->] (0,15)--(0,0)--(16.5,0); 
    \draw[name path = S] (0,0) ..controls (1,5) and (9,9.5) .. (12,10.1) node[right]{$S$};
    \draw[name path = Y] (0,0)--(12,12) node[right]{$Y$};

    \path [name intersections={of=S and Y, by = I1}];

    \draw[dashed] let \p1 = (I1) in (\x1,0) node[below]{$k^*$} --(\x1,\y1); 

    % a loop to generate the arrows on the x-axis
    \foreach\i in {1,...,5}{
        \draw let \p1 = (I1) in  (\x1,0) node[shift={(0.5*\i,0)}] {$<$};
        \draw let \p1 = (I1) in  (\x1,0) node[shift={(-0.5*\i,0)}] {$>$};
    }

    \end{tikzpicture}

\end{document}

This MWE produces this output:

enter image description here

I actually know why it is going wrong. The lines Y and S have two intersections - one at the origin, and one higher up (the one I actually want to work with). My code which specifies the coordinates of I1 is:

\path [name intersections={of=S and Y, by = I1}];

and this takes the first intersection at (0,0), which is why the output is as you see.

However, despite knowing the problem, I don't know how to fix it.

How do I modify that code to get the second intersection instead?


There is a 'cheat' which can be used to solve the problem. Simply change the initial coordinates of the Y line from (0,0) to (0.001, 0). This removes the first intersection with no visible effects. However, I'd still like to know how to solve it robustly.

2

You can pass a list to the by key, and then the intersections will get named according to the list. You can even sort the intersections along one path, using the sort by key, but this may fail for complex collections of straight lines.

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,through,backgrounds,matrix,patterns}

\begin{document}

    \begin{tikzpicture}[scale=0.5]
    \footnotesize

    \draw[<->] (0,15)--(0,0)--(16.5,0); 
    \draw[name path = S] (0,0) ..controls (1,5) and (9,9.5) .. (12,10.1) node[right]{$S$};
    \draw[name path = Y] (0,0)--(12,12) node[right]{$Y$};

    \path [name intersections={of=S and Y, by ={aux, I1}}];

    \draw[dashed] let \p1 = (I1) in (\x1,0) node[below]{$k^*$} --(\x1,\y1); 

    % a loop to generate the arrows on the x-axis
    \foreach\i in {1,...,5}{
        \draw let \p1 = (I1) in  (\x1,0) node[shift={(0.5*\i,0)}] {$<$};
        \draw let \p1 = (I1) in  (\x1,0) node[shift={(-0.5*\i,0)}] {$>$};
    }

    \end{tikzpicture}

\end{document}

enter image description here

  • 1
    instead \path [name intersections={of=S and Y, by ={aux, I1}}]; \draw[dashed] let \p1 = (I1) in (\x1,0) node[below]{$k^*$} --(\x1,\y1); you can shortly write \draw[name intersections={of=S and Y, by = {I1,I2}}, dashed] (I1) -- (I1 |- aux) node[below] {$k^*$}; – Zarko Oct 11 '18 at 1:13
  • @zarko The reason I didn't do that is because I needed to use the I2 coordinates in three places. – Thevesh Theva Oct 12 '18 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.