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 trying to draw a cycle, where the lines A-B and C-D overlap the 1-2 and 3-4 lines.

  1. Is it possible to trim or clip the numbered lines above and below when they cross the other ones?
  2. Is there alternatively a way to calculate the cross points so I can simply put them into the coordinates?

I've read through the documentary for hours and couldn't find a way though.

    \begin{tikzpicture} [>=latex]

        \draw [->, thick] (0,0) -- (10,0);
        \draw [->, thick] (0,0) -- (0,8);

        \coordinate (A) at (0.5,1.5);
        \coordinate (B) at (8.5,7.5);
        \coordinate (C) at (8.5,4);
        \coordinate (D) at (0.5,0.5);

        \coordinate [label=below:$1$] (1) at (1.5,0.5);
        \coordinate [label=above:$2$] (2) at (1.5,2.5); 
        \coordinate [label=above:$3$] (3) at (7.5,7);
        \coordinate [label=below:$4$] (4) at (7.5,3);

        \draw [-] (A) to[out=25,in=230] (B);
        \draw [-] (C) to[out=215,in=15] (D);
        \draw [-] (1) to (2);
        \draw [-] (3) to (4);

    \end{tikzpicture}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You could use clipping, but here's an answer using the intersections library:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[>=latex]
\draw [->, thick] (0,0) -- (10,0);
\draw [->, thick] (0,0) -- (0,8);

\coordinate (A) at (0.5,1.5);
\coordinate (B) at (8.5,7.5);
\coordinate (C) at (8.5,4);
\coordinate (D) at (0.5,0.5);

\coordinate [label=below:$1$] (1) at (1.5,0.5);
\coordinate [label=above:$2$] (2) at (1.5,2.5); 
\coordinate [label=above:$3$] (3) at (7.5,7);
\coordinate [label=below:$4$] (4) at (7.5,3);

\draw [-, name path=A to B] (A) to[out=25,in=230] (B);
\draw [-, name path=C to D] (C) to[out=215,in=15] (D);
\path [-, name path=1 to 2] (1) to (2);
\path [-, name path=3 to 4] (3) to (4);

\tikzset{
    name intersections={of=A to B and 1 to 2, by={X1}},
    name intersections={of=C to D and 1 to 2, by={Y1}},
    name intersections={of=A to B and 3 to 4, by={X2}},
    name intersections={of=C to D and 3 to 4, by={Y2}}
}
\draw (X1) -- (Y1);
\draw (X2) -- (Y2);

\useasboundingbox (-0.5,-0.5) rectangle (10.5, 8.5);
\end{tikzpicture}
\end{document}

EDIT: Changed specification of intersections to a single \tikzset rather than multiple \path commands.

enter image description here

share|improve this answer
    
Haven't thought of intersections yet. I will have a deeper look into it. Thank you very much. –  Stephanus Sutor Feb 25 '13 at 21:09

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.