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

spielwiese
Last change on this file since 9173792 was 9173792, checked in by Christoph Lossen <lossen@…>, 23 years ago
* westenb: help strings edited, typos corrected git-svn-id: file:///usr/local/Singular/svn/trunk@5244 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.1 KB
Line 
1//last change: 13.02.2001 (Eric Westenberger)
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: surf.lib,v 1.18 2001-02-19 14:17:49 lossen 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 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
43ASSUME: I involves only 2 or 3 variables
44RETURN: nothing
45NOTE: requires the external program 'surf' to be installed
46EXAMPLE: example plot; shows an example
47"
48{
49  string l="/tmp/surf"+string(system("pid"));
50  def base=basering;
51  intvec v=num_of_vars(I);
52  int i,j,n;
53  for(i=size(v);i>0;i--)
54  {
55    if (v[i]!=0) { n++; }
56  }
57  if (n==0 or n>3)
58  {
59    string err_mes="Cannot plot equations with "+string(n)+" variables";
60    ERROR(err_mes);
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;
80background_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    if (size(#)>0)
85    {
86      write(l,#[1]);
87    }
88    write(l,"curve=",I[1],";");
89    write(l,"draw_curve;");
90  }
91  else
92  {
93    if (ncols(I)==1 and n==3) // surface
94    {
95      write(":w "+l,
96      "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;");
97     write(l, "width=500; height=500; set_size; do_background=yes;
98background_red=255; background_green=255; background_blue=255;");
99      write(l,"rot_x=0.14; rot_y=-0.3;");
100     if (size(#)>0)
101       {
102         write(l,#[1]);
103       }
104      write(l,"surface=",I[1],";");
105      write(l,"draw_surface;");
106    }
107    else
108    {
109      ERROR("cannot plot"+string(ncols(I))+"equations in"
110             +string(n)+"variables");
111    }
112  }
113  string surf_call = "surf ";
114  if (defined(extra_surf_opts))
115  {
116    surf_call = surf_call + extra_surf_opts + " ";
117  }
118//  "calling surf (by Stephan Endrass) for drawing";
119  i=system("sh",surf_call + l +" >/dev/null 2>&1");
120  if (i!=0)
121  {
122    ERROR("calling `surf` failed. (the shell return the error code"
123          +string(i)+")."+newline+
124    "probably the executable `surf` is not found.");
125  }
126  i=system("sh","/bin/rm "+l);
127}
128example
129{ "EXAMPLE:"; echo =2;
130   // ---------  plane curves ------------
131   ring rr0 = 0,(x1,x2),dp;
132
133   ideal I = x1^3 - x2^2;
134   plot(I);
135
136   ring rr1 = 0,(x,y,z),dp;
137   ideal I(1) = 2x2-1/2x3 +1-y+1;
138   plot(I(1));
139
140  //  ---- Singular Logo --------------
141  poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2);
142  plot(logo);
143
144   // --------- implicit curves ------------
145   // implicit curves
146   ideal I(1) = y,-x2;
147   plot(I(1));
148   ideal I(2) = x2,-y2 +4;
149   plot(I(2));
150
151   //the lemniscate
152
153   ideal I(3) = x4+2x2y2 + y4, x2-y2;
154   plot(I(3));
155
156   // ----------- surfaces -------------------
157   ideal J(1) = 3xy4 + 2xy2, x5y3 + x + y6,10x2;
158   plot(J(1));
159
160   // Steiner surface
161
162   ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z;
163   plot(J(2));
164
165  plot(x*(x2-y2)+z2);
166
167  // E7
168  plot(x^3-x*y^3+z^2);
169
170  // Whitney umbrella
171  plot(z^2-x^2*y);
172
173}
174///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.