source: git/Singular/LIB/surf.lib @ 05d2e8

fieker-DuValspielwiese
Last change on this file since 05d2e8 was 05d2e8, checked in by Hans Schönemann <hannes@…>, 23 years ago
*keilen: add. arguments to surf git-svn-id: file:///usr/local/Singular/svn/trunk@5039 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.3 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2version="$Id: surf.lib,v 1.16 2001-01-10 15:40:19 Singular 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,list #)
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;
77background_red=255; background_green=255; background_blue=255;");
78    write(l,
79    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
80    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
81    if (size(#)>0)
82    {
83      write(l,#[1]);
84    }
85    write(l,"curve=",I[1],";");
86    write(l,"draw_curve;");
87  }
88  else
89  {
90    if (ncols(I)==1 and n==3) // surface
91    {
92      write(":w "+l,
93      "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
94     write(l, "width=500; height=500; set_size; do_background=yes;
95background_red=255; background_green=255; background_blue=255;");
96      write(l,"rot_x=0.14; rot_y=-0.3;");
97     if (size(#)>0)
98       {   
99         write(l,#[1]);
100       }
101      write(l,"surface=",I[1],";");
102      write(l,"draw_surface;");
103    }
104    else
105    {
106      ERROR("cannot plot"+string(ncols(I))+"equations in"
107             +string(n)+"variables");
108    }
109  }
110  string surf_call = "surf ";
111  if (defined(extra_surf_opts))
112  {
113    surf_call = surf_call + extra_surf_opts + " ";
114  }
115//  "calling surf (by Stephan Endrass) for drawing";
116  i=system("sh",surf_call + l +" >/dev/null 2>&1");
117  if (i!=0)
118  {
119    ERROR("calling `surf` failed. (the shell return the error code"
120          +string(i)+")."+newline+
121    "probably the executable `surf` is not found.");
122  }
123  i=system("sh","/bin/rm "+l);
124}
125example
126{ "EXAMPLE:"; echo =2;
127   // ---------  plane curves ------------
128   ring rr0 = 0,(x1,x2),dp;
129
130   ideal I = x1^3 - x2^2;
131   plot(I);
132   ideal J = x1^2-x1-x2^3;
133   plot(J);
134
135   ring rr1 = 0,(x,y,z),dp;
136   ideal I(1) = 2x2-1/2x3 +1-y+1;
137   plot(I(1));
138   ideal I(2) = x3-x-y;
139   plot(I(2));
140
141  //  ---- Singular Logo --------------
142  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
143  plot(logo);
144
145
146   // --------- implicit curves ------------
147   // implicit curves
148   ideal I(1) = y,-x2;
149   plot(I(1));
150   ideal I(2) = x2,-y2 +4;
151   plot(I(2));
152
153   //the lemniscate
154
155   ideal I(3) = x4+2x2y2 + y4, x2-y2;
156   plot(I(3));
157
158   // a critical part
159   // adjust the plotregion properly to get a good picture
160
161   poly f = (x-y)*(x2+y);
162   plot(f,1);
163   ideal J = jacob(f);
164   J;
165   plot(J);     // bad resolution
166
167   // ----------- surfaces -------------------
168   ideal J(1) = 3xy4 + 2xy2, x5y3 + x + y6,10x2;
169   plot(J(1));
170
171   // Steiner surface
172
173   ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
174   plot(J(2));
175
176  plot(x*(x2-y2)+z2);
177
178  // E7
179  plot(x^3-x*y^3+z^2);
180
181  // Whitney umbrella
182  plot(z^2-x^2*y);
183
184  // A1
185  plot(y2-xz);
186
187
188}
189///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.