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'd like to be able to draw the following cell complex structure on the (three-dimensional embedding of the) Klein bottle using LaTeX. I am pretty pleased with my hand-drawn rendition, but LaTeX is prettier, and can be edited.

enter image description here

I am still in the process of learning TikZ, and I have not used the pgfplots package before so I don't know if it can help. The only places I found online that seemed related were

http://www.gnuplotting.org/klein-bottle/

pgfplots in combination with gnuplot requires additional semicolon

Edit: Thanks to hpesoj626's helpful comment below, I have got gnuplots working, so I can compile at least the second example above now (I still don't know how to implement the first one). However, there is still the issue of decorating the Klein bottle with the various curves and points I want to draw, which neither post addresses.

Also, both plotting solutions seem to be too "heavy", visually, to really make labeling them in the way I want seem viable. I am looking for more of an outline-looking Klein bottle. If the ultimate answer is that I need to draw it out "by hand" (i.e. plan out a 2-dimensional image representing the Klein bottle), then please post any advice you have about how to go about doing that.

Can anyone suggest a method of drawing this in LaTeX?

share|improve this question
2  
Welcome to TeX.SE. What error messages does question you linked to pgfplots in combination with gnuplot requires additional semicolon produce for you? –  Peter Grill Oct 14 '12 at 6:30
    
Thanks for the helpful introduction to the site. I have added the error message I am getting. I am using TeXstudio 2.4 on Windows 7 64-bit with MiKTeX 2.9. –  Zev Chonoles Oct 14 '12 at 6:41
    
Do you have -shell-scape as an option to pfdlatex, and is gnuplot in your path? I am getting the same error message, but it seems that I do not have gnuplot installed. As I recently changed computers, I also don't have gcc installed so can't build gnuplot, nor can I find precompiled binaries!! And since I am not on the latest Mac OS, I can't download XCode from Apple either!! So, sorry, won't be able to help you further with the gnuplot version. –  Peter Grill Oct 14 '12 at 7:09
    
I'm afraid I don't know what it would mean to "have -shell-scape as an option to pdflatex", nor whether "gnuplot is in my path". Could you provide / link to information about what these mean, and how I can do them? I had already installed gnuplot, thinking that that might be the issue, but there was no change. –  Zev Chonoles Oct 14 '12 at 7:18
    
For your second problem, Open Options>Configure TexStudio The put --shell-escape in the box of the compiler you are using. Say if you are using pdflatex then pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex will do. –  hpesoj626 Oct 14 '12 at 11:25
show 1 more comment

2 Answers

up vote 20 down vote accepted

Further explanations will follow, for now so much:

  • put your sketch in a node
  • recreate the lines using draw commands (I used to[in=,out=,looseness=])
  • remove the sketch

It's far from perfect, somee labels are missing. You can increase the quality ba adding more intermediate points.

(Final) Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}

\usepackage{tikz}
\usetikzlibrary{scopes,intersections}

