Debian Codegraph @

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

raw
1 % J. Schwaiger with help of
2 % FEATPOST and the macropackages
3 % la3Dmacros.mp and hlr3Dmacros.mp
4 % by L. Nobre G.
5 % 2003
6
7 % Figure (2) retouched in 2004 by L. Nobre G.
8
9 input featpost3Dplus2D;
10
11 verbatimtex
12 \documentclass[a4paper,12pt]{article}
13 \usepackage[T1]{fontenc}
14 \usepackage[latin1]{inputenc}
15 \usepackage{euler}
16 \usepackage{graphicx}
17 \begin{document}
18 etex
19
20 % for trigonometric functions when angles are measured in rad
21 %
22 def sinrad( expr t)=sind(t/3.145*180) enddef;
23 def cosrad( expr t)=cosd(t/3.145*180) enddef;
24
25 def parsurface( expr tc,sc )=
26 (%
27 (4 cosrad(tc) - sinrad(sc)*cosrad(tc),%
28 4 sinrad(tc) - sinrad(sc)*sinrad(tc),%
29 cosrad(sc))%
30 )% A torus
31 enddef;
32
33 def parsurfacetwo( expr tc,sc )=
34 (%
35 (4+4cosrad(tc) - sinrad(sc)*cosrad(tc),%
36 cosrad(sc),
37 4sinrad(tc) - sinrad(sc)*sinrad(tc)%
38 )%
39 )% Another torus
40 enddef;
41
42 def parsurfacethree( expr tc,sc )=
43 % 0<=sc<=2pi,-2<=tc<=2
44 %xmin=-1.4, xmax=1.4
45 %ymin=-0.7, ymax=2
46 %zmin=-2.5,zmax=2.5
47 (%
48 (1.414213562*cosrad(sc)*cosrad(tc)
49 -2*sinrad(sc)*sinrad(tc))/(2*(abs(tc) + 1)) + sinrad(tc),%
50 cosrad(tc) - (1.414213562*cosrad(sc)*sinrad(tc)
51 + 2*sinrad(sc)*cosrad(tc))/(2*(abs(tc) + 1)),%
52 tc - 2*cosrad(sc)/(2*(abs(tc) + 1))
53 )%
54 % A space tube governed by a helix
55 enddef;
56
57 def zsurface( expr xc, yc ) =
58 ( xc, yc, cosd(xc*57)*cosd(yc*57)+4*mexp(-(xc**2+yc**2)*6.4) )
59 enddef;
60
61 f:=(8,1.5,1.5);
62 Spread := 127;
63
64
65 beginfig(1);
66 numeric Ns, Nt, lows, higs, lowt, higt, lowx, highx, lowy, highy,
67 facz, lowz, higz, base, topo;
68 path chair;
69 % for torus
70 f:=(4,1.5,1.5);
71 Spread:=150;
72 Ns = 16;
73 Nt= 16;
74 lows := 3.145*0.25;
75 higs := 3.145*1.75;
76 lowt = -3.145;
77 higt = 3.145;
78 facz=1;
79 lowz = -5;
80 higz = 5;
81 lowx:=-5;
82 lowy:=-5;
83 higx:=10;
84 higy:=7;
85 %
86 NF:=0; %Initialize number of faces;
87 %
88 partrimesh( Ns,Nt,lowt,higt,lows,higs,
89 lowx,higx,lowy,higy,lowz,higz,facz,parsurfacetwo );
90 lows := 3.145*0.5;
91 higs := 2.25*3.145; % new parameters and new surface
92 partrimesh( Ns,Nt,lowt,higt,lows,higs,
93 lowx,higx,lowy,higy,lowz,higz,facz,parsurface );
94 base = -1/facz;
95 topo = 1/facz;
96 chair = rp((-1,-1,base))--rp((1,-1,base))--rp((1,1,base))
97 --rp((-1,1,base))--rp((-1,-1,base))--rp((-1,-1,topo))
98 --rp((-1,1,topo))--rp((-1,1,base))--cycle;
99 draw_invisible( false,true,(blue+0.5green),0.6white);
100 draw bbox currentpicture;
101 endfig;
102
103 beginfig(2);
104 numeric Ns, Nt, lows, higs, lowt, higt, lowx, highx, lowy, highy,
105 facz, lowz, higz, base, topo;
106 path chair;
107
108 f := (6,0.5,3);
109 Spread:=150;
110
111 Ns = 19;
112 Nt= 19;
113 lows := -3.145;
114 higs := 3.145;
115 lowt = -3.145;
116 higt = 3.145;
117 facz = 2;
118 lowz = -2;
119 higz = 2;
120 lowx:=-5;
121 lowy:=-5;
122 higx:=5;
123 higy:=5;
124 NF:=0; %Initialize number of faces;
125 %
126 partrimesh( Ns,Nt,lowt,higt,lows,higs,
127 lowx,higx,lowy,higy,lowz,higz,facz,parsurface );
128
129 nx := 27;
130 lowy := -7;
131 higy := 7;
132 lowx := -7;
133 higx := 7;
134 facz := 2;
135 lowz := -1;
136 higz := 5;
137 partrimesh( nx,nx,lowx,higx,lowy,higy,
138 lowx,higx,lowy,higy,lowz,higz,facz,zsurface);
139 base = -1/facz;
140 topo = 1/facz;
141 chair = rp((-1,-1,base))--rp((1,-1,base))--rp((1,1,base))
142 --rp((-1,1,base))--rp((-1,-1,base))--rp((-1,-1,topo))
143 --rp((-1,1,topo))--rp((-1,1,base))--cycle;
144 fill chair withcolor 0.9 blue+0.6white;
145 draw chair withcolor 0.1white ;
146 draw_invisible( false,false,(red+0.32blue),0.6white);
147 endfig;
148
149 verbatimtex \end{document} etex
150
151 end;