4

This is a horn torus. How can I use latex to generate it ? This is a horn torus. How can I use latex to generate it ?

3
  • 5
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Jun 6, 2018 at 17:22
  • 1
    Maybe this post or this one will help you with the torus. Making it rotate after that shouldn't be too complicated. Jun 6, 2018 at 17:24
  • this is maybe a related but slightly different request. I'm looking for a static vector of this wire torus. At an angle, and also square on looking from one side. Does anyone have access to a vector file or otherwise can guide me in Illustrator with the math required to do so? Thanks!
    – Malcolm
    May 20, 2022 at 6:19

3 Answers 3

20
\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{colormaps}
\begin{document}
\foreach \X in {0,...,14}
{\begin{tikzpicture}
     \begin{axis}[view/h=45,axis lines = none,colormap={fake}{
rgb255(0cm)=(255,255,255); rgb255(1cm)=(255,255,255); rgb255(2cm)=(255,0,0);
rgb255(3cm)=(255,0,0)},unit vector ratio=1 1 1]
        \addplot3[domain=0:360,domain y=0:360,point meta=x-y+z,mesh,
    z buffer=sort]
       ({(1+cos(x+\X))*cos(y+\X)}, 
        {(1+cos(x+\X))*sin(y+\X)}, 
        {sin(x+\X)});
      \end{axis}
      \path (1,1) rectangle (5.9,4.7); % <- Thanks to J Leon V. !
\end{tikzpicture}}
\end{document}

enter image description here

UPDATE: Removed the flickers, big thanks to J Leon V.! And removed the amsmath package and slightly changed the view.

1
  • I still can see the flickers. Jun 6, 2018 at 20:45
14

Just for discover, an option in Asymptote, I tried to find a way to control the color of the spline pen, but I found nothing, the manual is very dark, with this code you get the render according to the question, which is to draw the torus, the file that creates asymptote, allows to rotate the generated graphic, as long as it is through pdf readers that support, 3d, like Acrobat.

The animation is a separate work, because it does not work the same as with tikz the method of using foreach in the stand alone environment, so the animation was done manually by generating 15 files and putting them together in a single pdf, then processing them with the imagemagic converter.

RESULT: enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
% arara: asymptote
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
\documentclass[border=20pt]{standalone}
\usepackage{asymptote}
\begin{document}
    \begin{asy}
        import graph3;      
        size(400,0);
        currentprojection=orthographic(4,0,2);

        real R=10;
        real a=10;
        real D=15*pi/180;

        triple f(pair t) {
        return ((R+a*cos(t.y+D))*cos(t.x+D),(R+a*cos(t.y+D))*sin(t.x+D),a*sin(t.y+D));
        }

        pen p=rgb(1,0,0)+thick();
        surface s=surface(f,(0,0),(2pi,2pi),24,24,Spline);

        draw(s,surfacepen=material(white+opacity(0.8),
        ambientpen=white),meshpen=p);


    \end{asy}
\end{document}

PSD: I could not avoid the flickering since I used the standalone document class, which cuts the canvas according to what is rendered, and it happens that when the rotation is made it varies, I think it can be solved with the geometry package.

UPDATE: AVOID FLICKERING IN ANIMATION...

% PROCESADOR ARARA V3.0
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
% arara: asymptote
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
\documentclass[a5paper]{article}
\usepackage{pdflscape}
\usepackage[
    left=60pt,
    right=0pt,
    top=0pt,
    bottom=0pt,
    foot=0pt
    ]{geometry}
\usepackage{asymptote}
\begin{document}
\pagestyle{empty}
\begin{landscape}
    \centering
    \begin{asy}
        import graph3;      
        size(500,300);
        currentprojection=orthographic(4,0,2);

        real R=10;
        real a=10;
        real D=15*pi/180;

        triple f(pair t) {
        return ((R+a*cos(t.y+D))*cos(t.x+D),(R+a*cos(t.y+D))*sin(t.x+D),a*sin(t.y+D));
        }

        pen p=rgb(1,0,0)+thick();
        surface s=surface(f,(0,0),(2pi,2pi),24,24,Spline);

        draw(s,surfacepen=material(white+opacity(0.8),
        ambientpen=white),meshpen=p);


    \end{asy}
\end{landscape}
\end{document}

UPDATED ANIMATION:

enter image description here


About Colors and Opacity for meshpen:

