source: git/Singular/LIB/surf.lib @ 238c959

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