tomwalters@0
|
1 function H=arrow3(p1,p2,s,w,h,ip,alpha,beta)
|
tomwalters@0
|
2 % ARROW3
|
tomwalters@0
|
3 % ARROW3(P1,P2) will draw vector lines (2D/3D) from P1 to P2 with
|
tomwalters@0
|
4 % arrowheads, where P1 and P2 can be either nx2 matrices (for 2D),
|
tomwalters@0
|
5 % or nx3 matrices (for 3D).
|
tomwalters@0
|
6 %
|
tomwalters@0
|
7 % ARROW3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties
|
tomwalters@0
|
8 % of the line and arrowhead. S is a character string made with one
|
tomwalters@0
|
9 % element from any or all of the following 3 columns:
|
tomwalters@0
|
10 %
|
tomwalters@0
|
11 % Color Switches LineStyle LineWidth
|
tomwalters@0
|
12 % ------------------ ------------------- --------------------
|
tomwalters@0
|
13 % k black (default) - solid (default) 0.5 points (default)
|
tomwalters@0
|
14 % y yellow : dotted 0 no lines
|
tomwalters@0
|
15 % m magenta -. dashdot / LineWidthOrder
|
tomwalters@0
|
16 % c cyan -- dashed
|
tomwalters@0
|
17 % r red * LineStyleOrder
|
tomwalters@0
|
18 % g green
|
tomwalters@0
|
19 % b blue
|
tomwalters@0
|
20 % w white __________ __
|
tomwalters@0
|
21 % a apple green ^ |
|
tomwalters@0
|
22 % d dark gray / \ |
|
tomwalters@0
|
23 % e evergreen / \ |
|
tomwalters@0
|
24 % f fuchsia / \ |
|
tomwalters@0
|
25 % h honey / \ Height
|
tomwalters@0
|
26 % i indigo / \ |
|
tomwalters@0
|
27 % j jade / \ |
|
tomwalters@0
|
28 % l lilac / \ |
|
tomwalters@0
|
29 % n nutbrown /______ ______\ __|__
|
tomwalters@0
|
30 % p pink | | | |
|
tomwalters@0
|
31 % q kumquat |---- Width ----|
|
tomwalters@0
|
32 % s sky blue | | | |
|
tomwalters@0
|
33 % t tan | |
|
tomwalters@0
|
34 % u umber | |
|
tomwalters@0
|
35 % v violet | |
|
tomwalters@0
|
36 % z zinc -->| |<--LineWidth
|
tomwalters@0
|
37 % x random named color | |
|
tomwalters@0
|
38 % o ColorOrder
|
tomwalters@0
|
39 %
|
tomwalters@0
|
40 % The components of S may be specified in any order. Invalid
|
tomwalters@0
|
41 % characters in S will be ignored and replaced by default settings.
|
tomwalters@0
|
42 %
|
tomwalters@0
|
43 % Prefixing the color code with '_' produces a darker shade, e.g.
|
tomwalters@0
|
44 % '_t' is dark tan; prefixing the color code with '^' produces a
|
tomwalters@0
|
45 % lighter shade, e.g. '^q' is light kumquat. The relative
|
tomwalters@0
|
46 % brightness of light and dark color shades is controled by the
|
tomwalters@0
|
47 % scalar parameter BETA. Color code prefixes do not affect the
|
tomwalters@0
|
48 % basic colors (kymcrgbw) or the special color switches (xo).
|
tomwalters@0
|
49 %
|
tomwalters@0
|
50 % ColorOrder may be achieved in two fashions: The user may either
|
tomwalters@0
|
51 % set the ColorOrder property (using RGB triples) or define the
|
tomwalters@0
|
52 % global variable ColorOrder (using a string of valid color codes).
|
tomwalters@0
|
53 % If the color switch is specified with 'o', and the global variable
|
tomwalters@0
|
54 % ColorOrder is a string of color codes (color switches less 'x' and
|
tomwalters@0
|
55 % 'o', optionally prefixed with '_' or '^'), then the ColorOrder
|
tomwalters@0
|
56 % property will be set to the sequence of colors indicated by the
|
tomwalters@0
|
57 % ColorOrder variable. If the color switch is specified with 'o',
|
tomwalters@0
|
58 % and the global variable ColorOrder is empty or invalid, then the
|
tomwalters@0
|
59 % current ColorOrder property will be used. Note that the ColorOrder
|
tomwalters@0
|
60 % variable takes precedence over the ColorOrder property.
|
tomwalters@0
|
61 %
|
tomwalters@0
|
62 % The current LineStyleOrder property will be used if LineStyle is
|
tomwalters@0
|
63 % specified with '*'. MATLAB cycles through the line styles defined
|
tomwalters@0
|
64 % by the LineStyleOrder property only after using all colors defined
|
tomwalters@0
|
65 % by the ColorOrder property. If however, the global variable
|
tomwalters@0
|
66 % LineWidthOrder is defined, and LineWidth is specified with '/',
|
tomwalters@0
|
67 % then each line will be drawn with sequential color, linestyle, and
|
tomwalters@0
|
68 % linewidth.
|
tomwalters@0
|
69 %
|
tomwalters@0
|
70 % W is a vector of arrowhead widths. For linear plots with equal
|
tomwalters@0
|
71 % axes, the units of W (default = 1/72 of the PlotBox diagonal) are
|
tomwalters@0
|
72 % the same as those of the coordinate data (P1,P2). For linear plots
|
tomwalters@0
|
73 % with unequal axes, the units of W are scaled to fit as if the axes
|
tomwalters@0
|
74 % were equal. For log plots, the units of W (default = 1) are 1/72
|
tomwalters@0
|
75 % of the PositionRectangle diagonal.
|
tomwalters@0
|
76 %
|
tomwalters@0
|
77 % H (default = 3W) is a vector of arrowhead heights. If vector IP is
|
tomwalters@0
|
78 % neither empty nor negative, initial point markers will be plotted
|
tomwalters@0
|
79 % with diameter IP; for default diameter W, use IP = 0. The units of
|
tomwalters@0
|
80 % W, H, and IP are absolute for linear plots and relative to the
|
tomwalters@0
|
81 % PositionRectangle for log plots.
|
tomwalters@0
|
82 %
|
tomwalters@0
|
83 % ALPHA (default = 1) is a vector of FaceAlpha (MATLAB 6+) values
|
tomwalters@0
|
84 % ranging between 0 (clear) and 1 (opaque). FaceAlpha is a surface
|
tomwalters@0
|
85 % (arrowhead and initial point marker) property and does not affect
|
tomwalters@0
|
86 % lines. BETA (default = 0.4) is a scalar that controls the relative
|
tomwalters@0
|
87 % brightness of light and dark color shades, ranging between 0 (no
|
tomwalters@0
|
88 % contrast) and 1 (maximum contrast).
|
tomwalters@0
|
89 %
|
tomwalters@0
|
90 % Plotting lines with a single color, linestyle, and linewidth is
|
tomwalters@0
|
91 % faster than plotting lines with multiple colors and/or linestyles.
|
tomwalters@0
|
92 % Plotting lines with multiple linewidths is slower still.
|
tomwalters@0
|
93 %
|
tomwalters@0
|
94 % H = ARROW3(P1,P2,...) returns a vector of handles to line and
|
tomwalters@0
|
95 % surface objects created by ARROW3.
|
tomwalters@0
|
96 %
|
tomwalters@0
|
97 % ARROW3 COLORS will plot a table of named colors with default
|
tomwalters@0
|
98 % brightness. ARROW3('colors',BETA) will plot a table of named
|
tomwalters@0
|
99 % colors with brightness BETA.
|
tomwalters@0
|
100 %
|
tomwalters@0
|
101 % If a particular aspect ratio is required, use DASPECT, PBASPECT,
|
tomwalters@0
|
102 % AXIS, or XYZLIM commands before calling ARROW3. Changing aspect
|
tomwalters@0
|
103 % ratios or limits after calling ARROW3 may alter the appearance
|
tomwalters@0
|
104 % of arrowheads and initial point markers. ARROW3 sets XYZLimMode
|
tomwalters@0
|
105 % to manual for all plots, sets DataAspectRatioMode to manual for
|
tomwalters@0
|
106 % linear plots, and sets PlotBoxAspectRatioMode to manual for log
|
tomwalters@0
|
107 % plots and 3D plots.
|
tomwalters@0
|
108 %
|
tomwalters@0
|
109 % ARROW3 UPDATE will restore the the appearance of arrowheads and
|
tomwalters@0
|
110 % initial point markers that have become corrupted by changes to
|
tomwalters@0
|
111 % limits or aspect ratios. ARROW3('update',SF) will redraw initial
|
tomwalters@0
|
112 % point markers and arrowheads with scale factor SF. If SF has one
|
tomwalters@0
|
113 % one element, SF scales W, H and IP. If SF has two elements, SF(1)
|
tomwalters@0
|
114 % scales W and IP, and SF(2) scales H. If SF has three elements,
|
tomwalters@0
|
115 % SF(1) scales W, SF(2) scales H, and SF(3) scales IP.
|
tomwalters@0
|
116 %
|
tomwalters@0
|
117 % Usage Examples:
|
tomwalters@0
|
118 %
|
tomwalters@0
|
119 % % 2D vectors
|
tomwalters@0
|
120 % Arrow3([0 0],[1 3])
|
tomwalters@0
|
121 % Arrow3([0 0],[1 2],'-.e')
|
tomwalters@0
|
122 % Arrow3([0 0],[10 10],'--x2',1)
|
tomwalters@0
|
123 % Arrow3(zeros(10,2),50*rand(10,2),'x',1,3)
|
tomwalters@0
|
124 % Arrow3(zeros(10,2),[10*rand(10,1),500*rand(10,1)],'u')
|
tomwalters@0
|
125 % Arrow3(10*rand(10,2),50*rand(10,2),'x',1,[],1)
|
tomwalters@0
|
126 %
|
tomwalters@0
|
127 % % 3D vectors
|
tomwalters@0
|
128 % Arrow3([0 0 0],[1 1 1])
|
tomwalters@0
|
129 % Arrow3(zeros(20,3),50*rand(20,3),'--x1.5',2)
|
tomwalters@0
|
130 % Arrow3(zeros(100,3),50*rand(100,3),'x',1,3)
|
tomwalters@0
|
131 % Arrow3(zeros(10,3),[10*rand(10,1),500*rand(10,1),50*rand(10,1)],'a')
|
tomwalters@0
|
132 % Arrow3(10*rand(10,3),50*rand(10,3),'x',[],[],0)
|
tomwalters@0
|
133 %
|
tomwalters@0
|
134 % % Just for fun
|
tomwalters@0
|
135 % Arrow3(zeros(100,3),50*rand(100,3),'x',10,3,[],0.95)
|
tomwalters@0
|
136 % light('Position',[-10 -10 -10],'Style','local')
|
tomwalters@0
|
137 % light('Position',[60,60,60]), lighting gouraud
|
tomwalters@0
|
138 %
|
tomwalters@0
|
139 % % ColorOrder variable, color code prefixes, and Beta
|
tomwalters@0
|
140 % global ColorOrder, ColorOrder='^ui^e_hq^v';
|
tomwalters@0
|
141 % theta=[0:pi/22:pi/2]';
|
tomwalters@0
|
142 % Arrow3(zeros(12,2),[cos(theta),sin(theta)],'1.5o',0.1,[],[],[],0.5)
|
tomwalters@0
|
143 %
|
tomwalters@0
|
144 % % ColorOrder property, LineStyleOrder, LineWidthOrder, and Alpha
|
tomwalters@0
|
145 % global ColorOrder, ColorOrder=[];
|
tomwalters@0
|
146 % set(gca,'ColorOrder',[1,0,0;0,0,1;0.25,0.75,0.25;0,0,0])
|
tomwalters@0
|
147 % set(gca,'LineStyleOrder',{'-','--','-.',':'})
|
tomwalters@0
|
148 % global LineWidthOrder, LineWidthOrder=[1,2,4,8];
|
tomwalters@0
|
149 % w=[5,10,15,20]; h=[20,40,30,40]; alpha=[1,1,0.2,0.2];
|
tomwalters@0
|
150 % Arrow3(zeros(4,2),[10*rand(4,1),500*rand(4,1)],'o*/',w,h,10,alpha)
|
tomwalters@0
|
151 %
|
tomwalters@0
|
152 % % Log plot
|
tomwalters@0
|
153 % loglog([1e2,1e8],[1e-2,1e-1],'wo','MarkerSize',eps), hold on
|
tomwalters@0
|
154 % p1=repmat([1e3,2e-2],15,1);
|
tomwalters@0
|
155 % q1=[1e7,1e6,1e5,1e4,1e3,1e7,1e7,1e7,1e7,1e7,1e7,1e6,1e5,1e4,1e3];
|
tomwalters@0
|
156 % q2=1e-2*[9,9,9,9,9,7,5,4,3,2,1,1,1,1,1]; p2=[q1',q2'];
|
tomwalters@0
|
157 % global ColorOrder, ColorOrder=[];
|
tomwalters@0
|
158 % set(gca,'ColorOrder',rand(15,3))
|
tomwalters@0
|
159 % Arrow3(p1,p2,'o'), grid on, hold off
|
tomwalters@0
|
160 %
|
tomwalters@0
|
161 % % Color tables
|
tomwalters@0
|
162 % Arrow3('colors') % default color table
|
tomwalters@0
|
163 % Arrow3('colors',0.3) % low contrast color table
|
tomwalters@0
|
164 % Arrow3('colors',0.5) % high contrast color table
|
tomwalters@0
|
165 %
|
tomwalters@0
|
166 % % Update initial point markers and arrowheads
|
tomwalters@0
|
167 % Arrow3('update') % redraw same size
|
tomwalters@0
|
168 % Arrow3('update',2) % redraw double size
|
tomwalters@0
|
169 % Arrow3('update',0.5) % redraw half size
|
tomwalters@0
|
170 % Arrow3('update',[0.5,2,1]) % redraw W half size,
|
tomwalters@0
|
171 % % H double size, and
|
tomwalters@0
|
172 % % IP same size
|
tomwalters@0
|
173
|
tomwalters@0
|
174 % Copyright(c)2002,2003 Version 4.54
|
tomwalters@0
|
175 % Jeff Chang <cpmame@hotmail.com>
|
tomwalters@0
|
176 % Tom Davis <tdavis@eng.usf.edu>
|
tomwalters@0
|
177
|
tomwalters@0
|
178 % Revision History:
|
tomwalters@0
|
179 %
|
tomwalters@0
|
180 % 02/01/03 - Added UPDATE scale factor and matlab version
|
tomwalters@0
|
181 % checking, replaced call to CROSS (TD)
|
tomwalters@0
|
182 % 12/26/02 - Added UserData and UPDATE option (TD)
|
tomwalters@0
|
183 % 11/16/02 - Added more named colors, color code prefix,
|
tomwalters@0
|
184 % global ColorOrder, ALPHA , and BETA (TD)
|
tomwalters@0
|
185 % 10/12/02 - Added global LineWidthOrder,
|
tomwalters@0
|
186 % vectorized W, H and IP (TD)
|
tomwalters@0
|
187 % 10/05/02 - Changed CLF to CLA for subplot support,
|
tomwalters@0
|
188 % added ColorOrder and LineStyleOrder support (TD)
|
tomwalters@0
|
189 % 04/27/02 - Minor log plot revisions (TD)
|
tomwalters@0
|
190 % 03/26/02 - Added log plot support (TD)
|
tomwalters@0
|
191 % 03/24/02 - Adaptive grid spacing control to trade off
|
tomwalters@0
|
192 % appearance vs. speed based on size of matrix (JC)
|
tomwalters@0
|
193 % 03/16/02 - Added "axis tight" for improved appearance (JC)
|
tomwalters@0
|
194 % 03/12/02 - Added initial point marker (TD)
|
tomwalters@0
|
195 % 03/03/02 - Added aspect ratio support (TD)
|
tomwalters@0
|
196 % 03/02/02 - Enchance program's user friendliness (JC)
|
tomwalters@0
|
197 % (lump Color, LineStyle, and LineWidth together)
|
tomwalters@0
|
198 % 03/01/02 - Replaced call to ROTATE (TD)
|
tomwalters@0
|
199 % 02/28/02 - Modified line plotting,
|
tomwalters@0
|
200 % added linewidth and linestyle (TD)
|
tomwalters@0
|
201 % 02/27/02 - Minor enhancements on 3D appearance (JC)
|
tomwalters@0
|
202 % 02/26/02 - Minor enhancements for speed (TD&JC)
|
tomwalters@0
|
203 % 02/26/02 - Optimise PLOT3 and SURF for speed (TD)
|
tomwalters@0
|
204 % 02/25/02 - Return handler, error handling, color effect,
|
tomwalters@0
|
205 % generalize for 2D/3D vectors (JC)
|
tomwalters@0
|
206 % 02/24/02 - Optimise PLOT3 and SURF for speed (TD)
|
tomwalters@0
|
207 % 02/23/02 - First release (JC&TD)
|
tomwalters@0
|
208
|
tomwalters@0
|
209 %==========================================================================
|
tomwalters@0
|
210 % Error Checking
|
tomwalters@0
|
211 oldver=0; v=version; if v(1)<'6', oldver=1; end % matlab version
|
tomwalters@0
|
212 if nargin<8 | isempty(beta), beta=0.4; end, beta=abs(beta(1));
|
tomwalters@0
|
213 if strcmpi(p1,'colors') % plot color table
|
tomwalters@0
|
214 if nargin>1, beta=abs(p2(1)); end
|
tomwalters@0
|
215 LocalColorTable(1,beta); return
|
tomwalters@0
|
216 end
|
tomwalters@0
|
217 fig=gcf; ax=gca;
|
tomwalters@0
|
218 if strcmpi(p1,'update'), ud=get(ax,'UserData'); % update surfaces
|
tomwalters@0
|
219 if size(ud,2)<13, error('Invalid UserData'), end
|
tomwalters@0
|
220 set(ax,'UserData',[]); sf=[1,1,1];
|
tomwalters@0
|
221 if nargin>1, sf=p2(1)*sf; n=length(p2(:));
|
tomwalters@0
|
222 if n>1, sf(2)=p2(2); if n>2, sf(3)=p2(3); end, end
|
tomwalters@0
|
223 end
|
tomwalters@0
|
224 LocalUpdate(fig,ax,ud,sf); return
|
tomwalters@0
|
225 end
|
tomwalters@0
|
226 InputError=['Invalid input, type HELP ',upper(mfilename),...
|
tomwalters@0
|
227 ' for usage examples'];
|
tomwalters@0
|
228 if nargin<2, error(InputError), end
|
tomwalters@0
|
229 [r1,c1]=size(p1); [r2,c2]=size(p2); n=r1; Zeros=zeros(n,1);
|
tomwalters@0
|
230 if c1<2 | c1>3, error(InputError), end
|
tomwalters@0
|
231 if r1~=r2, error('P1 and P2 must have same number of rows'), end
|
tomwalters@0
|
232 if c1~=c2, error('P1 and P2 must have same number of columns'), end
|
tomwalters@0
|
233 if c1==2, p1=[p1,Zeros]; p2=[p2,Zeros];
|
tomwalters@0
|
234 elseif ~any([p1(:,3);p2(:,3)]), c1=2; end
|
tomwalters@0
|
235 L=get(ax,'LineStyleOrder'); C=get(ax,'ColorOrder');
|
tomwalters@0
|
236 ST=get(ax,'DefaultSurfaceTag'); LT=get(ax,'DefaultLineTag');
|
tomwalters@0
|
237 EC=get(ax,'DefaultSurfaceEdgeColor');
|
tomwalters@0
|
238 if strcmp(get(ax,'nextplot'),'add') & strcmp(get(fig,'nextplot'),'add')
|
tomwalters@0
|
239 Xr=get(ax,'xlim'); Yr=get(ax,'ylim'); Zr=get(ax,'zlim');
|
tomwalters@0
|
240 set(ax,'XLimMode','auto','YLimMode','auto','ZLimMode','auto');
|
tomwalters@0
|
241 xs=strcmp(get(ax,'xscale'),'log');
|
tomwalters@0
|
242 ys=strcmp(get(ax,'yscale'),'log');
|
tomwalters@0
|
243 zs=strcmp(get(ax,'zscale'),'log');
|
tomwalters@0
|
244 if zs, error('Z log scale not supported'), end
|
tomwalters@0
|
245 xys=xs+ys; restore=1;
|
tomwalters@0
|
246 if xys & any([p1(:,3);p2(:,3)])
|
tomwalters@0
|
247 error('3D log plot not supported')
|
tomwalters@0
|
248 end
|
tomwalters@0
|
249 else, restore=0; cla; view(c1); xys=0;
|
tomwalters@0
|
250 set(fig,'nextplot','add'); set(ax,'UserData',[],'nextplot','add');
|
tomwalters@0
|
251 end
|
tomwalters@0
|
252
|
tomwalters@0
|
253 %==========================================================================
|
tomwalters@0
|
254 % Style Control
|
tomwalters@0
|
255 [vc,cn]=LocalColorTable(0); prefix=''; OneColor=0;
|
tomwalters@0
|
256 if nargin<3, [c,ls,lw]=LocalValidateCLSW; % default Color, LineStyle/Width
|
tomwalters@0
|
257 else,
|
tomwalters@0
|
258 [c,ls,lw]=LocalValidateCLSW(s);
|
tomwalters@0
|
259 if length(c)>1, if sum('_^'==c(1)), prefix=c(1); end, c=c(2); end
|
tomwalters@0
|
260 if c=='x', c=cn(randperm(23),:); % random named color (less white)
|
tomwalters@0
|
261 elseif c=='o', global ColorOrder % ColorOrder
|
tomwalters@0
|
262 if length(ColorOrder)
|
tomwalters@0
|
263 [c,failed]=LocalColorMap(lower(ColorOrder),vc,cn,beta);
|
tomwalters@0
|
264 if failed, warning(['Invalid ColorOrder variable, ',...
|
tomwalters@0
|
265 'current ColorOrder property will be used'])
|
tomwalters@0
|
266 else, C=c; end
|
tomwalters@0
|
267 end, c=C;
|
tomwalters@0
|
268 elseif ~sum(vc==c), c='k'; warning(['Invalid color switch, ',...
|
tomwalters@0
|
269 'default color (black) will be used'])
|
tomwalters@0
|
270 end
|
tomwalters@0
|
271 end
|
tomwalters@0
|
272 if length(c)==1 % single color
|
tomwalters@0
|
273 c=LocalColorMap([prefix,c],vc,cn,beta); OneColor=1;
|
tomwalters@0
|
274 end
|
tomwalters@0
|
275 set(ax,'ColorOrder',c); c=repmat(c,ceil(n/size(c,1)),1);
|
tomwalters@0
|
276 if ls~='*', set(ax,'LineStyleOrder',ls); end % LineStyleOrder
|
tomwalters@0
|
277 if lw=='/', global LineWidthOrder % LineWidthOrder
|
tomwalters@0
|
278 if length(LineWidthOrder)
|
tomwalters@0
|
279 lw=repmat(LineWidthOrder(:),ceil(n/length(LineWidthOrder)),1);
|
tomwalters@0
|
280 else, lw=0.5; warning(['Undefined LineWidthOrder, ',...
|
tomwalters@0
|
281 'default width (0.5) will be used'])
|
tomwalters@0
|
282 end
|
tomwalters@0
|
283 end
|
tomwalters@0
|
284 if nargin<7 | isempty(alpha), alpha=1; end
|
tomwalters@0
|
285 a=repmat(alpha(:),ceil(n/length(alpha)),1); % FaceAlpha
|
tomwalters@0
|
286
|
tomwalters@0
|
287 %==========================================================================
|
tomwalters@0
|
288 % Log Plot
|
tomwalters@0
|
289 if xys
|
tomwalters@0
|
290 units=get(ax,'units'); set(ax,'units','points');
|
tomwalters@0
|
291 pos=get(ax,'position'); set(ax,'units',units);
|
tomwalters@0
|
292 if strcmp(get(ax,'PlotBoxAspectRatioMode'),'auto')
|
tomwalters@0
|
293 set(ax,'PlotBoxAspectRatio',[pos(3),pos(4),1]);
|
tomwalters@0
|
294 end
|
tomwalters@0
|
295 par=get(ax,'PlotBoxAspectRatio');
|
tomwalters@0
|
296 set(ax,'DataAspectRatio',[par(2),par(1),par(3)]);
|
tomwalters@0
|
297 % map coordinates onto unit square
|
tomwalters@0
|
298 q=[p1;p2]; xr=Xr; yr=Yr;
|
tomwalters@0
|
299 if xs, xr=log10(xr); q(:,1)=log10(q(:,1)); end
|
tomwalters@0
|
300 if ys, yr=log10(yr); q(:,2)=log10(q(:,2)); end
|
tomwalters@0
|
301 q=q-repmat([xr(1),yr(1),0],2*n,1);
|
tomwalters@0
|
302 dx=xr(2)-xr(1); dy=yr(2)-yr(1);
|
tomwalters@0
|
303 q=q*diag([1/dx,1/dy,1]);
|
tomwalters@0
|
304 q1=q(1:n,:); q2=q(n+1:end,:);
|
tomwalters@0
|
305 else, xs=0; ys=0; dx=0; dy=0; xr=0; yr=0; end
|
tomwalters@0
|
306
|
tomwalters@0
|
307 %==========================================================================
|
tomwalters@0
|
308 % Line
|
tomwalters@0
|
309 set(ax,'DefaultLineTag','arrow3');
|
tomwalters@0
|
310 if length(lw)==1
|
tomwalters@0
|
311 if lw>0
|
tomwalters@0
|
312 if OneColor & ls~='*' % single color, linestyle, and linewidth
|
tomwalters@0
|
313 P=zeros(3*n,3); i=1:n;
|
tomwalters@0
|
314 P(3*i-2,:)=p1(i,:); P(3*i-1,:)=p2(i,:); P(3*i,1)=NaN;
|
tomwalters@0
|
315 H1=plot3(P(:,1),P(:,2),P(:,3),'LineWidth',lw);
|
tomwalters@0
|
316 else % single linewidth
|
tomwalters@0
|
317 H1=plot3([p1(:,1),p2(:,1)]',[p1(:,2),p2(:,2)]',...
|
tomwalters@0
|
318 [p1(:,3),p2(:,3)]','LineWidth',lw);
|
tomwalters@0
|
319 end
|
tomwalters@0
|
320 else, H1=[]; end
|
tomwalters@0
|
321 else % use LineWidthOrder
|
tomwalters@0
|
322 ls=repmat(cellstr(L),ceil(n/size(L,1)),1);
|
tomwalters@0
|
323 H1=Zeros;
|
tomwalters@0
|
324 for i=1:n
|
tomwalters@0
|
325 H1(i)=plot3([p1(i,1),p2(i,1)],[p1(i,2),p2(i,2)],[p1(i,3),p2(i,3)],...
|
tomwalters@0
|
326 ls{i},'Color',c(i,:),'LineWidth',lw(i));
|
tomwalters@0
|
327 end
|
tomwalters@0
|
328 end
|
tomwalters@0
|
329
|
tomwalters@0
|
330 %==========================================================================
|
tomwalters@0
|
331 % Scale
|
tomwalters@0
|
332 ar=get(ax,'DataAspectRatio'); ar=sqrt(3)*ar/norm(ar);
|
tomwalters@0
|
333 set(ax,'DataAspectRatioMode','manual');
|
tomwalters@0
|
334 if nargin<4 | isempty(w) % width
|
tomwalters@0
|
335 if xys, w=1;
|
tomwalters@0
|
336 else, xr=get(ax,'xlim'); yr=get(ax,'ylim'); zr=get(ax,'zlim');
|
tomwalters@0
|
337 w=norm([xr(2)-xr(1),yr(2)-yr(1),zr(2)-zr(1)])/72;
|
tomwalters@0
|
338 end
|
tomwalters@0
|
339 end
|
tomwalters@0
|
340 w=repmat(w(:),ceil(n/length(w)),1);
|
tomwalters@0
|
341 if nargin<5 | isempty(h), h=3*w; end % height
|
tomwalters@0
|
342 h=repmat(h(:),ceil(n/length(h)),1);
|
tomwalters@0
|
343 if nargin>5 & ~isempty(ip) % ip
|
tomwalters@0
|
344 i=find(ip==0); ip(i)=w(i);
|
tomwalters@0
|
345 ip=repmat(ip(:),ceil(n/length(ip)),1);
|
tomwalters@0
|
346 else, ip=-ones(n,1); end
|
tomwalters@0
|
347
|
tomwalters@0
|
348 %==========================================================================
|
tomwalters@0
|
349 % UserData
|
tomwalters@0
|
350 set(ax,'UserData',[get(ax,'UserData');...
|
tomwalters@0
|
351 p1,p2,c(1:n,:),w(1:n),h(1:n),ip(1:n),a]);
|
tomwalters@0
|
352
|
tomwalters@0
|
353 %==========================================================================
|
tomwalters@0
|
354 % Arrowhead
|
tomwalters@0
|
355 if xys, whip=[w,h,ip]*sqrt(2)/72;
|
tomwalters@0
|
356 w=whip(:,1); h=whip(:,2); ip=whip(:,3); p1=q1; p2=q2;
|
tomwalters@0
|
357 end
|
tomwalters@0
|
358 W=(p1-p2)./repmat(ar,n,1);
|
tomwalters@0
|
359 W=W./repmat(sqrt(sum(W.*W,2)),1,3); % new z direction
|
tomwalters@0
|
360 U=[-W(:,2),W(:,1),Zeros];
|
tomwalters@0
|
361 N=sqrt(sum(U.*U,2)); i=find(N<eps); j=length(i);
|
tomwalters@0
|
362 U(i,:)=repmat([1,0,0],j,1); N(i)=ones(j,1);
|
tomwalters@0
|
363 U=U./repmat(N,1,3); % new x direction
|
tomwalters@0
|
364 V=[W(:,2).*U(:,3)-W(:,3).*U(:,2),... % new y direction
|
tomwalters@0
|
365 W(:,3).*U(:,1)-W(:,1).*U(:,3),...
|
tomwalters@0
|
366 W(:,1).*U(:,2)-W(:,2).*U(:,1)];
|
tomwalters@0
|
367
|
tomwalters@0
|
368 m1=30; m2=10; num=200; % max, min grid spacing, and threshold
|
tomwalters@0
|
369 if n<num, m=round((m2-m1)*n/num+m1); % adjust grid spacing automatically
|
tomwalters@0
|
370 else m=m2; end % for speed when matrix size > num
|
tomwalters@0
|
371
|
tomwalters@0
|
372 set(ax,'DefaultSurfaceTag','arrow3','DefaultSurfaceEdgeColor','none');
|
tomwalters@0
|
373 [x,y,z]=cylinder([0,1],m);
|
tomwalters@0
|
374 G=surface(x/2,y/2,z); dar=diag(ar);
|
tomwalters@0
|
375 X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData');
|
tomwalters@0
|
376 H2=Zeros; [j,k]=size(X);
|
tomwalters@0
|
377 for i=1:n % translate, rotate, and scale
|
tomwalters@0
|
378 H2(i)=copyobj(G,ax);
|
tomwalters@0
|
379 xyz=[w(i)*X(:),w(i)*Y(:),h(i)*Z(:)]*[U(i,:);V(i,:);W(i,:)]*dar;
|
tomwalters@0
|
380 x=reshape(xyz(:,1),j,k)+p2(i,1);
|
tomwalters@0
|
381 y=reshape(xyz(:,2),j,k)+p2(i,2);
|
tomwalters@0
|
382 z=reshape(xyz(:,3),j,k)+p2(i,3);
|
tomwalters@0
|
383 LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,...
|
tomwalters@0
|
384 x,y,z,a(i),c(i,:),H2(i),oldver);
|
tomwalters@0
|
385 end, delete(G);
|
tomwalters@0
|
386
|
tomwalters@0
|
387 %==========================================================================
|
tomwalters@0
|
388 % Initial Point Marker
|
tomwalters@0
|
389 if any(ip>0)
|
tomwalters@0
|
390 [x,y,z]=sphere(m);
|
tomwalters@0
|
391 G=surface(x*ar(1)/2,y*ar(2)/2,z*ar(3)/2);
|
tomwalters@0
|
392 X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData');
|
tomwalters@0
|
393 H3=zeros(n,1);
|
tomwalters@0
|
394 for i=1:n % translate
|
tomwalters@0
|
395 if ip(i)>0
|
tomwalters@0
|
396 H3(i)=copyobj(G,ax);
|
tomwalters@0
|
397 x=p1(i,1)+X*ip(i); y=p1(i,2)+Y*ip(i); z=p1(i,3)+Z*ip(i);
|
tomwalters@0
|
398 LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,...
|
tomwalters@0
|
399 x,y,z,a(i),c(i,:),H3(i),oldver);
|
tomwalters@0
|
400 end
|
tomwalters@0
|
401 end, delete(G);
|
tomwalters@0
|
402 else, H3=[]; end
|
tomwalters@0
|
403
|
tomwalters@0
|
404 %==========================================================================
|
tomwalters@0
|
405 % Finish
|
tomwalters@0
|
406 if xys, xr=Xr; yr=Yr; zr=Zr;
|
tomwalters@0
|
407 set(ax,'DataAspectRatioMode','auto');
|
tomwalters@0
|
408 else, set(fig,'Renderer','OpenGL');
|
tomwalters@0
|
409 w=max(w)*ar/2; ip=max([ip;0])*ar/2;
|
tomwalters@0
|
410 xr=[min([p1(:,1)-ip(1);p2(:,1)-w(1)]),max([p1(:,1)+ip(1);p2(:,1)+w(1)])];
|
tomwalters@0
|
411 yr=[min([p1(:,2)-ip(2);p2(:,2)-w(2)]),max([p1(:,2)+ip(2);p2(:,2)+w(2)])];
|
tomwalters@0
|
412 zr=[min([p1(:,3)-ip(3);p2(:,3)-w(3)]),max([p1(:,3)+ip(3);p2(:,3)+w(3)])];
|
tomwalters@0
|
413 if restore
|
tomwalters@0
|
414 xr=[min(xr(1),Xr(1)),max(xr(2),Xr(2))];
|
tomwalters@0
|
415 yr=[min(yr(1),Yr(1)),max(yr(2),Yr(2))];
|
tomwalters@0
|
416 zr=[min(zr(1),Zr(1)),max(zr(2),Zr(2))];
|
tomwalters@0
|
417 else, set(ax,'nextplot','replace'); end
|
tomwalters@0
|
418 end
|
tomwalters@0
|
419 set(ax,'LineStyleOrder',L,'ColorOrder',C,'DefaultLineTag',LT,...
|
tomwalters@0
|
420 'DefaultSurfaceTag',ST,'DefaultSurfaceEdgeColor',EC,...
|
tomwalters@0
|
421 'xlim',xr,'ylim',yr,'zlim',zr);
|
tomwalters@0
|
422 if c1==3, set(ax,'CameraViewAngle',get(ax,'CameraViewAngle'),...
|
tomwalters@0
|
423 'PlotBoxAspectRatio',get(ax,'PlotBoxAspectRatio'));
|
tomwalters@0
|
424 end
|
tomwalters@0
|
425 if nargout, H=[H1(:);H2(:);H3(:)]; end
|
tomwalters@0
|
426
|
tomwalters@0
|
427 %==========================================================================
|
tomwalters@0
|
428 % Update
|
tomwalters@0
|
429 function LocalUpdate(fig,ax,ud,sf)
|
tomwalters@0
|
430 p1=ud(:,1:3); p2=ud(:,4:6); c=ud(:,7:9); a=ud(:,13);
|
tomwalters@0
|
431 w=sf(1)*ud(:,10); h=sf(2)*ud(:,11); ip=sf(3)*ud(:,12);
|
tomwalters@0
|
432 H=get(ax,'children'); tag=get(H,'tag'); type=get(H,'type');
|
tomwalters@0
|
433 delete(H(strcmp(tag,'arrow3') & strcmp(type,'surface')));
|
tomwalters@0
|
434 set(fig,'nextplot','add'); set(ax,'ColorOrder',c,'nextplot','add');
|
tomwalters@0
|
435 global ColorOrder, ColorOrder=[]; arrow3(p1,p2,'o0',w,h,ip,a);
|
tomwalters@0
|
436
|
tomwalters@0
|
437 %==========================================================================
|
tomwalters@0
|
438 % SetSurface
|
tomwalters@0
|
439 function LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,x,y,z,a,c,H,oldver)
|
tomwalters@0
|
440 if xys
|
tomwalters@0
|
441 x=x*dx+xr(1); y=y*dy+yr(1);
|
tomwalters@0
|
442 if xs, x=10.^x; end
|
tomwalters@0
|
443 if ys, y=10.^y; end
|
tomwalters@0
|
444 end
|
tomwalters@0
|
445 if oldver
|
tomwalters@0
|
446 set(H,'XData',x,'YData',y,'ZData',z,'FaceColor',c);
|
tomwalters@0
|
447 else
|
tomwalters@0
|
448 set(H,'XData',x,'YData',y,'ZData',z,'FaceAlpha',a,'FaceColor',c);
|
tomwalters@0
|
449 end
|
tomwalters@0
|
450
|
tomwalters@0
|
451 %==========================================================================
|
tomwalters@0
|
452 % ColorTable
|
tomwalters@0
|
453 function [vc,cn]=LocalColorTable(n,beta)
|
tomwalters@0
|
454 vc='kymcrgbadefhijlnpqstuvzw'; % valid color codes
|
tomwalters@0
|
455 % k y m c
|
tomwalters@0
|
456 cn=[0.00,0.00,0.00; 1.00,1.00,0.00; 1.00,0.00,1.00; 0.00,1.00,1.00;
|
tomwalters@0
|
457 % r g b a
|
tomwalters@0
|
458 1.00,0.00,0.00; 0.00,1.00,0.00; 0.00,0.00,1.00; 0.00,0.70,0.00;
|
tomwalters@0
|
459 % d e f h
|
tomwalters@0
|
460 0.40,0.40,0.40; 0.00,0.40,0.00; 0.90,0.00,0.40; 1.00,0.80,0.00;
|
tomwalters@0
|
461 % i j l n
|
tomwalters@0
|
462 0.00,0.00,0.70; 0.20,0.80,0.50; 0.80,0.40,0.80; 0.50,0.20,0.00;
|
tomwalters@0
|
463 % p q s t
|
tomwalters@0
|
464 1.00,0.40,0.60; 1.00,0.40,0.00; 0.00,0.80,1.00; 0.80,0.40,0.00;
|
tomwalters@0
|
465 % u v z w
|
tomwalters@0
|
466 0.70,0.00,0.00; 0.60,0.00,1.00; 0.60,0.60,0.60; 1.00,1.00,1.00;];
|
tomwalters@0
|
467 if n % plot color table
|
tomwalters@0
|
468 name={'black','yellow','magenta','cyan',...
|
tomwalters@0
|
469 'red','green','blue','apple green',...
|
tomwalters@0
|
470 'dark gray','evergreen','fuchsia','honey',...
|
tomwalters@0
|
471 'indigo','jade','lilac','nutbrown',...
|
tomwalters@0
|
472 'pink','kumquat','sky blue','tan',...
|
tomwalters@0
|
473 'umber','violet','zinc','white'};
|
tomwalters@0
|
474 c=['yhtn';'gjae';'csbi';'plmv';'frqu';'wzdk'];
|
tomwalters@0
|
475 clf, set(gcf,'DefaultAxesXTick',[],'DefaultAxesYTick',[],...
|
tomwalters@0
|
476 'DefaultAxesXTickLabel',[],'DefaultAxesYTickLabel',[],...
|
tomwalters@0
|
477 'DefaultAxesXLim',[0,0.75],'DefaultAxesYLim',[0,0.75],...
|
tomwalters@0
|
478 'DefaultRectangleEdgeColor','none');
|
tomwalters@0
|
479 for i=1:24
|
tomwalters@0
|
480 subplot(4,6,i); j=find(vc==c(i)); title(name{j});
|
tomwalters@0
|
481 dark=LocalBrighten(cn(j,:),-beta);
|
tomwalters@0
|
482 light=LocalBrighten(cn(j,:),beta);
|
tomwalters@0
|
483 rectangle('Position',[0,0.00,0.75,0.25],'FaceColor',dark);
|
tomwalters@0
|
484 rectangle('Position',[0,0.25,0.75,0.25],'FaceColor',cn(j,:));
|
tomwalters@0
|
485 rectangle('Position',[0,0.50,0.75,0.25],'FaceColor',light);
|
tomwalters@0
|
486 rectangle('Position',[0,0.00,0.75,0.75],'EdgeColor','k');
|
tomwalters@0
|
487 if rem(i,6)==1
|
tomwalters@0
|
488 set(gca,'YTickLabel',{'dark','normal','light'},...
|
tomwalters@0
|
489 'YTick',[0.125,0.375,0.625]);
|
tomwalters@0
|
490 if i==19
|
tomwalters@0
|
491 text(0,-0.25,['{\bf\itARROW3} Named Color Table ',...
|
tomwalters@0
|
492 '( \beta = ',num2str(beta),' )']);
|
tomwalters@0
|
493 end
|
tomwalters@0
|
494 end
|
tomwalters@0
|
495 end
|
tomwalters@0
|
496 end
|
tomwalters@0
|
497
|
tomwalters@0
|
498 %==========================================================================
|
tomwalters@0
|
499 % ColorMap
|
tomwalters@0
|
500 function [C,failed]=LocalColorMap(c,vc,cn,beta)
|
tomwalters@0
|
501 n=length(c); failed=0; C=zeros(n,3); i=1; j=1;
|
tomwalters@0
|
502 while 1
|
tomwalters@0
|
503 if isempty(find([vc,'_^']==c(i))), failed=1; break, end
|
tomwalters@0
|
504 if sum('_^'==c(i))
|
tomwalters@0
|
505 if i+1>n, failed=1; break, end
|
tomwalters@0
|
506 if ~sum(vc==c(i+1)), failed=1; break, end
|
tomwalters@0
|
507 cc=cn(find(vc==c(i+1)),:); gamma=beta;
|
tomwalters@0
|
508 if c(i)=='_', gamma=-beta; end
|
tomwalters@0
|
509 C(j,:)=LocalBrighten(cc,gamma); i=i+2;
|
tomwalters@0
|
510 else, C(j,:)=cn(find(vc==c(i)),:); i=i+1; end
|
tomwalters@0
|
511 if i>n, break, end, j=j+1;
|
tomwalters@0
|
512 end, if n>j, C(j+1:n,:)=[]; end
|
tomwalters@0
|
513
|
tomwalters@0
|
514 %==========================================================================
|
tomwalters@0
|
515 % Brighten
|
tomwalters@0
|
516 function C=LocalBrighten(c,beta)
|
tomwalters@0
|
517 C=c.^((1-min(1-sqrt(eps),abs(beta)))^sign(beta));
|
tomwalters@0
|
518
|
tomwalters@0
|
519 %==========================================================================
|
tomwalters@0
|
520 % Generate valid value for color, linestyle and linewidth
|
tomwalters@0
|
521 function [c,ls,lw]=LocalValidateCLSW(s)
|
tomwalters@0
|
522 if nargin<1, c='k'; ls='-'; lw=0.5;
|
tomwalters@0
|
523 else
|
tomwalters@0
|
524 % identify linestyle
|
tomwalters@0
|
525 if findstr(s,'--'), ls='--'; s=strrep(s,'--','');
|
tomwalters@0
|
526 elseif findstr(s,'-.'), ls='-.'; s=strrep(s,'-.','');
|
tomwalters@0
|
527 elseif findstr(s,'-'), ls='-'; s=strrep(s,'-','');
|
tomwalters@0
|
528 elseif findstr(s,':'), ls=':'; s=strrep(s,':','');
|
tomwalters@0
|
529 elseif findstr(s,'*'), ls='*'; s=strrep(s,'*','');
|
tomwalters@0
|
530 else, ls='-'; end
|
tomwalters@0
|
531
|
tomwalters@0
|
532 % identify linewidth
|
tomwalters@0
|
533 tmp=double(s);
|
tomwalters@0
|
534 tmp=find(tmp>45 & tmp<57);
|
tomwalters@0
|
535 if length(tmp)
|
tomwalters@0
|
536 if any(s(tmp)=='/'), lw='/'; else, lw=str2num(s(tmp)); end
|
tomwalters@0
|
537 s(tmp)='';
|
tomwalters@0
|
538 else, lw=0.5; end
|
tomwalters@0
|
539
|
tomwalters@0
|
540 % identify color
|
tomwalters@0
|
541 if length(s), s=lower(s);
|
tomwalters@0
|
542 if length(s)>1, c=s(1:2);
|
tomwalters@0
|
543 else, c=s(1); end
|
tomwalters@0
|
544 else, c='k'; end
|
tomwalters@0
|
545 end |