1
## Copyright (C) 1998, 1999, 2000 Joao Cardoso.
3
## This program is free software; you can redistribute it and/or modify it
4
## under the terms of the GNU General Public License as published by the
5
## Free Software Foundation; either version 2 of the License, or (at your
6
## option) any later version.
8
## This program is distributed in the hope that it will be useful, but
9
## WITHOUT ANY WARRANTY; without even the implied warranty of
10
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
## General Public License for more details.
13
## This file is part of plplot_octave.
14
## It is based on the corresponding demo function of PLplot.
16
## Does several contour plots using different coordinate mappings.
20
global XPTS=35; ## Data points in x
21
global YPTS=46; ## Datat points in y
23
global tr = [2/(XPTS-1); 0.0; -1.0; 0.0; 2/(YPTS-1); -1.0];
25
function [tx ty] = mypltr(x, y)
31
tx = tr(1) * x + tr(2) * y + tr(3);
32
ty = tr(4) * x + tr(5) * y + tr(6);
39
plenv(-1., 1., -1., 1., 0, -2);
48
t = (2.*pi/(PERIMETERPTS-1))*i;
53
## create data to be contoured
59
theta = (2.*pi/(THETAPTS-1))*j;
64
lev = 0.05 + 0.10* i';
67
plcont2(z, 1, RPTS, 1, THETAPTS, lev, xg', yg');
69
pllab("", "", "Polar Contour Plot");
72
## shielded potential contour plot example.
81
## create data to be contoured
86
theta = (2.*pi/(PTHETAPTS-1))*(0.5 + j);
101
xpmin = xmin - abs(xmin)*peps;
102
xpmax = xmax + abs(xmax)*peps;
103
ypmin = ymin - abs(ymin)*peps;
104
ypmax = ymax + abs(ymax)*peps;
106
## Potential inside a conducting cylinder (or sphere) by method of images.
107
## Charge 1 is placed at (d1, d1), with image charge at (d2, d2).
108
## Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2).
109
## Also put in smoothing term at small distances.
125
div1 = sqrt((xg-d1).^2 + (yg-d1).^2 + eeps^2);
126
div1i = sqrt((xg-d1i).^2 + (yg-d1i).^2 + eeps^2);
127
div2 = sqrt((xg-d2).^2 + (yg+d2).^2 + eeps^2);
128
div2i = sqrt((xg-d2i).^2 + (yg+d2i).^2 + eeps^2);
129
z = q1./div1 + q1i./div1i + q2./div2 + q2i./div2i;
134
## Positive and negative contour levels.
135
dz = (zmax-zmin)/ PNLEVEL;
138
clevel = zmin + ( i + 0.5)*dz;
139
clevelneg = clevel(clevel <= 0);
140
clevelpos = clevel(clevel > 0);
141
nlevelneg = columns( clevelneg);
142
nlevelpos = columns( clevelpos);
149
## Finally start plotting this page!
153
plvpas(0.1, 0.9, 0.1, 0.9, 1.0);
154
plwind(xpmin, xpmax, ypmin, ypmax);
155
plbox("", 0., 0, "", 0., 0);
161
plcont2(z, 1, PRPTS, 1, PTHETAPTS, clevelneg', xg, yg);
167
plcont2(z, 1, PRPTS, 1, PTHETAPTS, clevelpos', xg, yg);
170
## Draw outer boundary
171
i = 0:PPERIMETERPTS-1;
172
t = (2.*pi/(PPERIMETERPTS-1))*i;
173
px = x0 + rmax*cos(t);
174
py = y0 + rmax*sin(t);
180
pllab("", "", "Shielded potential of charges in a conducting sphere");
190
clevel = linspace(-1,1,11)';
191
## Hack to ensure that zero contour really is zero
192
## and not a very small number.
193
## For me problem only occurs on i386 32 bit Debian 3.1
194
## with octave 2.1.69.
195
## 64-bit Ubuntu Dapper with octave 2.1.72 seems ok.
198
mark0 = []; space0 = [];
199
mark1 = [1500]; space1 = [1500];
201
## Parse and process command line arguments
203
## (void) plparseopts(&argc, argv, PL_PARSE_FULL);
209
## Set up function arrays
212
xx = (i - fix(XPTS / 2)) / fix(XPTS / 2);
213
yy = ((0:YPTS-1) - fix(YPTS / 2)) / fix(YPTS / 2) - 1.0;
214
z(i+1,:) = xx * xx - yy .* yy;
215
w(i+1,:) = 2 * xx .* yy;
218
## Plot using identity transform
220
pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
221
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
223
plcont(z, 1, XPTS, 1, YPTS, clevel, tr);
224
plstyl(mark1, space1);
226
plcont(w, 1, XPTS, 1, YPTS, clevel, tr);
227
plstyl(mark0, space0);
229
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
231
pl_setcontlabelformat(4,3);
232
pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
233
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
235
plcont(z, 1, XPTS, 1, YPTS, clevel, tr);
236
plstyl(mark1, space1);
238
plcont(w, 1, XPTS, 1, YPTS, clevel, tr);
239
plstyl(mark0, space0);
241
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
246
[xx yy] = mypltr(i, (0:YPTS-1));
252
xg3(i+1,:) = xx .+ distort .* cos(argx);
253
yg3(i+1,:) = yy .- distort .* cos(argy);
255
xg2(i+1,:) = xx .+ distort .* cos(argx) .* cos(argy);
256
yg2(i+1,:) = yy .- distort .* cos(argx) .* cos(argy);
263
## Plot using 1d coordinate transform
265
pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
266
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
268
plcont1(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
269
plstyl(mark1, space1);
271
plcont1(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
272
plstyl(mark0, space0);
274
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
276
pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
277
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
279
plcont1(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
280
plstyl(mark1, space1);
282
plcont1(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
283
plstyl(mark0, space0);
285
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
287
## Plot using 2d coordinate transform
289
pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
290
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
292
plcont2(z, 1, XPTS, 1, YPTS, clevel, xg2, yg2);
293
plstyl(mark1, space1);
295
plcont2(w, 1, XPTS, 1, YPTS, clevel, xg2, yg2);
296
plstyl(mark0, space0);
298
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
300
pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
301
plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
303
plcont1(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
304
plstyl(mark1, space1);
306
plcont1(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1);
307
plstyl(mark0, space0);
309
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
311
pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
313
## pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
317
pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
319
## pl_setcontlabelparam(0.006, 0.3, 0.1, 1);