Auteur ou autrice : Luís Nobre Gonçalves.
Mise en ligne le 30 janvier 2025

Cet exemple illustre l’utilisation du package featpost
présent sur le CTAN. Ce package permet de réaliser des
dessins en trois dimensions (et en deux dimensions). Il est très pratique pour
illustrer de la géométrie basique dans l’espace.
Code
% cubicstructures.mp
% L. Nobre G.
% 2011
input featpost3Dplus2D;
prologues := 1;
f := 2*(5,3,3.5);
Spread := 20;
Nobjects := 0;
beginfig(6);
numeric i, j, k, c, Mx, My, Mz, is;
string comm, comn, this;
boolean jisodd, kisodd;
color there, ref, aux, Ve[];
path pa, pb, pc, pd;
Mx = 3;
My = 3;
Mz = 3;
kisodd = false;
c = 0.5*sqrt(2);
ref = -0.5*c*(Mx,My,Mz);
aux = ref-0.5*(1,1,1);
Ve0 = aux;
Ve1 = (-X(aux),Y(aux),Z(aux));
Ve2 = (X(aux),-Y(aux),Z(aux));
Ve3 = (X(aux),Y(aux),-Z(aux));
Ve4 = (X(aux),-Y(aux),-Z(aux));
Ve5 = (-X(aux),Y(aux),-Z(aux));
Ve6 = (-X(aux),-Y(aux),Z(aux));
Ve7 = (-X(aux),-Y(aux),-Z(aux));
pa = rp(Ve0)--rp(Ve1)--rp(Ve6)--rp(Ve2)--cycle;
pb = rp(Ve0)--rp(Ve2)--rp(Ve4)--rp(Ve3)--cycle;
pc = rp(Ve0)--rp(Ve3)--rp(Ve5)--rp(Ve1)--cycle;
pd = rp(Ve7)--rp(Ve4)--rp(Ve2)--rp(Ve6)--cycle;
unfill pa; draw pa;
unfill pb; draw pb;
unfill pc; draw pc;
for k=0 upto Mz:
if kisodd:
jisodd := true;
else:
jisodd := false;
fi;
for j=0 upto My:
if jisodd:
is := 1;
else:
is := 0;
fi;
for i=is step 2 until Mx:
there := c*(i,j,k)+ref;
this := "rigorousfearpath(" & cstr(there);
comm := "unfill " & this & ",0.5);";
comn := "draw " & this & ",0.5);";
getready( comm & comn, there );
endfor;
jisodd := not jisodd;
endfor;
kisodd := not kisodd;
endfor;
doitnow;
unfill pd; draw pd;
endfig;
end;