Graphics, Figures & TablesDrawing interlocking tori using sketch/tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
moitetajni
Posts: 2
Joined: Tue Aug 25, 2015 11:03 pm

Drawing interlocking tori using sketch/tikz

Post by moitetajni »

Hello.

I am trying to create the graph of some interlocking tori like these two
interlocking_tori2.png
interlocking_tori2.png (39.63 KiB) Viewed 3804 times
Since I am not an expert on tikz or sketch, I have been modifying some code I found on the web. So here's the code I have been running so far:

Code: Select all

def torus {
    def n_segs 60
    sweep [draw=none, fill=cyan, fill opacity=0.75] {n_segs, rotate(360/n_segs, (0,0,0), [0,1,0])}
        sweep {n_segs, rotate(360/n_segs, (1.5,0,0), [0,0,1])}
        (2,0,0)
}

def torus2 {
	def n_segs 60
	sweep [draw=none, fill=orange, fill opacity=0.75] {n_segs, rotate(360/n_segs, (1.5,0,0), [0,0,1]) }
		sweep {n_segs, rotate(360/n_segs, (0,0,0), [0,1,0])}
		(2,0,0)

}

put { view((10,4,2)) } {{torus2} {torus}}

global { language tikz }
Here, torus2 was the code I created based on torus. However it is not doing the trick, since I I get is this mess:
failed_interlocking_tori.png
failed_interlocking_tori.png (87.02 KiB) Viewed 3804 times
So my question would be: how can I redefine torus2 so the whole image looks like the one I want?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Drawing interlocking tori using sketch/tikz

Post by Stefan Kottwitz »

Welcome to the forum!

So what did you use - Sketch?

I could imagine making it using pgfplots, which bases on TikZ. Such as this example from TeXwelt, by Henri and Ross:

Code: Select all

\documentclass[margin=2mm,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
%Oberflächenproblem
\begin{tikzpicture}[line width=.7pt]
\begin{axis}[axis equal image,
    clip=false,
    xlabel=\empty, ylabel=\empty, zlabel=\empty,
    axis lines=middle,
    colormap/blackwhite,
    %y dir=reverse,
    %axis on top
    ]
    % sym. Torus:
            \addplot3[domain=0:360,y domain=0:360, samples=50,
            surf,z buffer=sort
            ]
            ({15+(10+4*cos(x))*cos(y)} ,
            {15+(10+4*cos(x))*sin(y)},
            {4+4*sin(x)});
\end{axis}
\end{tikzpicture} 
\end{document}
torus.png
torus.png (60.05 KiB) Viewed 3797 times
Two tori may be split in parts and drawn in an order so the back would be behind the front.

Stefan
LaTeX.org admin
Post Reply