[Tex/LaTex] How to draw differential geometry diagrams like the one below

diagramsnotestikz-pgf

I am making notes on the subject and I have to make too many figures of the following kind. How do I do this?Mani

Best Answer

An alternative tool is Metapost with lualatex and the luamplib package.

enter image description here

Here's a routine to draw manifolds as general randomised ellipses. Drawing labels, arrows, and boxes, etc is covered in the manuals and tutorials linked above. As a bonus I've added the torus hole too.

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
vardef manifold(expr a,b,rho) = 
    (for t=0 upto 7: 
       right scaled (a+rho*normaldeviate) rotated 45t .. 
     endfor cycle) yscaled (b/a)
enddef;
randomseed:=1855.10574;

beginfig(1);
path M, N, torus_edge_lower, torus_edge_upper, torus_hole;

M = manifold(90,60,10);  
N = manifold(80,80,3) shifted 240 right rotated 10;

torus_edge_lower = quartercircle scaled 80 rotated 225 shifted center M shifted (-25,15);
torus_edge_upper = point 1/3 of torus_edge_lower 
              {direction 1/3 of torus_edge_lower rotated 80} 
                .. point 5/3 of torus_edge_lower;
torus_hole = buildcycle(torus_edge_lower,torus_edge_upper);

fill M withcolor .9[blue,white];
unfill torus_hole;
draw M; 
draw torus_edge_lower; 
draw torus_edge_upper;
label(btex $M$ etex, point 7 of M shifted (-6,16));

fill N withcolor .9[green,white];
draw N;
label(btex $N$ etex, point 7 of N shifted (-6,16));
endfig;
\end{mplibcode}
\end{document}