# Asymptote 3D: how to draw a surface with a pattern (e.g. checkerboard)?

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):

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?
-
The simplest solution to the checker problem is probably to use a nested for loop to draw each square as a separate surface. –  Charles Staats May 21 at 1:16
Ah, that's too bad there's not something more elegant.... And the cross-hatch I'm guessing is to draw lines using a loop too? –  fltfan May 21 at 1:27
You might check out the grid3 module. You might also check out Figure 70 on this page. Any method you use will require you to draw the surface using a different method than you are using, and the nested for loop is by far the simplest method to learn. –  Charles Staats May 21 at 2:49
For the oblique perspective from below, try currentprojection = oblique(angle=-45);. According to the documentation, "If an optional real argument is given, the negative z axis is drawn at this angle in degrees." –  Charles Staats May 21 at 2:53
Thanks for all the responses. Setting angle=-45 doesn't bend the arrow upward but apparently people have already tried and failed playing with the parameter (playing with it myself I can at most get it to be "horizontal" on the page: tex.stackexchange.com/questions/125027/… –  fltfan May 21 at 3:21

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:

-

Run with xelatex or latex->dvips->ps2pdf:

\documentclass[pstricks]{standalone}
\usepackage{pst-solides3d}
\colorlet{Green}{green!100!white!40}
\begin{document}

\multido{\iA=0+15}{18}{%  Only for the animation, can be deleted
\psset{lightsrc=viewpoint,viewpoint=30 \iA\space 20 rtp2xyz,Decran=25}
\begin{pspicture}(-5,-2)(5,2)
\psSolid[object=grille,grid,
fcol= /t 0 def 0 1 63 { dup dup 8 mod 0 eq { /t t 1 add def } if
t add 2 mod 0 eq { (Green) }{ (red) } ifelse } for,
base=-4 4 -4 4]
\end{pspicture}%
}% end of multido

\end{document}


-