Using palette module: For surface we have s.colors(palette(s.map(xpart),Gradient(color1,....colorx)) That change the surface color according x position; for pen ¿will not have any similar properties? like p=unknown_macro(palette(p.map(xpart), Gradient(color1,..., colorx)); instead for pgplots colormap in the marmot's answer , if it is possible to do it with the mesh, the problem there is that the mesh is not curved type as splines in Asymptote. For the surfaces it works even with the opacity, as the following test example:

TEST RESULT: enter image description here

Testing MWE:

% PROCESADOR ARARA V3.0
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
% arara: asymptote
% arara: pdflatex: {synctex: yes, action: nonstopmode, shell: yes}
\documentclass[a5paper]{article}
\usepackage{pdflscape}
\usepackage[
    left=60pt,
    right=0pt,
    top=0pt,
    bottom=0pt,
    foot=0pt
    ]{geometry}
\usepackage{asymptote}
\begin{document}
\pagestyle{empty}
\begin{landscape}
    \centering
    \begin{asy}
        import graph3;
        import palette;     
        size(500,300);
        currentprojection=orthographic(0,-2,1);

        real R=10;
        real a=10;
        real D=15*pi/180;

        triple f(pair t) {
        return ((R+a*cos(t.y+D))*cos(t.x+D),(R+a*cos(t.y+D))*sin(t.x+D),a*sin(t.y+D));
        }

        pen p=rgb(0,0,0)+thick();
        surface s=surface(f,(0,0),(2pi,2pi),24,24,Spline);
        s.colors(palette(s.map(xpart),Gradient(red,purple,blue,green+opacity(0.7),green+opacity(0.2))));

        draw(s,meshpen=p,render(merge=true));


    \end{asy}
\end{landscape}
\end{document}
4
  • It looks very nice! I think the spline pen can be changed by altering the RGB values in pen p=rgb(1,0,0)+thick();
    – James
    Jun 7, 2018 at 11:24
  • Very nice! +1 It is possible to vary the color along a path in asymptote, see here. BTW, I often find the tutorial by Charles Staats more accessible than the official documentation. And isn't the flickering just because of the fact that we convert the stuff to gif and there is a limit on the size of the uploaded picture?
    – user121799
    Jun 7, 2018 at 14:29
  • @marmot, Ok, but it's to draw other lines, and the issue is with the mesh, I've put some updates on it, there will be a solution similar to colormap in your answer, for the mesh in asymptote?.
    – J Leon V.
    Jun 7, 2018 at 17:59
  • 2
    The animation is so beautiful. I can not stop looking to it.
    – Sigur
    Jun 7, 2018 at 23:24
5

I normally do not post two answers, but somehow I felt that it should be noted that there is no problem making the torus fade in asymptote, nor to do the animation. I'll be happy to remove this if @J.LeonV adds the elements to her/his answer. I just did not want the readers to get the impression that asymptote has major deficiencies, which I don't think it has.

\documentclass[border=5pt]{standalone}
% using Charles Staats' tutorial: https://math.uchicago.edu/~cstaats/Charles_Staats_III/Notes_and_papers_files/asymptote_tutorial.pdf 
% https://tex.stackexchange.com/a/339046/121799 for the plane
% https://tex.stackexchange.com/a/339046/121799 for the animation
% and https://tex.stackexchange.com/a/435341/121799 for the torus parametrization
\usepackage{filecontents}
\begin{filecontents*}{horntorus.asf}
\begin{asypicture}{name=horntorus}
settings.render = 8;
settings.prc = false;
settings.outformat = "pdf";

import graph3;
import contour;
size3(8cm);

real rotangle = @myangle;

currentprojection = orthographic(10,1,4);
defaultrender = render(merge = true);

        real R=2;
        real a=2;
        real D=15*pi/180;

triple f(pair t) {
        return ((R+a*cos(t.y+D))*cos(t.x+D),(R+a*cos(t.y+D))*sin(t.x+D),a*sin(t.y+D));
        }

path3 vcircle(real vx){
 triple fx(real t) {
    return f((t,vx*D));
  }
  return graph(fx, 0, 2*pi, operator ..);
}

path3 hcircle(real vx){
 triple fy(real t) {
    return f((vx*D,t));
  }
  return graph(fy, 0, 2*pi, operator ..);
}

for (int irun=1; irun<=24;irun+=1)
{
draw(vcircle(irun+rotangle), p=red);
draw(hcircle(irun+rotangle), p=red);
}

real Rad=2*R; 
path3 plane =  Rad*sqrt(2)*Y+Rad*Z -- Rad*sqrt(2)*Y-Rad*Z -- 
-Rad*sqrt(2)*Y-Rad*Z -- -Rad*sqrt(2)*Y+Rad*Z -- cycle;
surface cheatplane = surface(plane);
for (int irun=0; irun<=10;irun+=1)
{
draw(shift((0.2-0.25*irun)*(X))*rotate(-45,Y)*cheatplane,white+opacity(0.1*irun),light=nolight);
}
\end{asypicture}
\end{filecontents*}
\usepackage{pgffor}
\usepackage{asypictureB}
\standaloneenv{asypicture}
\begin{document}
\foreach \X [count=\n,evaluate={\myangle=\X/24)}] in {1,...,24}
{
\RequireAsyRecompile
\input{horntorus.asf}
}
\end{document}

enter image description here

The way I made the torus fade away is putting white planes with a certain opacity at the right (?) places. The really cool thing about asymptote is that it has a 3D engine, such that this is really easy to implement.

3
  • 1
    +1 Excellent, as always; your code solves all the problems in my attempt, it must be accepted as the best solution ...
    – J Leon V.
    Jun 7, 2018 at 18:05
  • @JLeonV. You can still build this into your nice solution, if you want... Otherwise that's the first time (I think) that I post two answers...
    – user121799
    Jun 7, 2018 at 21:19
  • I do not think it's a problem that you have 2 answers if both are alternatives that can be very useful, in my opinion aligning it with my answer would decrease the variety of alternatives, for me the ideal would be to include it in an update to your first response, Maybe you can also use it to remove the flickering of your first answer, adding a frame like \draw[white](1,1) rectangle 5.9.4.7);
    – J Leon V.
    Jun 7, 2018 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .