TransWikia.com

Filling out the space between two circles with dashed lines in order to create a torus like shape

TeX - LaTeX Asked by Crimson Crusader on January 18, 2021

documentclass[fleqn]{book}
usepackage{amsmath, amssymb}
usepackage{amsthm}
usepackage{xcolor}
definecolor{nord0}{HTML}{2E3440}
definecolor{nord4}{HTML}{D8DEE9}
definecolor{nord5}{HTML}{E5E9F0}
usepackage{tikz}
usepackage{tikz-3dplot}
usetikzlibrary{shapes.geometric, arrows.meta, decorations.markings}
usepackage{pagecolor}
pagecolor{nord0}

tdplotsetmaincoords{60}{120}
begin{document}


begin{figure}[ht] % ’ht’ tells LaTeX to place the figure ’here’ or at the top of the page
centering % centers the figure
begin{tikzpicture}[tdplot_main_coords]% tikz code goes here
% Axes
draw [-latex, color=nord4] (0,0,0) -- (4,0,0) node [below left] {$x$};
draw [-latex, color=nord4] (0,0,0) -- (0,4,0) node [right] {$y$};
draw [-latex, color=nord4] (0,0,0) -- (0,0,4) node [above] {$z$}; 
draw[color=nord5] (0,0,0) ellipse (3cm and 1cm);
draw[color=nord5] (0,0,0) ellipse (3.55cm and 1.2cm);
draw[color=nord5] (0,0,1) ellipse (3cm and 1cm);
draw[color=nord5] (0,0,1) ellipse (3.55cm and 1.2cm);
draw[color=nord5, thick, decoration={markings, mark=at position 0.75 with {arrow{stealth'}}}, postaction={decorate}] (0,0,0.5) ellipse (3.27cm and 1.1cm);
end{tikzpicture}
end{figure}

end{document}

The title speaks for itself.
Currently this is what I have managed so far enter image description here

One Answer

If you want to draw the torus with tikz I think that is better if you draw circles in a a plane set with canvas and let tikz to calculate the perspective for you.

The following code has a tikz drawing with a possible solution (if I correctly understand what you want to achieve). Then I added another pgfplots drawing perhaps more simple and that looks better (for me).

documentclass[border=2mm]{standalone}
usepackage{pgfplots}
usepackage{tikz-3dplot}
usetikzlibrary{shapes.geometric, arrows.meta, decorations.markings}
pgfplotsset{compat=1.17}

tdplotsetmaincoords{60}{120}
begin{document}
begin{tikzpicture}[tdplot_main_coords]
% Axes
draw [-latex] (-3,0,0) -- (4,0,0) node [below left] {$x$};
draw [-latex] (0,-3,0) -- (0,4,0) node [right] {$y$};
draw [-latex] (0,0,0)  -- (0,0,3) node [above] {$z$}; 
% Main circles
begin{scope}[canvas is xy plane at z=0]
  draw (0,0) circle (2);
  draw[thick, red, decoration={markings, mark=at position 0.15 with {arrow{stealth'}}}, postaction={decorate}] (0,0) circle (2.5);
  draw (0,0) circle (3);
end{scope}
begin{scope}[canvas is xy plane at z=0.5]
  draw (0,0) circle (2.5);
end{scope}
begin{scope}[canvas is xy plane at z=-0.5]
  draw (0,0) circle (2.5);
end{scope}
foreachz in {10,20,...,80}
{
  pgfmathsetmacror{0.5*cos(z)};
  begin{scope}[canvas is xy plane at z=0.5*sin(z)]
    draw[very thin,gray] (0,0) circle (2.5+r);
    draw[very thin,gray] (0,0) circle (2.5-r);
  end{scope}
  begin{scope}[canvas is xy plane at z=-0.5*sin(z)]
    draw[very thin,gray] (0,0) circle (2.5+r);
    draw[very thin,gray] (0,0) circle (2.5-r);
  end{scope}
}

begin{scope}[canvas is xz plane at y=0]
  draw[dashed]  (2.5,0) circle (0.5);
  draw[dashed] (-2.5,0) circle (0.5);
end{scope}
begin{scope}[canvas is yz plane at x=0]
  draw[dashed]  (2.5,0) circle (0.5);
  draw[dashed] (-2.5,0) circle (0.5);
end{scope}
end{tikzpicture}

begin{tikzpicture}
begin{axis}[
  axis equal,
  axis lines=middle,
  xmax=5,ymax=5,zmax=3,
  ticks=none,
  axis line style={draw=none}
  ]
    draw (0,0,0) -- (2,0,0);
    draw (0,0,0) -- (0,-2,0);
    draw[dashed] (2,0,0) -- (3,0,0);
    draw[dashed] (0,-2,0) -- (0,-3,0);
    addplot3[mesh, draw=gray!50, domain=0:360,y domain=0:360, samples=36]
       ({(2.5+0.5*cos(x))*cos(y)}, {(2.5+0.5*cos(x))*sin(y)}, {0.5*sin(x)});
    draw[-latex] (0,-3,0) -- (0,-4,0) node [left]  {$x$};
    draw[-latex] (3,0,0)  -- (4,0,0)  node [right] {$y$};
    draw[-latex] (0,0,0)  -- (0,0,3)  node [above] {$z$};
    end{axis}
end{tikzpicture} 
end{document}

These are both drawings: enter image description here

Correct answer by Juan Castaño on January 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP