[Tex/LaTex] Asymptote 3D: how to draw a surface with a pattern (e.g. checkerboard)

3dasymptote

In Asymptote, I'd like to draw two intersecting planes, one with a solid color and another with some pattern (e.g. checkerboard), so that it would look okay if printed black and white. However, the pattern module doesn't appear to work.

The code below is what I'm trying to get to work, with the statement that I wished drew that plane commented out (I understand of course that function doesn't exist, I just don't know which one to use).

settings.prc = false;
defaultpen(fontsize(10pt));
import three;
import graph3;
import patterns;
size(11cm,0);

real rot_param = 0.01;
currentprojection=perspective((10000,-20000,100000),up=(-rot_param,1-rot_param,0));
currentlight = (4,-1,4);

render render = render(compression=Low, merge = true);

limits((0,0,0), (3,3,3));

real delta = 0.75;
real dterm = (1-delta)/delta;

draw(surface(O -- (dterm,0,0) -- (3,3-dterm,0) -- (3,3,0) -- cycle), orange+opacity(0.5), render);
draw(surface(O -- (3,3,0) -- (0,3,0) -- cycle), orange+opacity(0.5), render);
draw(surface(O -- (3,3,0) -- (3,3,3) -- (0,0,3) -- cycle), lightred+opacity(0.5), render);
draw(surface((dterm,0,0) -- (3,3-dterm,0) -- (3,3-dterm,3) -- (dterm,0,3) -- cycle), lightblue+opacity(0.5), render);

// Does not work!
//filldraw(surface((dterm,0,0) -- (3,3-dterm,0) -- (3,3-dterm,3) -- (dterm,0,3) -- cycle), pattern("checker"));

xaxis3("",Bounds,black+dashed,InTicks(3,1));
yaxis3("",Bounds,black+dashed,InTicks(3,1));
//zaxis3("",Bounds,black,InTicks(3,1));
draw(O -- 3.5X,arrow=Arrow3);
label("$\gamma(C)$",3.7X);
draw(O -- 4Y,dashed, arrow=Arrow3);
label("$\gamma(D)$",4.2Y);
draw(O -- 4Z,arrow=Arrow3);
label("$\phi(C,\theta_0)$",(-0.2,0,5));
label("1",(-0.1,0,3));

draw(box((0,0,3),(3,3,3)), black+linewidth(0.6pt));
draw((0,3,0) -- (0,3,3), dashed);
draw((3,3,0) -- (3,3,3));
draw((3,0,0) -- (3,0,3));

This is how it looks (I'd like to make at least the blue plane checkerboard):
Generated plot

I would be very grateful if anyone knows how to do this. In case you can't tell I have some other problems too, so I'll just throw these out there if anyone happens to know:

  • I'm using perspective but I'd like to use the "oblique" perspective except from "below", so that the axis pointing "out of the screen" ($\phi(C,\theta_0)$ ) is actually pointing up and to the left a bit. I've tried to approximate it as you can see. Is there a way to do this?
  • How do I get the last "3"s to show up as labels on the axis?
  • I don't want the vertical axis to scale (I want it bigger than it appears, so I'm just relabeling, e.g. the 1). Is there a way to do this automatically?

Best Answer

Here's a minimal example showing an elegant(?) way to set up a checkerboard pattern on a surface. To use this you need control over how exactly the surface is built out of patches; this is easiest to accomplish by constructing the surface as a parametric graph and using the nu= and if necessary the nv= parameters.

\documentclass[margin=10pt, convert]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=plane}
settings.outformat="png";
settings.render=4;
size(10cm);
import graph3;      //Need graph3, not just three, for parametric surfaces.

triple uaxis = X, vaxis = Y, c = O;
int n = 8;

triple plane(pair coords) {
    return c + coords.x*uaxis + coords.y*vaxis;
} 

surface s = surface(plane, (0,0), (1,1), nu=n);

material[] surfacepen = new material[] {red, green};
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);
\end{asypicture}
\end{document}

The result:

enter image description here