5

I want to draw a surface of genus 3. I produced this

\documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings} 
\usetikzlibrary{arrows, arrows.meta}


\begin{document}


\begin{tikzpicture}

\draw (-2.6,-1.5) to [out=320, in=70] (-2,-4) %unterer Torus
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=220] (2.6,-1.5);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.2,-6.4) to[bend right] (1.2,-6.4);
\end{tikzpicture}

\end{document}

Which gives me

enter image description here

Now, I would like to get 2 copies of this, rotate them and glue them together to get one surface. Is there an easy way to do this?

  • It's a nice question, but your code produces quite a bumpy handle, plus the way you draw the "hole" should probably not be rotated. I think you might get prettier results, if you allowed answers that just draw a surface of genus 3 in tikz without using your code... (I hope you don't take offence — I don't mean to be snarky.) – Earthliŋ Dec 20 '18 at 19:05
  • I definitely agree that the "hole" shouldn't be rotated. And yes, the handle is not the nicest. What would be a better approach? – mathstackuser Dec 21 '18 at 10:21
  • Charles Staat's solution to my problem (https://tex.stackexchange.com/questions/231515/draw-a-smooth-surface) is a beautiful genus 3 surface. – Benjamin McKay Dec 21 '18 at 20:48

3 Answers3

6

This is what pics are made for. You can rotate (and stretch etc.) them and also name coordinates within them that get prefixed. That allows you to connect the handles in a smooth way.

\documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{tikz}
\tikzset{pics/.cd,
handle/.style={code={
\draw (-2.6,-1.5) coordinate (-left) to [out=320, in=70] (-2,-4) %unterer Torus
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=220] (2.6,-1.5)  coordinate (-right);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.2,-6.4) to[bend right] (1.2,-6.4);
}}}
\begin{document}
\begin{tikzpicture}
\pic {handle};
\end{tikzpicture}

\begin{tikzpicture}
\pic (lower) at (0,1) {handle};
\pic[rotate=180] (upper) at (0,-1) {handle};
\draw (lower-left) to[out=130,in=-130] (upper-right);
\draw (lower-right) to[out=50,in=-50] (upper-left);
\end{tikzpicture}

\end{document}

enter image description here

Harald Hanche-Olsen reminded me what genus-3 is, so I read the question wrong. Big thanks to Harald.

\documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{tikz}
\tikzset{pics/.cd,
handle/.style={code={
\draw (-2.6,-1.5) coordinate (-left) to [out=320, in=70] (-2,-4) %unterer Torus
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=220] (2.6,-1.5)  coordinate (-right);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.2,-6.4) to[bend right] (1.2,-6.4);
}}}
\begin{document}

\begin{tikzpicture}
\pic (lower) at (-0.5,0.85) {handle};
\pic[rotate around={120:(120:1)}] (tr) at (-120:1) {handle};
\pic[rotate around={-120:(-120:-1)}] (tl) at (-120:1) {handle};
\end{tikzpicture}

\end{document}

enter image description here

Here is an arguably nicer looking alternative.

\documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{tikz}
\tikzset{pics/.cd,
handle/.style={code={
\draw[fill=gray!20]  (-2,0) coordinate (-left) 
to [out=260, in=60] (-3,-2) 
to [out=240, in=110] (-3,-4) 
to [out=290,in=180] (0,-6) 
to [out=0,in=250] (3,-4) 
to [out=70,in=300] (3,-2) 
to [out=120,in=280] (2,0)  coordinate (-right);
\pgfgettransformentries{\tmpa}{\tmpb}{\tmp}{\tmp}{\tmp}{\tmp}
\pgfmathsetmacro{\myrot}{-atan2(\tmpb,\tmpa)}
\draw[rotate around={\myrot:(0,-2.5)}] (-1.2,-2.4) to[bend right]  (1.2,-2.4);
\draw[fill=white,rotate around={\myrot:(0,-2.5)}] (-1,-2.5) to[bend right] (1,-2.5) 
to[bend right] (-1,-2.5);
}}}
\begin{document}

\begin{tikzpicture}
\pic (lower) at (0,-pi) {handle};
\pic[rotate=120] (tr) at (30:pi) {handle};
\pic[rotate=-120] (tl) at (150:pi) {handle};
\fill[gray!20]  (lower-right) to[out=100,in=200] (tr-left)-- 
(tr-right) to[out=-130,in=-40] (tl-left)
-- (tl-right) to[out=-20,in=80] (lower-left) -- cycle;
\draw (lower-right) to[out=100,in=200] (tr-left);
\draw (tr-right) to[out=-130,in=-40] (tl-left);
\draw (tl-right) to[out=-20,in=80] (lower-left);
\end{tikzpicture}
\end{document}

