source: git/Singular/LIB/surf.lib @ 131a579

fieker-DuValspielwiese
Last change on this file since 131a579 was 131a579, checked in by Olaf Bachmann <obachman@…>, 24 years ago
Some of GMG's changes git-svn-id: file:///usr/local/Singular/svn/trunk@4003 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.9 KB
Line 
1// $Id: surf.lib,v 1.7 1999-12-10 16:43:34 obachman Exp $
2//
3// author : Hans Schoenemann
4//
5///////////////////////////////////////////////////////////////////////////////
6version="$Id: surf.lib,v 1.7 1999-12-10 16:43:34 obachman 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://www.mathematik.uni-mainz.de/AlgebraischeGeometrie/surf/surf.shtml}
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    "Cannot plot equations with", n, "variables";
61    return();
62  }
63  ring r=0,(x,y,z),dp;
64  short=0;
65  map phi=base,0;
66  j=1;
67  for(i=1;i<=size(v);i++)
68  {
69    if (v[i]!=0)
70    {
71      phi[i]=var(j);
72      j++;
73      if(j==4) break;
74    }
75  }
76  ideal I=simplify(phi(I),2);
77  if (ncols(I)==1 and n<=2) // curve
78  {
79    write(":w "+l,"clip=none;");
80      write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
81    write(l,
82    "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
83    write(l, "curve_green=0; curve_blue=0; curve_width=1.5;");
84    write(l,"curve=",I[1],";");
85    write(l,"draw_curve;");
86  }
87  else
88  {
89    if (ncols(I)==1 and n==3) // surface
90    {
91      write(":w "+l,
92      "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
93     write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;");
94      write(l,"rot_x=0.14; rot_y=-0.3;");
95      write(l,"surface=",I[1],";");
96      write(l,"draw_surface;");
97    }
98    else
99    {
100      "cannot plot",ncols(I),"equations in",n,"variables";
101      return();
102    }
103  }
104//  "calling surf (by Stephan Endrass) for drawing";
105  i=system("sh","surf "+l+" >/dev/null 2>&1");
106  i=system("sh","/bin/rm "+l);
107}
108example
109{ "EXAMPLE:"; echo =2;
110   // ---------  plane curves ------------
111   ring rr0 = 0,(x1,x2),dp;
112
113   ideal I = x1^3 - x2^2;
114   plot(I);
115   ideal J = x1^2-x1-x2^3;
116   plot(J);
117
118   ring rr1 = 0,(x,y,z),dp;
119   ideal I(1) = 2x2-1/2x3 +1-y+1;
120   plot(I(1));
121   ideal I(2) = x3-x-y;
122   plot(I(2));
123
124  //  ---- Singular Logo --------------
125  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
126  plot(logo);
127
128
129   // --------- implicit curves ------------
130   // implicit curves
131   ideal I(1) = y,-x2;
132   plot(I(1));
133   ideal I(2) = x2,-y2 +4;
134   plot(I(2));
135
136   //the lemniscate
137
138   ideal I(3) = x4+2x2y2 + y4, x2-y2;
139   plot(I(3));
140
141   // a critical part
142   // adjust the plotregion properly to get a good picture
143
144   poly f = (x-y)*(x2+y);
145   plot(f,1);
146   ideal J = jacob(f);
147   J;
148   plot(J);     // bad resolution
149
150   // ----------- surfaces -------------------
151   ideal J(1) = 3xy4 + 2xy2, x5y3 + x + y6,10x2;
152   plot(J(1));
153
154   // Steiner surface
155
156   ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
157   plot(J(2));
158
159  plot(x*(x2-y2)+z2);
160
161  // E7
162  plot(x^3-x*y^3+z^2);
163
164  // Whitney umbrella
165  plot(z^2-x^2*y);
166
167  // A1
168  plot(y2-xz);
169
170
171}
172///////////////////////////////////////////////////////////////////////////////
173
174
Note: See TracBrowser for help on using the repository browser.