1 | //last change: 02.03.2001 (Eric Westenberger) |
---|
2 | /////////////////////////////////////////////////////////////////////////////// |
---|
3 | version="$Id: surf.lib,v 1.21 2002-07-17 08:49:08 keilen Exp $"; |
---|
4 | category="Visualization"; |
---|
5 | info=" |
---|
6 | LIBRARY: surf.lib Procedures for Graphics with Surf |
---|
7 | AUTHOR: Hans Schoenemann, |
---|
8 | the program surf is written by Stefan Endrass |
---|
9 | |
---|
10 | NOTE: |
---|
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 | |
---|
19 | PROCEDURES: |
---|
20 | plot(I); plots plane curves and surfaces |
---|
21 | "; |
---|
22 | |
---|
23 | /////////////////////////////////////////////////////////////////////////////// |
---|
24 | static 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 | |
---|
41 | proc plot(ideal I,list #) |
---|
42 | "USAGE: plot(I); I ideal or poly |
---|
43 | ASSUME: I defines a plane curve or a surface given by one equation |
---|
44 | RETURN: nothing |
---|
45 | NOTE: requires the external program 'surf' to be installed |
---|
46 | EXAMPLE: example plot; shows an example |
---|
47 | " |
---|
48 | { |
---|
49 | string extra_surf_opts=" -x "; // remove this line for surf 0.9 |
---|
50 | string l="/tmp/surf"+string(system("pid")); |
---|
51 | string err_mes; // string containing error messages |
---|
52 | def base=basering; |
---|
53 | intvec v=num_of_vars(I); |
---|
54 | int i,j,n; |
---|
55 | for(i=size(v);i>0;i--) |
---|
56 | { |
---|
57 | if (v[i]!=0) { n++; } |
---|
58 | } |
---|
59 | if (n==0 or n>3) |
---|
60 | { |
---|
61 | err_mes="Cannot plot equations with "+string(n)+" variables"; |
---|
62 | ERROR(err_mes); |
---|
63 | } |
---|
64 | ring r=0,(x,y,z),dp; |
---|
65 | short=0; |
---|
66 | map phi=base,0; |
---|
67 | j=1; |
---|
68 | for(i=1;i<=size(v);i++) |
---|
69 | { |
---|
70 | if (v[i]!=0) |
---|
71 | { |
---|
72 | phi[i]=var(j); |
---|
73 | j++; |
---|
74 | if(j==4) break; |
---|
75 | } |
---|
76 | } |
---|
77 | ideal I=simplify(phi(I),2); |
---|
78 | if (leadcoef(I[1]) <0) { I[1]=-I[1]; } |
---|
79 | if (ncols(I)==1 and n<=2 and nvars(base)!=3) // curve |
---|
80 | { |
---|
81 | write(":w "+l,"clip=none;"); |
---|
82 | write(l, "width=500; height=500; set_size; do_background=yes; |
---|
83 | background_red=255; background_green=255; background_blue=255;"); |
---|
84 | write(l, |
---|
85 | "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;"); |
---|
86 | write(l, "curve_green=0; curve_blue=0; curve_width=1.5;"); |
---|
87 | if (size(#)>0) |
---|
88 | { |
---|
89 | write(l,#[1]); |
---|
90 | } |
---|
91 | write(l,"curve=",I[1],";"); |
---|
92 | write(l,"draw_curve;"); |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | if (ncols(I)==1 and (n==3 or nvars(base)==3)) // surface |
---|
97 | { |
---|
98 | write(":w "+l, |
---|
99 | "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;"); |
---|
100 | write(l, "width=500; height=500; set_size; do_background=yes; |
---|
101 | background_red=255; background_green=255; background_blue=255;"); |
---|
102 | write(l,"rot_x=0.14; rot_y=-0.3;"); |
---|
103 | if (size(#)>0) |
---|
104 | { |
---|
105 | write(l,#[1]); |
---|
106 | } |
---|
107 | write(l,"surface=",I[1],";"); |
---|
108 | write(l,"draw_surface;"); |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | err_mes="cannot plot "+string(ncols(I))+" equations in " |
---|
113 | +string(n)+" variables"; |
---|
114 | ERROR(err_mes); |
---|
115 | } |
---|
116 | } |
---|
117 | string surf_call = "surf "; |
---|
118 | if (defined(extra_surf_opts)) |
---|
119 | { |
---|
120 | surf_call = surf_call + extra_surf_opts + " "; |
---|
121 | } |
---|
122 | // "calling surf (by Stephan Endrass) for drawing"; |
---|
123 | i=system("sh",surf_call + l +" >/dev/null 2>&1"); |
---|
124 | if (i!=0) |
---|
125 | { |
---|
126 | err_mes = "calling `surf` failed. (the shell return the error code " |
---|
127 | +string(i)+")."+newline+ |
---|
128 | "probably the executable `surf` is not found."; |
---|
129 | ERROR(err_mes); |
---|
130 | } |
---|
131 | i=system("sh","/bin/rm "+l); |
---|
132 | } |
---|
133 | example |
---|
134 | { "EXAMPLE:"; echo =2; |
---|
135 | // --------- plane curves ------------ |
---|
136 | ring rr0 = 0,(x1,x2),dp; |
---|
137 | |
---|
138 | ideal I = x1^3 - x2^2; |
---|
139 | plot(I); |
---|
140 | |
---|
141 | ring rr1 = 0,(x,y,z),dp; |
---|
142 | ideal I(1) = 2x2-1/2x3 +1-y+1; |
---|
143 | plot(I(1)); |
---|
144 | |
---|
145 | // ---- Singular Logo -------------- |
---|
146 | poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2); |
---|
147 | plot(logo); |
---|
148 | |
---|
149 | // Steiner surface |
---|
150 | ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z; |
---|
151 | plot(J(2)); |
---|
152 | |
---|
153 | // -------------------- |
---|
154 | plot(x*(x2-y2)+z2); |
---|
155 | |
---|
156 | // E7 |
---|
157 | plot(x^3-x*y^3+z^2); |
---|
158 | |
---|
159 | // Whitney umbrella |
---|
160 | plot(z^2-x^2*y); |
---|
161 | |
---|
162 | } |
---|
163 | /////////////////////////////////////////////////////////////////////////////// |
---|