1 | // $Id: surf.lib,v 1.4 1999-07-06 11:33:16 obachman Exp $ |
---|
2 | // |
---|
3 | // author : Hans Schoenemann |
---|
4 | // |
---|
5 | /////////////////////////////////////////////////////////////////////////////// |
---|
6 | version="$Id: surf.lib,v 1.4 1999-07-06 11:33:16 obachman Exp $"; |
---|
7 | info=" |
---|
8 | LIBRARY: surf.lib PROCEDURES FOR GRAPHICS WITH SURF (by Stephan Endrass) |
---|
9 | |
---|
10 | PROCEDURES: |
---|
11 | plot(I); plots curves and surfaces |
---|
12 | "; |
---|
13 | |
---|
14 | /////////////////////////////////////////////////////////////////////////////// |
---|
15 | static proc num_of_vars(ideal I) |
---|
16 | { |
---|
17 | intvec v; |
---|
18 | int i; |
---|
19 | poly p; |
---|
20 | for(i=size(I);i>0;i--) |
---|
21 | { |
---|
22 | p=I[i]; |
---|
23 | while(p!=0) |
---|
24 | { |
---|
25 | v=v+leadexp(p); |
---|
26 | p=p-lead(p); |
---|
27 | } |
---|
28 | } |
---|
29 | return(v); |
---|
30 | } |
---|
31 | |
---|
32 | proc plot(ideal I) |
---|
33 | "USAGE: plot(I); I ideal |
---|
34 | RETURN: |
---|
35 | NOTE: |
---|
36 | EXAMPLE: example plot; shows an example |
---|
37 | " |
---|
38 | { |
---|
39 | string l="/tmp/surf"+string(system("pid")); |
---|
40 | def base=basering; |
---|
41 | intvec v=num_of_vars(I); |
---|
42 | int i,j,n; |
---|
43 | for(i=size(v);i>0;i--) |
---|
44 | { |
---|
45 | if (v[i]!=0) { n++; } |
---|
46 | } |
---|
47 | if (n==0 or n>3) |
---|
48 | { |
---|
49 | "Cannot plot equations with", n, "variables"; |
---|
50 | return(); |
---|
51 | } |
---|
52 | ring r=0,(x,y,z),dp; |
---|
53 | short=0; |
---|
54 | map phi=base,0; |
---|
55 | j=1; |
---|
56 | for(i=1;i<=size(v);i++) |
---|
57 | { |
---|
58 | if (v[i]!=0) |
---|
59 | { |
---|
60 | phi[i]=var(j); |
---|
61 | j++; |
---|
62 | if(j==4) break; |
---|
63 | } |
---|
64 | } |
---|
65 | ideal I=simplify(phi(I),2); |
---|
66 | if (ncols(I)==1 and n<=2) // curve |
---|
67 | { |
---|
68 | write(":w "+l,"clip=none;"); |
---|
69 | write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;"); |
---|
70 | write(l, |
---|
71 | "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;"); |
---|
72 | write(l, "curve_green=0; curve_blue=0; curve_width=4.5;"); |
---|
73 | write(l,"curve=",I[1],";"); |
---|
74 | write(l,"draw_curve;"); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | if (ncols(I)==1 and n==3) // surface |
---|
79 | { |
---|
80 | write(":w "+l, |
---|
81 | "root_finder=d_chain_bisection;epsilon=0.0000000001;iterations=20000;"); |
---|
82 | write(l, "width=500; height=500; set_size; do_background=yes; background_red=255; background_green=255; background_blue=255;"); |
---|
83 | write(l,"rot_x=0.14; rot_y=-0.3;"); |
---|
84 | write(l,"surface=",I[1],";"); |
---|
85 | write(l,"draw_surface;"); |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | "cannot plot",ncols(I),"equations in",n,"variables"; |
---|
90 | return(); |
---|
91 | } |
---|
92 | } |
---|
93 | // "calling surf (by Stephan Endrass) for drawing"; |
---|
94 | i=system("sh","surf "+l+" >/dev/null 2>&1"); |
---|
95 | i=system("sh","/bin/rm "+l); |
---|
96 | } |
---|
97 | example |
---|
98 | { "EXAMPLE:"; echo =2; |
---|
99 | // --------- plane curves ------------ |
---|
100 | ring rr0 = 0,(x1,x2),dp; |
---|
101 | |
---|
102 | ideal I = x1^3 - x2^2; |
---|
103 | plot(I); |
---|
104 | ideal J = x1^2-x1-x2^3; |
---|
105 | plot(J); |
---|
106 | |
---|
107 | ring rr1 = 0,(x,y,z),dp; |
---|
108 | ideal I(1) = 2x2-1/2x3 +1-y+1; |
---|
109 | plot(I(1)); |
---|
110 | ideal I(2) = x3-x-y; |
---|
111 | plot(I(2)); |
---|
112 | |
---|
113 | // ---- Singular Logo -------------- |
---|
114 | poly logo = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2); |
---|
115 | plot(logo); |
---|
116 | |
---|
117 | |
---|
118 | // --------- implicit curves ------------ |
---|
119 | // implicit curves |
---|
120 | ideal I(1) = y,-x2; |
---|
121 | plot(I(1)); |
---|
122 | ideal I(2) = x2,-y2 +4; |
---|
123 | plot(I(2)); |
---|
124 | |
---|
125 | //the lemniscate |
---|
126 | |
---|
127 | ideal I(3) = x4+2x2y2 + y4, x2-y2; |
---|
128 | plot(I(3)); |
---|
129 | |
---|
130 | // a critical part |
---|
131 | // adjust the plotregion properly to get a good picture |
---|
132 | |
---|
133 | poly f = (x-y)*(x2+y); |
---|
134 | plot(f,1); |
---|
135 | ideal J = jacob(f); |
---|
136 | J; |
---|
137 | plot(J); // bad resolution |
---|
138 | |
---|
139 | // ----------- surfaces ------------------- |
---|
140 | ideal J(1) = 3xy4 + 2xy2, x5y3 + x + y6,10x2; |
---|
141 | plot(J(1)); |
---|
142 | |
---|
143 | // Steiner surface |
---|
144 | |
---|
145 | ideal J(2) = x^2*y^2+x^2*z^2+y^2*z^2-17*x*y*z; |
---|
146 | plot(J(2)); |
---|
147 | |
---|
148 | plot(x*(x2-y2)+z2); |
---|
149 | |
---|
150 | // E7 |
---|
151 | plot(x^3-x*y^3+z^2); |
---|
152 | |
---|
153 | // Whitney umbrella |
---|
154 | plot(z^2-x^2*y); |
---|
155 | |
---|
156 | // A1 |
---|
157 | plot(y2-xz); |
---|
158 | |
---|
159 | |
---|
160 | } |
---|
161 | /////////////////////////////////////////////////////////////////////////////// |
---|
162 | |
---|
163 | |
---|