Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/hexagonalgrid.mp

raw
1 % hexagonalgrid.mp
2 % L. Nobre G.
3 % 2014
4
5 verbatimtex \documentclass{article}\begin{document} etex
6
7 prologues := 3;
8
9 input graph;
10
11 beginfig(1);
12 numeric u, vertlim, horilim, dotsiz, inistep, mininistep, maxinistep;
13 numeric securitymargin;
14 u = 1.01cm;
15 vertlim = 30u;
16 horilim = vertlim/sqrt(2);
17 dotsiz = 0.3u;
18 mininistep = 4.867u;
19 maxinistep = 4.868u;
20 inistep = 0.5*(mininistep+maxinistep);
21 securitymargin = 4u;
22 pair upperleft, horizrigh;
23 upperleft = (-15u,45u)+45u*dir(135);
24 horizrigh = (35u,vertlim);
25 pen defpen;
26 defpen = pencircle scaled dotsiz;
27 numeric i, j, Num;
28 Num = 150;
29 j = 0;
30 for i=mininistep step (maxinistep-mininistep)/Num until maxinistep:
31 pair Dh[]v[];
32 Dh0v0 = (0,vertlim);
33 Dh0v1 = (0,vertlim-i);
34 numeric indh;
35 indh = 0;
36 forever:
37 Dh[indh+1]v1 = whatever[upperleft,Dh[indh]v0];
38 Dh[indh+1]v1 = whatever[horizrigh,Dh[indh]v1];
39 xpart Dh[indh+1]v0 = xpart Dh[indh+1]v1;
40 Dh[indh+1]v0 = whatever[horizrigh,Dh[indh]v0];
41 exitif xpart Dh[indh+1]v0 > horilim;
42 indh := indh + 1;
43 endfor;
44 z[j] = (i,xpart Dh[indh+1]v0 - horilim)/u;
45 j := j + 1;
46 endfor;
47 path thecurve;
48 picture theplus;
49 theplus = btex $+$ etex;
50 theplus := theplus shifted -(center theplus);
51 thecurve = z0 for i=1 upto j-1: --z[i] endfor;
52 picture thegraph;
53 thegraph = begingraph(9u,6u);
54 glabel.bot( btex inistep/u etex, OUT );
55 glabel.lft( btex deviation/u etex, OUT );
56 gdraw thecurve withpen defpen withcolor blue;
57 gdraw thecurve plot theplus;
58 autogrid(grid.bot,grid.lft) withcolor red dashed evenly;
59 endgraph;
60 draw thegraph;
61 endfig;
62
63 beginfig(2);
64 pair Dh[]v[];
65 Dh0v0 = (0,vertlim);
66 Dh0v1 = (0,vertlim-inistep);
67 drawoptions( withpen defpen );
68 draw Dh0v0;
69 draw Dh0v1;
70 numeric indh, indv, maxindv[];
71 indh = 0;
72 indv = 2;
73 forever:
74 Dh[indh+1]v[indv-1] = whatever[upperleft,Dh[indh]v[indv-2]];
75 Dh[indh+1]v[indv-1] = whatever[horizrigh,Dh[indh]v[indv-1]];
76 draw Dh[indh+1]v[indv-1];
77 forever:
78 xpart Dh[indh+1]v[indv-1] = xpart Dh[indh+1]v[indv];
79 Dh[indh+1]v[indv] = whatever[upperleft,Dh[indh]v[indv-1]];
80 draw Dh[indh+1]v[indv];
81 xpart Dh[indh]v[indv] = xpart Dh[indh]v[indv-1];
82 Dh[indh]v[indv] = whatever[horizrigh,Dh[indh+1]v[indv]];
83 draw Dh[indh]v[indv];
84 exitif ypart Dh[indh]v[indv] < -securitymargin;
85 indv := indv + 1;
86 endfor;
87 maxindv[indh] = indv;
88 xpart Dh[indh+1]v0 = xpart Dh[indh+1]v1;
89 Dh[indh+1]v0 = whatever[horizrigh,Dh[indh]v0];
90 draw Dh[indh+1]v0;
91 show xpart Dh[indh+1]v0 - xpart Dh[indh]v0;
92 exitif xpart Dh[indh+1]v0 > horilim+securitymargin;
93 indh := indh + 1;
94 indv := 2;
95 Dh[indh+1]v[indv-1] = whatever[upperleft,Dh[indh]v[indv-2]];
96 Dh[indh+1]v[indv-1] = whatever[horizrigh,Dh[indh]v[indv-1]];
97 draw Dh[indh+1]v[indv-1];
98 xpart Dh[indh+1]v0 = xpart Dh[indh+1]v1;
99 show xpart Dh[indh+1]v0 - xpart Dh[indh]v0;
100 Dh[indh+1]v0 = whatever[horizrigh,Dh[indh]v0];
101 draw Dh[indh+1]v0;
102 indh := indh + 1;
103 endfor;
104 drawoptions();
105 for i=2 step 2 until indh+1:
106 for j=0 upto maxindv[i-2]-1:
107 draw Dh[i]v[j+1]--Dh[i-1]v[j]--Dh[i]v[j]--cycle;
108 draw Dh[i-1]v[j+1]--Dh[i-2]v[j]--Dh[i-1]v[j]--cycle;
109 endfor;
110 endfor;
111 path borde, bordf;
112 borde = (-dotsiz,-dotsiz)
113 --(-dotsiz,vertlim+dotsiz)
114 --(horilim+dotsiz,vertlim+dotsiz)
115 --(horilim+dotsiz,-dotsiz)--cycle;
116 bordf = origin--(0,vertlim)--(horilim,vertlim)--(horilim,0)--cycle;
117 clip currentpicture to bordf;
118 draw bordf;
119 picture lasercutprofile;
120 lasercutprofile = currentpicture;
121 draw borde;
122 %draw upperleft withpen defpen;
123 %draw horizrigh withpen defpen;
124 endfig;
125
126 beginfig(3);
127 draw lasercutprofile withpen pencircle scaled 0 withcolor red;
128 endfig;
129
130 verbatimtex \end{document} etex
131
132 end.