2

http://pstricks.blogspot.com/2015/02/tore-evide-avec-pst-solides3d.html

enter image description here

Asymptote code,

settings.render=10;
import graph3;
// import palette;

currentprojection=orthographic(1,1,.5);

size(7cm);
defaultrender.merge=true;

triple f(pair z) {
real u=z.x,v=z.y;
return ((3+ 1.5*cos(u))*cos(v),1.5*sin(u),(3+ 1.5*cos(u))*sin(v));
}

surface s=surface(f,(pi/4,0),(1.75*pi,2pi),24,48,Spline);

draw(s,cyan,black+0.6bp);

draw(Label("$y$",1),(0,-6,0)--(0,6,0),red,Arrow3);
draw(Label("$x$",1),(-6,0,0)--(6,0,0),red,Arrow3);
draw(Label("$z$",1),(0,0,-5)--(0,0,6),red,Arrow3);

enter image description here

Question:

How can I fill inside and outside like this torus in Asymptote?

2
  • @chishimotoji, your question should be phrased clearly. May 14, 2021 at 18:04
  • @KimJongUn I forgot this name a long time ago. May 15, 2021 at 9:20

1 Answer 1

5

This is almost exactly copied from this answer except that I use your surface, changed the colors to black and white, and adjusted n.

\documentclass[margin=10pt, convert]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=plane}
settings.render=10;
import graph3;
// import palette;

currentprojection=orthographic(1,1,.5);

size(7cm);
defaultrender.merge=true;

int n = 48;

triple f(pair z) {
real u=z.x,v=z.y;
return ((3+ 1.5*cos(u))*cos(v),1.5*sin(u),(3+ 1.5*cos(u))*sin(v));
}

surface s=surface(f,(pi/4,0),(1.75*pi,2pi),24,48,Spline);

material[] surfacepen = new material[] {black,white};
surfacepen.cyclic = true;
if (n % 2 == 0) {
    surfacepen = sequence(new material(int i) {
            if (i >= n) ++i;
            return surfacepen[i];
            }, 
        2n);
    write(surfacepen.length);
    surfacepen.cyclic=true;
}


draw(s, surfacepen=surfacepen);

draw(Label("$y$",1),(0,-6,0)--(0,6,0),red,Arrow3);
draw(Label("$x$",1),(-6,0,0)--(6,0,0),red,Arrow3);
draw(Label("$z$",1),(0,0,-5)--(0,0,6),red,Arrow3);
\end{asypicture}
\end{document}

enter image description here

If you want to color the inner and outer parts of the surface differently, then you need to clarify what is meant by that. In general this requires an orientable surface, e.g. a Moebius strip does not have inner and outer parts. Of course, like in PSTricks, you can do it "by hand".

\documentclass[margin=10pt, convert]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=plane}
settings.render=10;
import graph3;
// import palette;

currentprojection=orthographic(1,1,.5);

size(7cm);
defaultrender.merge=true;

int n = 48;

triple fi(pair z) {
real u=z.x,v=z.y;
return ((3+ 1.5*cos(u))*cos(v),1.5*sin(u),(3+ 1.5*cos(u))*sin(v));
}

surface si=surface(fi,(pi/4,0),(1.75*pi,2pi),24,48,Spline);

material[] surfacepeni = new material[] {red,white};
surfacepeni.cyclic = true;
if (n % 2 == 0) {
    surfacepeni = sequence(new material(int i) {
            if (i >= n) ++i;
            return surfacepeni[i];
            }, 
        2n);
    write(surfacepeni.length);
    surfacepeni.cyclic=true;
}


draw(si, surfacepen=surfacepeni);

triple fo(pair z) {
real u=z.x,v=z.y;
return ((3+ 1.501*cos(u))*cos(v),1.501*sin(u),(3+ 1.501*cos(u))*sin(v));
}

surface so=surface(fo,(pi/4,0),(1.75*pi,2pi),24,48,Spline);

material[] surfacepeno = new material[] {black,white};
surfacepeno.cyclic = true;
if (n % 2 == 0) {
    surfacepeno = sequence(new material(int i) {
            if (i >= n) ++i;
            return surfacepeno[i];
            }, 
        2n);
    write(surfacepeno.length);
    surfacepeno.cyclic=true;
}


draw(so, surfacepen=surfacepeno);


draw(Label("$y$",1),(0,-6,0)--(0,6,0),red,Arrow3);
draw(Label("$x$",1),(-6,0,0)--(6,0,0),red,Arrow3);
draw(Label("$z$",1),(0,0,-5)--(0,0,6),red,Arrow3);
\end{asypicture}
\end{document}

enter image description here

4
  • You might misunderstand the question. The OP wanted to fill both the in and out surfaces. Not just making checkboard pattern. May 14, 2021 at 17:56
  • @KimJongUn Maybe. But then the question is not very well phrased. In particular since not all surfaces are orientable. So the question would, in my opinion, greatly benefit from clarification if it wants something along the lines you are suggesting.
    – user242026
    May 14, 2021 at 18:01
  • @user242026: In Asymptote (and most other 3d drawing systems I imagine), it's very hard to construct a surface that doesn't have an underlying orientable parameterization. If you want to draw a Moebius strip, for instance, you always have to leave a hidden seam, even if you manage to make the seam invisible. May 17, 2021 at 17:53
  • @CharlesStaats Thanks! However, even though the drawing may proceed through orientable surfaces I still think that any prescription of the sort "color the inner surface differently from the outer one" does need a proper definition of "inner" and "outer". For instance, looking at the upper example from p. 94 of your very nice manual I wouldn't know what the inner or outer parts are.
    – user242026
    May 17, 2021 at 18:06

You must log in to answer this question.

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