source: git/Singular/LIB/surf.lib @ 8bb77b

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