source: git/Singular/LIB/surf.lib @ 3754ca

spielwiese
Last change on this file since 3754ca was 3754ca, checked in by Frank Seelisch <seelisch@…>, 15 years ago
minor textual changes prior to 3-1-0 git-svn-id: file:///usr/local/Singular/svn/trunk@11714 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.8 KB
Line 
1// last modified 21.07.2005, Oliver Wienand
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: surf.lib,v 1.34 2009-04-15 11:15:56 seelisch Exp $";
4category="Visualization";
5info="
6LIBRARY: surf.lib    Procedures for Graphics with Surf
7AUTHOR: Hans Schoenemann
8
9NOTE:
10 @texinfo
11 Using this library requires the program @code{surf} to be installed.
12 You can download @code{surf} either from
13  @uref{http://sourceforge.net/projects/surf}
14  or from @uref{ftp://www.mathematik.uni-kl.de/pub/Math/Singular/utils/}.
15 The procedure surfer requires the program @code{surfer} to be installed.
16 You can download @code{surfer} from
17  @uref{http://www.imaginary2008.de/surfer.imaginary2008.de}
18 @*Under Windows, version 159 or newer of @code{surfer} is required.
19 @end texinfo
20
21SEE ALSO: surfex_lib
22
23PROCEDURES:
24 plot(I);  plots plane curves and surfaces
25";
26
27///////////////////////////////////////////////////////////////////////////////
28proc num_of_vars(ideal I)
29"USAGE: num_of_vars(ideal I)
30
31RETURN: an intvec containing one entry for each ring variable.
32each contains the sums of all degrees in this variable of all monomials
33occuring in the ideal.
34An entry is zero if and only if the corresponding variable does not occur in the ideal.
35"
36{
37  intvec v;
38  int i;
39  poly p;
40  for(i=ncols(I);i>0;i--)
41  {
42    p=I[i];
43    while(p!=0)
44    {
45      v=v+leadexp(p);
46      p=p-lead(p);
47    }
48  }
49  return(v);
50}
51example
52{
53  "EXAMPLE:"; echo = 2;
54  ring r = 0, (x,y,z),dp;
55  ideal j0 = x^2-x*y;
56  num_of_vars(j0);
57  ideal j1 = x^2-x*y-y;
58  num_of_vars(j1);
59  ideal j2 = x^2-x*y-y, x^3-2*y;
60  num_of_vars(j2);
61}
62
63proc plot(ideal I,list #)
64"USAGE:   plot(I);  I ideal or poly
65ASSUME: I defines a plane curve or a surface given by one equation
66RETURN: nothing
67NOTE: requires the external program 'surf' to be installed,
68      to close the graphical interface just press 'Q'
69EXAMPLE: example plot; shows an example
70"
71{
72  string extra_surf_opts=" -x --auto-resize "; // remove this line for surf 0.9
73  string l = "/tmp/surf"+string(system("pid"));
74  string err_mes; // string containing error messages
75  def base=basering;
76  intvec v=num_of_vars(I);
77  int i,j,n;
78  for(i=size(v);i>0;i--)
79  {
80    if (v[i]!=0) { n++; }
81  }
82  if (n==0 or n>3)
83  {
84    err_mes="Cannot plot equations with "+string(n)+" variables";
85    ERROR(err_mes);
86  }
87  ring r=0,(x,y,z),dp;
88  short=0;
89  map phi=base,0;
90  j=1;
91  for(i=1;i<=size(v);i++)
92  {
93    if (v[i]!=0)
94    {
95      phi[i]=var(j);
96      j++;
97      if(j==4) break;
98    }
99  }
100  ideal I=simplify(phi(I),2);
101  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
102  if (ncols(I)==1 and n<=2 and nvars(base)!=3) // curve
103  {
104    write(":w "+l,"clip=none;");
105      write(l, "width=500; height=500; set_size; do_background=yes;
106background_red=255; background_green=255; background_blue=255;");
107    write(l,
108    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
109    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
110    if (size(#)>0)
111    {
112      write(l,#[1]);
113    }
114    write(l,"curve=",I[1],";");
115    write(l,"draw_curve;");
116  }
117  else
118  {
119    if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
120    {
121      write(":w " + l,
122            "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
123      write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
124      write(l, "rot_x=0.14; rot_y=-0.3;");
125      if (size(#) > 0)
126      {
127          write(l, #[1]);
128      }
129      write(l, "surface=",I[1],";");
130      write(l, "draw_surface;");
131    }
132    else
133    {
134      err_mes = "cannot plot " + string(ncols(I)) + " equations in "
135              + string(n) + " variables";
136      ERROR(err_mes);
137    }
138  }
139  string surf_call;
140  surf_call = "surf ";
141  if (defined(extra_surf_opts))
142  {
143    surf_call = surf_call + " " + extra_surf_opts;
144  }
145  surf_call =surf_call + l + " >/dev/null 2>&1";
146
147  "Press q to exit from 'surf'";
148  if ("ppcMac-darwin" != system("uname"))
149  {
150     i=system("sh", surf_call);
151  }
152  else
153  {
154     surf_call = surf_call + " || " + "singularsurf "
155                 + extra_surf_opts + " " + l +" >/dev/null 2>&1";
156     i = system("sh", surf_call);
157  }
158
159  if (i != 0)
160  {
161    err_mes = "calling `surf` failed. (the shell return the error code "
162          + string(i) + ")." + newline +
163          "probably the executable `surf` is not found.";
164    ERROR(err_mes);
165  }
166  i = system("sh", "/bin/rm "+l);
167}
168example
169{ "EXAMPLE:"; echo = 2;
170  // ---------  plane curves ------------
171  ring rr0 = 0,(x1,x2),dp;
172
173  ideal I = x1^3 - x2^2;
174  plot(I);
175
176  ring rr1 = 0,(x,y,z),dp;
177  ideal I(1) = 2x2-1/2x3 +1-y+1;
178  plot(I(1));
179
180  //  ---- Singular Logo --------------
181  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
182  plot(logo);
183
184  // Steiner surface
185  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
186  plot(J(2));
187
188  // --------------------
189  plot(x*(x2-y2)+z2);
190
191  // E7
192  plot(x^3-x*y^3+z^2);
193
194  // Whitney umbrella
195  plot(z^2-x^2*y);
196
197}
198proc surfer(ideal I)
199"USAGE:   surfer(f);  f poly
200ASSUME: f defines a surface given by one equation
201RETURN: nothing
202NOTE: requires the external program 'surfer' to be installed,
203      to close the graphical interface just close the window of surfer
204EXAMPLE: example surfer; shows an example
205"
206{
207  string l = "/tmp/surf"+string(system("pid"));
208  string err_mes; // string containing error messages
209  def base=basering;
210  intvec v=num_of_vars(I);
211  int i,j,n;
212  for(i=size(v);i>0;i--)
213  {
214    if (v[i]!=0) { n++; }
215  }
216  if (n==0 or n>3)
217  {
218    err_mes="Cannot plot equations with "+string(n)+" variables";
219    ERROR(err_mes);
220  }
221  ring r=0,(x,y,z),dp;
222  short=0;
223  map phi=base,0;
224  j=1;
225  for(i=1;i<=size(v);i++)
226  {
227    if (v[i]!=0)
228    {
229      phi[i]=var(j);
230      j++;
231      if(j==4) break;
232    }
233  }
234  ideal I=simplify(phi(I),2);
235  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
236  if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
237  {
238    write(":w " + l, "surface=",I[1],";");
239  }
240  else
241  {
242    err_mes = "cannot plot " + string(ncols(I)) + " equations in "
243            + string(n) + " variables";
244    ERROR(err_mes);
245  }
246  string surf_call;
247  surf_call ="surfer " + l + " >/dev/null 2>&1";
248
249  "Close window to exit from 'surfer'";
250  i=system("sh", surf_call);
251
252  if (i != 0)
253  {
254    err_mes = "calling `surfer` failed. (the shell return the error code "
255          + string(i) + ")." + newline +
256          "probably the executable `surfer` is not found.";
257    ERROR(err_mes);
258  }
259  i = system("sh", "/bin/rm "+l);
260}
261example
262{ "EXAMPLE:"; echo = 2;
263  ring rr1 = 0,(x,y,z),dp;
264  // Steiner surface
265  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
266  surfer(J(2));
267
268  // --------------------
269  surfer(x*(x2-y2)+z2);
270
271  // E7
272  surfer(x^3-x*y^3+z^2);
273
274  // Whitney umbrella
275  surfer(z^2-x^2*y);
276
277}
278///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.