\newcommand{\Coordinate}[2]%
{ \coordinate (#1) at (#2);
    %\fill[red] (#2) circle (0.05) node[above] {#1};
}

\begin{document}

\begin{frame}

\begin{tikzpicture}
%   \node[above right,inner sep=0,outer sep=0] (a) {\includegraphics{klein.png}};
%   \draw[orange,thin,dashed,] (a.south west) grid (a.north east);
%   \foreach \x in {0,...,10}{\node [below] at (\x,0) {\x};}
%   \foreach \y in {0,...,12}{\node [left] at (0,\y) {\y};}

    \node[fill=blue,circle,label=0:P1,inner sep=0.5mm] (P1) at (4.9,6.7) {};
    \node[fill=blue,circle,label=270:P2,inner sep=0.5mm] (P2) at (2.5,5.4) {};
    \node[fill=blue,circle,label=45:P3,inner sep=0.5mm] (P3) at (1.6,4) {};
    \Coordinate{e5b}{3.6,1.3}
    \Coordinate{e4l}{0.7,4.8}
    \Coordinate{e4r}{9.9,3.7}
    \Coordinate{si}{4.5,7.4}
    \Coordinate{bottom}{6.8,0.9}

    {[very thick,black]
        \draw (e4l) to[out=270,in=160,looseness=1] (P3);
        \draw (P3) to[out=340,in=270,looseness=0.3] node[above,pos=0.7,black] {$e_4$} (e4r);
        \draw[name path=P2e4r] (P2) to[out=120,in=80,looseness=3.7] node[below left,pos=0.7,black] {$f_2$} (e4r);
        \draw[name path=P1P1] (P1) to[out=160,in=270,looseness=1] (2.6,9) to[out=90,in=90,looseness=1.3] node[above, pos=0.5,black] {$e_3$} (6.6,9.6) to[out=270,in=40,looseness=1]  (P1) ;
        \draw (P2) to[out=315,in=315,looseness=0.5] node[below right,pos=0.5,black] {$e_1$} (P1);
        \draw[dashed] (P2) to[out=135,in=135,looseness=0.5] node[below right,pos=0.5,black] {$f_1$} (P1);
        \draw (P2) to[out=220,in=90,looseness=1] (P3);
        \draw (P3) to[out=270,in=150,looseness=1] (e5b);
        \draw (e4l) to[out=270,in=160,looseness=1.3] (e5b);
        \draw (e5b) to[out=340,in=260,looseness=1.1] (e4r);
        \draw[dashed] (P2) to[out=300,in=330,looseness=1] (e5b);
        \draw[dashed] (e4l) to[out=90,in=90,looseness=0.6] (e4r);
        \draw[dashed] (P1) to[out=320,in=190,looseness=0.4] (bottom);
        \draw (P1) to[out=110,in=300,looseness=1] (si);

        \draw (si) to[out=120,in=270,looseness=1] (4,8.5) to[out=90,in=180,looseness=1] (5.2,9.7) to[out=0,in=90,looseness=1] (6,9) to[out=270,in=20,looseness=1] (si);

        \path[name path=e4lsi] (e4l) to[out=90,in=200,looseness=0.8] (si);
        \draw[name intersections={of=e4lsi and P2e4r}] (e4l) to[out=90,in=210,looseness=1] (intersection-1) coordinate (h1);
        \draw[dashed] (intersection-1) to[out=30,in=200,looseness=0.6] (si);
    }
\end{tikzpicture}

\end{frame}

\end{document}

Output

enter image description here

share|improve this answer
7  
Wot no hobby??? –  Loop Space Oct 14 '12 at 19:28
3  
No other hobbies than posting on TeX.SX ;-) –  Tom Bombadil Oct 14 '12 at 23:01
add comment

Here's an alternative to Tom Bombadil's which uses the Hobby algorithm for generating a smooth path through a given set of points (see Curve through a sequence of points with Metapost and TikZ). The point of using this is that it makes it easier to draw an ill-defined shape as you just keep specifying more points on it until it "looks right" - there's no mucking about with looseness or similar. I think that the resulting code looks cleaner as well.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/77606/86}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}[use Hobby shortcut]
\draw ([closed,blank=soft]0,0)
\foreach \pt in {
  (-2,2),
  (2,2),
  (2,-2),
  (-2,-2),
  ([blank]-2,-1),
  (-1,-1),
  (1,-2),
  ([blank=soft]1,2),
  ([blank=soft]-1,1),
  (-3,3),
  (6,4.5),
  (4.5,-4.5),
  (-2.5,-6)
} {
  .. ++\pt
};
\draw[dashed,use previous hobby path={invert soft blanks}];
\draw (0,0) .. +(-1,-1) .. ++(-2,-1);
\draw[dashed] (0,0) .. +(-1,-.75) .. ++(-2,-1);
\draw (-2.45,-3.9) .. +(3.3,-.75) .. (4.2,-3.95);
\draw[dashed] (-2.45,-3.9) .. +(4.3,.5) .. (4.2,-3.95);
\end{tikzpicture}
\end{document}

Result:

Klein bottle

Note that we actually draw the path twice, but invert (mostly) which parts are blanked (this wouldn't be possible via a postaction as it involves modifying the actual path; but when the algorithm is run then it merely generates the points so we can reuse that list but specify different actions to take). This makes it possible to use the same specification and draw the inside and outside parts differently. I mean the outside and inside parts differently. That is to say, the inside and ... oh, never mind.

You have to get the latest version of the hobby code (hobby.dtx, then run tex hobby.dtx) from the TeX-SX launchpad project as I added a few features to make this work.

share|improve this answer
    
Very nice, except for the lower dashed line. As the bottle opening is smooth and circular, it should form a circle with the bottom. –  Tom Bombadil Oct 15 '12 at 17:31
    
@TomBombadil picky picky. But you're right, I'm not happy about that path. In my defence, I did do a fairly important rewrite of the hobby shortcut mechanism that extended its capabilities considerably. –  Loop Space Oct 15 '12 at 19:19
    
@TomBombadil Having had a go at fixing the bottom path, I'm not convinced that it should be an ellipse. It's not like a cylinder end, it's a surface and so the tangent plane (forming the edge of what you see) won't necessarily be a circle. For the torus (which, as I'm sure you'll admit, should be even more circular than a klein bottle) then the equation is more complicated than a circle. –  Loop Space Oct 15 '12 at 19:55
    
Hmm, staring at a torus for several minutes, I think you're right it's not an ellipse, but neither your nor my solution either. I'll stare a little more, probably I'll think of something. –  Tom Bombadil Oct 15 '12 at 22:42
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.