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

spielwiese
Last change on this file since a15d90 was a15d90, checked in by Hans Schönemann <hannes@…>, 18 years ago
*hannes: format, typos in docu git-svn-id: file:///usr/local/Singular/svn/trunk@9317 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.27 2006-07-18 15:53:58 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
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,
46      to close the graphical interface just press 'Q'
47EXAMPLE: example plot; shows an example
48"
49{
50  string extra_surf_opts=" -x --auto-resize "; // remove this line for surf 0.9
51  string l = "/tmp/surf"+string(system("pid"));
52  string err_mes; // string containing error messages
53  def base=basering;
54  intvec v=num_of_vars(I);
55  int i,j,n;
56  for(i=size(v);i>0;i--)
57  {
58    if (v[i]!=0) { n++; }
59  }
60  if (n==0 or n>3)
61  {
62    err_mes="Cannot plot equations with "+string(n)+" variables";
63    ERROR(err_mes);
64  }
65  ring r=0,(x,y,z),dp;
66  short=0;
67  map phi=base,0;
68  j=1;
69  for(i=1;i<=size(v);i++)
70  {
71    if (v[i]!=0)
72    {
73      phi[i]=var(j);
74      j++;
75      if(j==4) break;
76    }
77  }
78  ideal I=simplify(phi(I),2);
79  if (leadcoef(I[1]) <0) { I[1]=-I[1]; }
80  if (ncols(I)==1 and n<=2 and nvars(base)!=3) // curve
81  {
82    write(":w "+l,"clip=none;");
83      write(l, "width=500; height=500; set_size; do_background=yes;
84background_red=255; background_green=255; background_blue=255;");
85    write(l,
86    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
87    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
88    if (size(#)>0)
89    {
90      write(l,#[1]);
91    }
92    write(l,"curve=",I[1],";");
93    write(l,"draw_curve;");
94  }
95  else
96  {
97    if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface
98    {
99      write(":w " + l,
100            "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
101      write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
102      write(l, "rot_x=0.14; rot_y=-0.3;");
103      if (size(#) > 0)
104      {
105          write(l, #[1]);
106      }
107      write(l, "surface=",I[1],";");
108      write(l, "draw_surface;");
109    }
110    else
111    {
112      err_mes = "cannot plot " + string(ncols(I)) + " equations in "
113              + string(n) + " variables";
114      ERROR(err_mes);
115    }
116  }
117  string surf_call;
118  surf_call = "surf ";
119  if (defined(extra_surf_opts))
120  {
121    surf_call = surf_call + " " + extra_surf_opts;
122  }
123  surf_call =surf_call + l + " >/dev/null 2>&1";
124
125  "Press q to exit from 'surf'";
126  if ("ppcMac-darwin" != system("uname")) {
127     i=system("sh", surf_call);
128  } else {
129     surf_call = surf_call + " || " + "singularsurf "
130                 + extra_surf_opts + " " + l +" >/dev/null 2>&1";
131     i = system("sh", surf_call);
132  }
133
134  if (i != 0)
135  {
136    err_mes = "calling `surf` failed. (the shell return the error code "
137          + string(i) + ")." + newline +
138          "probably the executable `surf` is not found.";
139    ERROR(err_mes);
140  }
141  i = system("sh", "/bin/rm "+l);
142}
143example
144{ "EXAMPLE:"; echo = 2;
145  // ---------  plane curves ------------
146  ring rr0 = 0,(x1,x2),dp;
147
148  ideal I = x1^3 - x2^2;
149  plot(I);
150
151  ring rr1 = 0,(x,y,z),dp;
152  ideal I(1) = 2x2-1/2x3 +1-y+1;
153  plot(I(1));
154
155  //  ---- Singular Logo --------------
156  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
157  plot(logo);
158
159  // Steiner surface
160  ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
161  plot(J(2));
162
163  // --------------------
164  plot(x*(x2-y2)+z2);
165
166  // E7
167  plot(x^3-x*y^3+z^2);
168
169  // Whitney umbrella
170  plot(z^2-x^2*y);
171
172}
173///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.