Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
2  
Your example is not complete : line/.style ? axis/.style ? \begin{document}? the class ? –  Alain Matthes Jun 6 '12 at 6:10
add comment

1 Answer

up vote 13 down vote accepted

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

share|improve this answer
    
Beautiful! Thank you! –  Trevor Jun 6 '12 at 6:29
    
Trevor Click the tick mark in the left to accept as right answer –  sandu Jun 6 '12 at 6:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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