source: git/Singular/LIB/surf.lib @ 509d4c

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