Equations.mp
breite:=250; % width
hoehe:=175; % height
n:=4;
b0:=15;
b2:=15;
B:=.25breite;
h0:=10;
h2:=16;
H:=B/sqrt 2;
b1=.2B;
h1=.15H;
b0+B+(n-1)*db+b1+b2=breite; % unknown db is calculated by MetaPost
h0+H+(n-1)*dh+h1+h2=hoehe; % unknown dh is calculated by MetaPost
def draw_rect(expr P, arrow) =
save p, q;
path p, q;
p:=P+.5(-B, -H)--P+.5(+B, -H)--P+.5(+B, +H)--P+.5(-B, +H)--cycle;
q:=P+.5(0, -H)--P+(0, -dh)--P+(db-B/2, -dh);
fill p shifted (b1, -h1) withcolor .8white;
if arrow:
drawarrow q shifted (b1, -h1) withcolor .5white;
fi
unfill p;
draw p;
if arrow:
drawarrow q;
fi
enddef;
beginfig(1)
z0=(b0, hoehe-h2);
for i=1 upto n:
z[i]=(b0+B/2, hoehe-h2-H/2)+(i-1)*(db, -dh);
endfor
z[n+1]=z[n]+.5(B, -H);
z[n+2]=z[n+1]+(b1, -h1);
draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle;
for i=1 upto n:
draw_rect(z[i], in);
endfor
endfig;
beginfig(2)
z0=(b0, hoehe-h2);
for i=1 upto n:
z[i]=(b0+B/2, hoehe-h2-H/2)+(i-1)*(db, -dh);
endfor
z[n+1]=z[n]+.5(B, -H);
z[n+2]=z[n+1]+(b1, -h1);
draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle;
for i=1 upto n:
draw_rect(z[i], in);
endfor
for i=0 upto n+2:
draw (x[i], hoehe)--z[i]--(breite, y[i]) withcolor red;
fill fullcircle scaled 2 shifted z[i] withcolor red;
endfor
for i=0 upto n+2:
if (i=0) or (i=n):
if i=0:
label.top("b0" , (.5[0, x[i]], hoehe-h2));
fi
label.top("B/2" , (.5[x[i], x[i+1]], hoehe-h2-3));
elseif i=n:
label.top("dh" , (.5[x[i], x[i+1]], hoehe-h2));
elseif i=n+1:
label.top("b1" , (.5[x[i], x[i+1]], hoehe-h2));
else:
label.top("b2" , (.5[x[i], breite], hoehe-h2));
fi
endfor
endfig;
end