1/* -*-ePiX-*- */
2#include "epix.h"
3using namespace ePiX;
4
5// Style parameters
6const int MESH(12); // number of coordinate grid squares
7const int MAX(3); // maximum coordinate
8
9// camera location (in spherical coordinates); must be in first orthant
10const P VIEWPT(sph(4*MAX, M_PI/6, M_PI/6));
11
12const double sqrt3(sqrt(3));
13
14// function to be graphed
15P f(double x, double y)
16{
17  //  return P(x, y, 0.75*y*(y-sqrt3*x)*(y+sqrt3*x));
18  return P(x,y, 0.9*MAX*exp(-0.5*(x*x+y*y))*x*y);
19  //  return P(x, y, 0.25*(x-y*y)*(x-3*y*y));
20}
21
22P color(double u, double v, double w)
23{
24  return P(-0.5*w, 0.25*w, 0.5*w);
25}
26
27Color Bk(Green(0.7));
28
29int main()
30{
31  // picture(P(-2*MAX,-2*MAX), P(2*MAX,2*MAX), "6 x 6in");
32  picture(P(-MAX,-MAX), P(MAX,MAX), "6 x 6in");
33
34  begin();
35  backing(Bk);
36
37  camera.at(0,-10,4);
38
39  border(Green(0.6), "1pt");
40
41  clip_box(P(MAX,MAX,MAX));
42
43  domain R(P(-MAX,-MAX), P(MAX, MAX), (6*MESH, 6*MESH), mesh(6*MESH, 6*MESH));
44
45  legend L1, L2, L3;
46  L1.backing(Bk);
47  L2.backing(Bk);
48  L3.backing(Bk);
49
50  //  pen(RGB(1, 0.8, 0.2), 0.1);
51  for (int i=-10; i <=10; ++i)
52    {
53      clip_slice(P(0,0,0.1*i), P(0,0,1), 0.1);
54      // fill(RGB(0.25+0.1*i, 0, -0.1*i));
55      rgb(0.25+0.1*i, 0, -0.1*i);
56
57      std::stringstream buf;
58      buf << "$" << 0.1*i - 0.05
59	  << "\\leq z \\leq " << 0.1*i + 0.05 << "$";
60
61      if (i <-3)
62	L1.fill_item(buf.str());
63
64      else if(i<4)
65	L2.fill_item(buf.str());
66
67      else
68	L3.fill_item(buf.str());
69
70      nofill();
71      surface(f, R);
72      clip_restore();
73    }
74
75  camera.at(0,0,1000);
76  font_size("scriptsize");
77  label_color(Black());
78  L1.border(0);
79  L2.border(0);
80  L3.border(0);
81
82  L1.draw(canvas().bl(), P(2,2), tr);
83  L2.draw(canvas().bl()+P(2,0), P(2,2), tr);
84  L3.draw(canvas().bl()+P(4,0), P(2,2), tr);
85
86  pst_format();
87  end();
88}
89
90