6

I'm having issues with the intersection feature. It works, but it seems to "miss" the true intersection a bit. The code below produces the error for me. See this image (can't post it directly because <10 rep points):

http://i.imgur.com/WfRBQ.jpg

Notice how the point E2 is slightly below and to the right of the true intersection. Is this just a calculation error? Or am I doing something wrong?

Cheers,

Trevor

\usepackage{tikz}
\usetikzlibrary{arrows,shapes,trees,calc}
\usetikzlibrary{intersections}
\usepackage{relsize}

\begin{tikzpicture}[
    scale=2.2,
    dot/.style={circle, fill=black, minimum size=4pt, inner sep=0pt},]
\newcommand\Sshift{0.8cm}

\coordinate (D_1L) at (0.2,1.8); % DL begin
\coordinate (D_2L) at (2.3,0.2); % DL end
\coordinate (S_1L) at (0.2,0.2); % SL begin
\coordinate (S_2L) at (1.8,1.8); % SL end
\coordinate (S_21L) at ([xshift=\Sshift] S_1L);
\coordinate (S_22L) at ([xshift=\Sshift] S_2L);

\draw[axis,<->] (2.8,0) node(Sxaxis)[right] {$Q_{sec}$}
      -| (0,2) node(Syaxis)[above] {$P_{sec}$};

\draw[line, thick] (S_1L) -- (S_2L) node[right] {$S_1$};
\draw[line] (D_1L) -- (D_2L) node[right] {$D$};
\draw[line, thick] (S_21L) -- (S_22L) node[right] (S_22L) {$S_2$};

% intersections
\coordinate (E1L) at (intersection of S_1L--S_2L and D_1L--D_2L);
 \draw[dashed] (Syaxis |- E1L) node[left]{$P_1$}
 -| (Sxaxis -|E1L) node[below]{$Q_1$};
 \node[dot, label=above:{$E_1$}] (E1) at (E1L) {};
\coordinate (E2L) at (intersection of S_21L--S_22L and D_1L--D_2L);
 \draw[dashed] (Syaxis |- E2L) node[left]{$P_2$}
 -| (Sxaxis -|E2L) node[below]{$Q_2$};
 \node[dot, label=right:{$E_2$}] (E2) at (E2L) {};

\end{tikzpicture}
  • 2
    Your example is not complete : line/.style ? axis/.style ? \begin{document}? the class ? – Alain Matthes Jun 6 '12 at 6:10
13

You made a mistake here (I removed the unknown styles)

\draw[,thick] (S_21L) -- (S_22L) node[right] (S_22L) {$S_2$};  

You need to remove the last (S_22L)

    \draw[, thick] (S_21L) -- (S_22L) node[right]  {$S_2$};

You move the the coordinates (S_22L) with node[right] and S_22L) now is not on the line.

\documentclass{scrartcl}    
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,trees,calc}
\usetikzlibrary{intersections}
\usepackage{relsize}

\begin{document}
    \begin{tikzpicture}[
        scale=2.2,
        dot/.style={circle, fill=black, minimum size=4pt, inner sep=0pt},]
    \newcommand\Sshift{0.8cm}

    \coordinate (D_1L) at (0.2,1.8); % DL begin
    \coordinate (D_2L) at (2.3,0.2); % DL end
    \coordinate (S_1L) at (0.2,0.2); % SL begin
    \coordinate (S_2L) at (1.8,1.8); % SL end
    \coordinate (S_21L) at ([xshift=\Sshift] S_1L);
    \coordinate (S_22L) at ([xshift=\Sshift] S_2L);

    \draw[<->] (2.8,0) node (Sxaxis)[right] {$Q_{sec}$}
            -| (0,2)   node (Syaxis)[above] {$P_{sec}$};

    \draw[, thick] (S_1L)  -- (S_2L)  node[right] {$S_1$};
    \draw[]        (D_1L)  -- (D_2L)  node[right] {$D$};
    \draw[, thick] (S_21L) -- (S_22L) node[right]  {$S_2$};

    % intersections
    \coordinate (E1L) at (intersection of S_1L--S_2L and D_1L--D_2L);
     \draw[dashed] (Syaxis |- E1L) node[left]{$P_1$}
     -| (Sxaxis -|E1L) node[below]{$Q_1$};
     \node[dot, label=above:{$E_1$}] (E1) at (E1L) {};
    \coordinate (E2L) at (intersection of S_21L--S_22L and D_1L--D_2L);
     \draw[dashed] (Syaxis |- E2L) node[left]{$P_2$}
     -| (Sxaxis -|E2L) node[below]{$Q_2$};

     \node[dot, label=right:{$E_2$}] (E2) at (E2L) {};

    \end{tikzpicture}   
\end{document}

enter image description here

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.