source: git/Singular/LIB/surf.lib @ d85126

spielwiese
Last change on this file since d85126 was d85126, checked in by Oliver Wienand <wienand@…>, 19 years ago
surf.lib ---> autoresize ---> help string modified git-svn-id: file:///usr/local/Singular/svn/trunk@8439 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.3 KB
Line 
1// last modified 21.07.2005, Oliver Wienand
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: surf.lib,v 1.25 2005-07-21 09:19:42 wienand Exp $";
4category="Visualization";
5info="
6LIBRARY: surf.lib    Procedures for Graphics with Surf
7AUTHOR: Hans Schoenemann,
8        the program surf is written by Stefan Endrass
9
10NOTE:
11 @texinfo
12 To use this library requires the program @code{surf} to be installed.
13 @code{surf} is only available for Linux PCs and Sun workstations.
14 You can download @code{surf} either from
15  @uref{http://sourceforge.net/projects/surf}
16  or from @uref{ftp://www.mathematik.uni-kl.de/pub/Math/Singular/utils/}.
17 @end texinfo
18
19PROCEDURES:
20 plot(I);  plots plane curves and surfaces
21";
22
23///////////////////////////////////////////////////////////////////////////////
24static proc num_of_vars(ideal I)
25{
26  intvec v;
27  int i;
28  poly p;
29  for(i=size(I);i>0;i--)
30  {
31    p=I[i];
32    while(p!=0)
33    {
34      v=v+leadexp(p);
35      p=p-lead(p);
36    }
37  }
38  return(v);
39}
40
41proc plot(ideal I,list #)
42"USAGE:   plot(I);  I ideal or poly
43ASSUME: I defines a plane curve or a surface given by one equation
44RETURN: nothing
45NOTE: requires the external program 'surf' to be installed, to close the graphical just press 'Q'
46EXAMPLE: example plot; shows an example
47"
48{
49  string extra_surf_opts=" -x --auto-resize "; // remove this line for surf 0.9
50  string l = "/tmp/surf"+string(system("pid"));
51  string err_mes; // string containing error messages
52  def base=basering;
53  intvec v=num_of_vars(I);
54  int i,j,n;
55  for(i=size(v);i>0;i--)
56  {
57    if (v[i]!=0) { n++; }
58  }
59  if (n==0 or n>3)
60  {
61    err_mes="Cannot plot equations with "+string(n)+" variables";
62    ERROR(err_mes);
63  }
64  ring r=0,(x,y,z),dp;
65  short=0;
66  map phi=base,0;
67  j=1;
68  for(i=1;i<=size(v);i++)
69  {
70    if (v[i]!=0)
71    {
72      phi[i]=var(j);
73      j++;
74      if(j==4) break;
75    }
76  }
77  ideal I=simplify(phi(I),2);
78  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
79  if (ncols(I)==1 and n<=2 and nvars(base)!=3) // curve
80  {
81    write(":w "+l,"clip=none;");
82      write(l, "width=500; height=500; set_size; do_background=yes;
83background_red=255; background_green=255; background_blue=255;");
84    write(l,
85    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
86    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
87    if (size(#)>0)
88    {
89      write(l,#[1]);
90    }
91    write(l,"curve=",I[1],";");
92    write(l,"draw_curve;");
93  }
94  else
95  {
96    if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
97    {
98      write(":w " + l,
99            "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
100      write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
101      write(l, "rot_x=0.14; rot_y=-0.3;");
102      if (size(#) > 0)
103      {
104          write(l, #[1]);
105      }
106      write(l, "surface=",I[1],";");
107      write(l, "draw_surface;");
108    }
109    else
110    {
111      err_mes = "cannot plot " + string(ncols(I)) + " equations in "
112              + string(n) + " variables";
113      ERROR(err_mes);
114    }
115  }
116  string surf_call;
117  surf_call = "surf ";
118  if (defined(extra_surf_opts))
119  {
120    surf_call = surf_call + " " + extra_surf_opts;
121  }
122  surf_call =surf_call + l + " >/dev/null 2>&1";
123
124  if ("ppcMac-darwin" != system("uname")) {
125     i=system("sh", surf_call);
126  } else {
127     surf_call = surf_call + " || " + "singularsurf "
128                 + extra_surf_opts + " " + l +" >/dev/null 2>&1";
129     i = system("sh", surf_call);
130  }
131
132  if (i != 0)
133  {
134    err_mes = "calling `surf` failed. (the shell return the error code "
135          + string(i) + ")." + newline +
136          "probably the executable `surf` is not found.";
137    ERROR(err_mes);
138  }
139  i = system("sh", "/bin/rm "+l);
140}
141example
142{ "EXAMPLE:"; echo = 2;
143  // ---------  plane curves ------------
144  ring rr0 = 0,(x1,x2),dp;
145
146  ideal I = x1^3 - x2^2;
147  plot(I);
148
149  ring rr1 = 0,(x,y,z),dp;
150  ideal I(1) = 2x2-1/2x3 +1-y+1;
151  plot(I(1));
152
153  //  ---- Singular Logo --------------
154  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
155  plot(logo);
156
157  // Steiner surface
158  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
159  plot(J(2));
160
161  // --------------------
162  plot(x*(x2-y2)+z2);
163
164  // E7
165  plot(x^3-x*y^3+z^2);
166
167  // Whitney umbrella
168  plot(z^2-x^2*y);
169
170}
171///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.