enter image description here

  • 2
    A good answer so far, but to get genus 3, you need to have three copies stitched together. You want one in the original orientation, and the two others rotated 120 and 240 degrees respectively. I don't want to steal your code for an answer of my own, so leave it to you to implement it. 8-) – Harald Hanche-Olsen Dec 20 '18 at 14:26
  • @HaraldHanche-Olsen Thanks! I was not sure what the OP wants. I read "2 copies" in the way that the OP want only two handles. But you are right, genus-3 suggests that you read the question correctly. Thanks again! –  Dec 20 '18 at 14:45
  • Good! Now it's up to the OP to adjust the beginning and ending angles appropriately in order to get a smooth transition. – Harald Hanche-Olsen Dec 20 '18 at 15:34
  • Thanks! What would be a simpler code? I would like to be able to vary the angles at the end of the handle, as I also need to produce surfaces of higher genus – mathstackuser Dec 21 '18 at 10:27
  • 1
    I added something. +1 for your own proposal. –  Dec 21 '18 at 13:00
  • Thanks! Looks a bit better. I will position the "holes" by hand, as they shouldn't be turned. Now, I would like to draw the surface in grey. I tried to use the fill=gray command and then filling back the "holes" with white but that doesn't look good around the holes because more then the area betwenn the lines ist filled with whits then. Any idea how to solve this? – mathstackuser Dec 21 '18 at 13:38
  • @mathstackuser It is very easy not to turn the holes, or, more precisely, to rotate them back to "horizontal". and your holes were not filled correctly since they were not an appropriate fill path, but just two arcs going from left to right. You need some closed path instead. –  Dec 21 '18 at 17:04
  • @marmot Thanks a lot, this was very helpful! I would like to use a specific point on the arc which bounds the holes, something like (-1,-2.6) to[bend right] coordinate[pos=0.7] (A) (1,-2.6). But if I define it inside of \tikset I can not use it outside of it. Any idea for this? – mathstackuser Jan 14 '19 at 16:43
  • 1
    @mathstackuser You can use almost precisely what you suggest: use \draw[fill=white,rotate around={\myrot:(0,-2.5)}] (-1,-2.5) to[bend right] coordinate[pos=0.7] (-A) (1,-2.5) to[bend right] (-1,-2.5); in the definition of the pic and then you can access the coordinate from outside with \draw (lower-A) -- ++ (2,-2); Note that there is a prefix, but this is of course good because each of the pics will then produce unique coordinates (as long as their names are unique). –  Jan 14 '19 at 16:54
4

Quick and dirty

\documentclass[margin=0pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings}
\usetikzlibrary{arrows, arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate=180]
\draw (-2.6,-1.5) to [out=320, in=70] (-2,-4) %unterer Torus
to [out=260, in=60] (-3,-6)
to [out=240, in=110] (-3,-8)
to [out=290,in=175] (0,-9)
to [out=5,in=250] (3,-8)
to [out=70,in=300] (3,-6)
to [out=120,in=280] (2,-4)
to [out=110,in=220] (2.6,-1.5);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.2,-6.4) to[bend right] (1.2,-6.4);
\end{scope}
\begin{scope}[yshift=3cm]
\draw (-2.6,-1.5) to [out=320, in=70] (-2,-4) %unterer Torus
to [out=260, in=60] (-3,-6)
to [out=240, in=110] (-3,-8)
to [out=290,in=175] (0,-9)
to [out=5,in=250] (3,-8)
to [out=70,in=300] (3,-6)
to [out=120,in=280] (2,-4)
to [out=110,in=220] (2.6,-1.5);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.2,-6.4) to[bend right] (1.2,-6.4);
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Denis
  • 5,267
1

Editing some angles, this is what I got

    \documentclass[margin=0pt]{standalone}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings} 
\usetikzlibrary{arrows, arrows.meta}

\begin{document}

\begin{tikzpicture}

\draw (-2.6,-1.5) to [out=300, in=70] (-2,-4) %Torus 1
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9.5) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=240] (2.6,-1.5);
\draw (-1,-6.5) to[bend left] (1,-6.5);
\draw (-1.1,-6.43) to[bend right] (1.1,-6.43);

\draw[rotate=120] (-2.6,-1.5) to [out=300, in=70] (-2,-4) %Torus 2
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9.5) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=240] (2.6,-1.5);
\draw[shift={(5.7 cm,9.25 cm)}] (-1,-6.5) to[bend left] (1,-6.5);
\draw[shift={(5.7 cm,9.25 cm)}] (-1.1,-6.43) to[bend right] (1.1,-6.43);

\draw[rotate=240] (-2.6,-1.5) to [out=300, in=70] (-2,-4) %Torus 3
to [out=260, in=60] (-3,-6) 
to [out=240, in=110] (-3,-8) 
to [out=290,in=175] (0,-9.5) 
to [out=5,in=250] (3,-8) 
to [out=70,in=300] (3,-6) 
to [out=120,in=280] (2,-4) 
to [out=110,in=240] (2.6,-1.5);
\draw[shift={(-5.8 cm,10.25 cm)}] (-1,-6.5) to[bend left] (1,-6.5);
\draw[shift={(-5.8 cm,10.25cm)}] (-1.1,-6.43) to[bend right] (1.1,-6.43);


\node[above] (v1) at (0,0) {$x$}; %Beschriftung Basispunkt
\node[below] at (0,-9.5) {1}; %Beschriftung Tori
\node[right] at (8.25,4.7) {2}; %Beschriftung Tori
\node[left] at (-8.25,4.7) {3}; %Beschriftung Tori

\end{tikzpicture}

\end{document}

This produces

enter image description here