NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/plot3in2.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function plot3in2(x,y,z,width)
2
3 % PLOT3IN2 plots 3-dimensional lines as in 2-dimensions,
4 %      with the thickness of the line proportional to the 3-rd
5 %      coordinate (z).
6 %    PLOT3IN2(X) and PLOT3IN2(X,Y) are equivalent to the ordinary
7 %      routines  PLOT(X) and PLOT(X,Y).
8 %    PLOT3IN2(X,Y,Z) is equivalent to PLOT(X,Y) but with line
9 %      thickness proportional to Z.
10 %      All three variavles X, Y, Z must have the same size
11 %      (vectors or matrices). Usual MATLAB columnwise
12 %      vectorization is applied.
13 %    PLOT3IN2(X,Y,Z,WIDTH) also specifies maximum line width
14 %      relative to the figure size.
15 %      Works with 4.1 or later version.
16 %
17 % Calls: none
18
19 %  Kirill Pankratov,  kirill@plume.mit.edu
20 %  April 27, 1994
21
22 widthdflt = .015;   % Default for maximum width of the line relative
23                     % to the figure size
24
25  % Handle input .....................................................
26 if nargin==0
27   disp([10 '  Error: not enough input arguments' 10])
28   return
29 end
30 if nargin==1, plot(x),   return, end
31 if nargin==2, plot(x,y), return, end
32 if nargin==3, width = widthdflt; end
33
34 % Now if truly 3 dimensions (input arguments) .......................
35 fig = get(0,'currentfigure');
36 if strcmp(get(fig,'NextPlot'),'new')  % J.M. Shramm suggestion
37   fig = figure;
38 end
39 oldunits = get(fig,'units');
40 set(fig,'units','pixels')
41 szf = get(fig,'pos');
42 szf = max(szf(3:4));     %  Size of the figure
43 lw = ceil(szf*width);    % Number of thickenings for each line
44
45 holdst = ishold;         % Hold state
46 sz = size(x);
47
48  % Determine limits and scales ............
49 C = zeros(size(x));
50 C = C+isnan(x)+isnan(y)+isnan(z);
51 fnd = find(C==0);
52 xlim = [min(x(fnd)) max(x(fnd))];
53 ylim = [min(y(fnd)) max(y(fnd))];
54 zlim = [min(z(fnd)) max(z(fnd))];
55 scx = (xlim(2)-xlim(1))*width/2;
56 scy = (ylim(2)-ylim(1))*width/2;
57
58  % Calculate differentials ................
59 dx = zeros(size(x)); dy = dx;
60 dx(2:sz(1)-1,:) = (x(3:sz(1),:)-x(1:sz(1)-2,:))/2;
61 dy(2:sz(1)-1,:) = (y(3:sz(1),:)-y(1:sz(1)-2,:))/2;
62 C = sqrt(dx.^2+dy.^2+eps);  % Length of the line element dl
63 dx = dx./C;  % dx-elements of the line
64 dy = dy./C;  % dy-elements of the line
65 z = (z-zlim(1))/(zlim(2)-zlim(1));  % Normalized z
66
67  % Plot bounding lines ....................
68 plot(x+scx*z.*dy,y-scy*z.*dx)
69 hold on
70 plot(x-scx*z.*dy,y+scy*z.*dx)
71
72  % Fill inside ............................
73 for jw = 1:lw
74   fnd = find(z<jw/lw);
75   length(fnd);
76   x(fnd) = nan*ones(size(fnd));
77   y(fnd) = nan*ones(size(fnd));
78   plot(x,y,'linewidth',.5*(jw+1))
79 end
80
81  % Set units and hold toinitial state .....
82 set(fig,'units',oldunits)
83 if ~holdst, hold off, end
Note: See TracBrowser for help on using the browser.