tomwalters@0: function H=arrow3(p1,p2,s,w,h,ip,alpha,beta) tomwalters@0: % ARROW3 tomwalters@0: % ARROW3(P1,P2) will draw vector lines (2D/3D) from P1 to P2 with tomwalters@0: % arrowheads, where P1 and P2 can be either nx2 matrices (for 2D), tomwalters@0: % or nx3 matrices (for 3D). tomwalters@0: % tomwalters@0: % ARROW3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties tomwalters@0: % of the line and arrowhead. S is a character string made with one tomwalters@0: % element from any or all of the following 3 columns: tomwalters@0: % tomwalters@0: % Color Switches LineStyle LineWidth tomwalters@0: % ------------------ ------------------- -------------------- tomwalters@0: % k black (default) - solid (default) 0.5 points (default) tomwalters@0: % y yellow : dotted 0 no lines tomwalters@0: % m magenta -. dashdot / LineWidthOrder tomwalters@0: % c cyan -- dashed tomwalters@0: % r red * LineStyleOrder tomwalters@0: % g green tomwalters@0: % b blue tomwalters@0: % w white __________ __ tomwalters@0: % a apple green ^ | tomwalters@0: % d dark gray / \ | tomwalters@0: % e evergreen / \ | tomwalters@0: % f fuchsia / \ | tomwalters@0: % h honey / \ Height tomwalters@0: % i indigo / \ | tomwalters@0: % j jade / \ | tomwalters@0: % l lilac / \ | tomwalters@0: % n nutbrown /______ ______\ __|__ tomwalters@0: % p pink | | | | tomwalters@0: % q kumquat |---- Width ----| tomwalters@0: % s sky blue | | | | tomwalters@0: % t tan | | tomwalters@0: % u umber | | tomwalters@0: % v violet | | tomwalters@0: % z zinc -->| |<--LineWidth tomwalters@0: % x random named color | | tomwalters@0: % o ColorOrder tomwalters@0: % tomwalters@0: % The components of S may be specified in any order. Invalid tomwalters@0: % characters in S will be ignored and replaced by default settings. tomwalters@0: % tomwalters@0: % Prefixing the color code with '_' produces a darker shade, e.g. tomwalters@0: % '_t' is dark tan; prefixing the color code with '^' produces a tomwalters@0: % lighter shade, e.g. '^q' is light kumquat. The relative tomwalters@0: % brightness of light and dark color shades is controled by the tomwalters@0: % scalar parameter BETA. Color code prefixes do not affect the tomwalters@0: % basic colors (kymcrgbw) or the special color switches (xo). tomwalters@0: % tomwalters@0: % ColorOrder may be achieved in two fashions: The user may either tomwalters@0: % set the ColorOrder property (using RGB triples) or define the tomwalters@0: % global variable ColorOrder (using a string of valid color codes). tomwalters@0: % If the color switch is specified with 'o', and the global variable tomwalters@0: % ColorOrder is a string of color codes (color switches less 'x' and tomwalters@0: % 'o', optionally prefixed with '_' or '^'), then the ColorOrder tomwalters@0: % property will be set to the sequence of colors indicated by the tomwalters@0: % ColorOrder variable. If the color switch is specified with 'o', tomwalters@0: % and the global variable ColorOrder is empty or invalid, then the tomwalters@0: % current ColorOrder property will be used. Note that the ColorOrder tomwalters@0: % variable takes precedence over the ColorOrder property. tomwalters@0: % tomwalters@0: % The current LineStyleOrder property will be used if LineStyle is tomwalters@0: % specified with '*'. MATLAB cycles through the line styles defined tomwalters@0: % by the LineStyleOrder property only after using all colors defined tomwalters@0: % by the ColorOrder property. If however, the global variable tomwalters@0: % LineWidthOrder is defined, and LineWidth is specified with '/', tomwalters@0: % then each line will be drawn with sequential color, linestyle, and tomwalters@0: % linewidth. tomwalters@0: % tomwalters@0: % W is a vector of arrowhead widths. For linear plots with equal tomwalters@0: % axes, the units of W (default = 1/72 of the PlotBox diagonal) are tomwalters@0: % the same as those of the coordinate data (P1,P2). For linear plots tomwalters@0: % with unequal axes, the units of W are scaled to fit as if the axes tomwalters@0: % were equal. For log plots, the units of W (default = 1) are 1/72 tomwalters@0: % of the PositionRectangle diagonal. tomwalters@0: % tomwalters@0: % H (default = 3W) is a vector of arrowhead heights. If vector IP is tomwalters@0: % neither empty nor negative, initial point markers will be plotted tomwalters@0: % with diameter IP; for default diameter W, use IP = 0. The units of tomwalters@0: % W, H, and IP are absolute for linear plots and relative to the tomwalters@0: % PositionRectangle for log plots. tomwalters@0: % tomwalters@0: % ALPHA (default = 1) is a vector of FaceAlpha (MATLAB 6+) values tomwalters@0: % ranging between 0 (clear) and 1 (opaque). FaceAlpha is a surface tomwalters@0: % (arrowhead and initial point marker) property and does not affect tomwalters@0: % lines. BETA (default = 0.4) is a scalar that controls the relative tomwalters@0: % brightness of light and dark color shades, ranging between 0 (no tomwalters@0: % contrast) and 1 (maximum contrast). tomwalters@0: % tomwalters@0: % Plotting lines with a single color, linestyle, and linewidth is tomwalters@0: % faster than plotting lines with multiple colors and/or linestyles. tomwalters@0: % Plotting lines with multiple linewidths is slower still. tomwalters@0: % tomwalters@0: % H = ARROW3(P1,P2,...) returns a vector of handles to line and tomwalters@0: % surface objects created by ARROW3. tomwalters@0: % tomwalters@0: % ARROW3 COLORS will plot a table of named colors with default tomwalters@0: % brightness. ARROW3('colors',BETA) will plot a table of named tomwalters@0: % colors with brightness BETA. tomwalters@0: % tomwalters@0: % If a particular aspect ratio is required, use DASPECT, PBASPECT, tomwalters@0: % AXIS, or XYZLIM commands before calling ARROW3. Changing aspect tomwalters@0: % ratios or limits after calling ARROW3 may alter the appearance tomwalters@0: % of arrowheads and initial point markers. ARROW3 sets XYZLimMode tomwalters@0: % to manual for all plots, sets DataAspectRatioMode to manual for tomwalters@0: % linear plots, and sets PlotBoxAspectRatioMode to manual for log tomwalters@0: % plots and 3D plots. tomwalters@0: % tomwalters@0: % ARROW3 UPDATE will restore the the appearance of arrowheads and tomwalters@0: % initial point markers that have become corrupted by changes to tomwalters@0: % limits or aspect ratios. ARROW3('update',SF) will redraw initial tomwalters@0: % point markers and arrowheads with scale factor SF. If SF has one tomwalters@0: % one element, SF scales W, H and IP. If SF has two elements, SF(1) tomwalters@0: % scales W and IP, and SF(2) scales H. If SF has three elements, tomwalters@0: % SF(1) scales W, SF(2) scales H, and SF(3) scales IP. tomwalters@0: % tomwalters@0: % Usage Examples: tomwalters@0: % tomwalters@0: % % 2D vectors tomwalters@0: % Arrow3([0 0],[1 3]) tomwalters@0: % Arrow3([0 0],[1 2],'-.e') tomwalters@0: % Arrow3([0 0],[10 10],'--x2',1) tomwalters@0: % Arrow3(zeros(10,2),50*rand(10,2),'x',1,3) tomwalters@0: % Arrow3(zeros(10,2),[10*rand(10,1),500*rand(10,1)],'u') tomwalters@0: % Arrow3(10*rand(10,2),50*rand(10,2),'x',1,[],1) tomwalters@0: % tomwalters@0: % % 3D vectors tomwalters@0: % Arrow3([0 0 0],[1 1 1]) tomwalters@0: % Arrow3(zeros(20,3),50*rand(20,3),'--x1.5',2) tomwalters@0: % Arrow3(zeros(100,3),50*rand(100,3),'x',1,3) tomwalters@0: % Arrow3(zeros(10,3),[10*rand(10,1),500*rand(10,1),50*rand(10,1)],'a') tomwalters@0: % Arrow3(10*rand(10,3),50*rand(10,3),'x',[],[],0) tomwalters@0: % tomwalters@0: % % Just for fun tomwalters@0: % Arrow3(zeros(100,3),50*rand(100,3),'x',10,3,[],0.95) tomwalters@0: % light('Position',[-10 -10 -10],'Style','local') tomwalters@0: % light('Position',[60,60,60]), lighting gouraud tomwalters@0: % tomwalters@0: % % ColorOrder variable, color code prefixes, and Beta tomwalters@0: % global ColorOrder, ColorOrder='^ui^e_hq^v'; tomwalters@0: % theta=[0:pi/22:pi/2]'; tomwalters@0: % Arrow3(zeros(12,2),[cos(theta),sin(theta)],'1.5o',0.1,[],[],[],0.5) tomwalters@0: % tomwalters@0: % % ColorOrder property, LineStyleOrder, LineWidthOrder, and Alpha tomwalters@0: % global ColorOrder, ColorOrder=[]; tomwalters@0: % set(gca,'ColorOrder',[1,0,0;0,0,1;0.25,0.75,0.25;0,0,0]) tomwalters@0: % set(gca,'LineStyleOrder',{'-','--','-.',':'}) tomwalters@0: % global LineWidthOrder, LineWidthOrder=[1,2,4,8]; tomwalters@0: % w=[5,10,15,20]; h=[20,40,30,40]; alpha=[1,1,0.2,0.2]; tomwalters@0: % Arrow3(zeros(4,2),[10*rand(4,1),500*rand(4,1)],'o*/',w,h,10,alpha) tomwalters@0: % tomwalters@0: % % Log plot tomwalters@0: % loglog([1e2,1e8],[1e-2,1e-1],'wo','MarkerSize',eps), hold on tomwalters@0: % p1=repmat([1e3,2e-2],15,1); tomwalters@0: % q1=[1e7,1e6,1e5,1e4,1e3,1e7,1e7,1e7,1e7,1e7,1e7,1e6,1e5,1e4,1e3]; tomwalters@0: % q2=1e-2*[9,9,9,9,9,7,5,4,3,2,1,1,1,1,1]; p2=[q1',q2']; tomwalters@0: % global ColorOrder, ColorOrder=[]; tomwalters@0: % set(gca,'ColorOrder',rand(15,3)) tomwalters@0: % Arrow3(p1,p2,'o'), grid on, hold off tomwalters@0: % tomwalters@0: % % Color tables tomwalters@0: % Arrow3('colors') % default color table tomwalters@0: % Arrow3('colors',0.3) % low contrast color table tomwalters@0: % Arrow3('colors',0.5) % high contrast color table tomwalters@0: % tomwalters@0: % % Update initial point markers and arrowheads tomwalters@0: % Arrow3('update') % redraw same size tomwalters@0: % Arrow3('update',2) % redraw double size tomwalters@0: % Arrow3('update',0.5) % redraw half size tomwalters@0: % Arrow3('update',[0.5,2,1]) % redraw W half size, tomwalters@0: % % H double size, and tomwalters@0: % % IP same size tomwalters@0: tomwalters@0: % Copyright(c)2002,2003 Version 4.54 tomwalters@0: % Jeff Chang tomwalters@0: % Tom Davis tomwalters@0: tomwalters@0: % Revision History: tomwalters@0: % tomwalters@0: % 02/01/03 - Added UPDATE scale factor and matlab version tomwalters@0: % checking, replaced call to CROSS (TD) tomwalters@0: % 12/26/02 - Added UserData and UPDATE option (TD) tomwalters@0: % 11/16/02 - Added more named colors, color code prefix, tomwalters@0: % global ColorOrder, ALPHA , and BETA (TD) tomwalters@0: % 10/12/02 - Added global LineWidthOrder, tomwalters@0: % vectorized W, H and IP (TD) tomwalters@0: % 10/05/02 - Changed CLF to CLA for subplot support, tomwalters@0: % added ColorOrder and LineStyleOrder support (TD) tomwalters@0: % 04/27/02 - Minor log plot revisions (TD) tomwalters@0: % 03/26/02 - Added log plot support (TD) tomwalters@0: % 03/24/02 - Adaptive grid spacing control to trade off tomwalters@0: % appearance vs. speed based on size of matrix (JC) tomwalters@0: % 03/16/02 - Added "axis tight" for improved appearance (JC) tomwalters@0: % 03/12/02 - Added initial point marker (TD) tomwalters@0: % 03/03/02 - Added aspect ratio support (TD) tomwalters@0: % 03/02/02 - Enchance program's user friendliness (JC) tomwalters@0: % (lump Color, LineStyle, and LineWidth together) tomwalters@0: % 03/01/02 - Replaced call to ROTATE (TD) tomwalters@0: % 02/28/02 - Modified line plotting, tomwalters@0: % added linewidth and linestyle (TD) tomwalters@0: % 02/27/02 - Minor enhancements on 3D appearance (JC) tomwalters@0: % 02/26/02 - Minor enhancements for speed (TD&JC) tomwalters@0: % 02/26/02 - Optimise PLOT3 and SURF for speed (TD) tomwalters@0: % 02/25/02 - Return handler, error handling, color effect, tomwalters@0: % generalize for 2D/3D vectors (JC) tomwalters@0: % 02/24/02 - Optimise PLOT3 and SURF for speed (TD) tomwalters@0: % 02/23/02 - First release (JC&TD) tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Error Checking tomwalters@0: oldver=0; v=version; if v(1)<'6', oldver=1; end % matlab version tomwalters@0: if nargin<8 | isempty(beta), beta=0.4; end, beta=abs(beta(1)); tomwalters@0: if strcmpi(p1,'colors') % plot color table tomwalters@0: if nargin>1, beta=abs(p2(1)); end tomwalters@0: LocalColorTable(1,beta); return tomwalters@0: end tomwalters@0: fig=gcf; ax=gca; tomwalters@0: if strcmpi(p1,'update'), ud=get(ax,'UserData'); % update surfaces tomwalters@0: if size(ud,2)<13, error('Invalid UserData'), end tomwalters@0: set(ax,'UserData',[]); sf=[1,1,1]; tomwalters@0: if nargin>1, sf=p2(1)*sf; n=length(p2(:)); tomwalters@0: if n>1, sf(2)=p2(2); if n>2, sf(3)=p2(3); end, end tomwalters@0: end tomwalters@0: LocalUpdate(fig,ax,ud,sf); return tomwalters@0: end tomwalters@0: InputError=['Invalid input, type HELP ',upper(mfilename),... tomwalters@0: ' for usage examples']; tomwalters@0: if nargin<2, error(InputError), end tomwalters@0: [r1,c1]=size(p1); [r2,c2]=size(p2); n=r1; Zeros=zeros(n,1); tomwalters@0: if c1<2 | c1>3, error(InputError), end tomwalters@0: if r1~=r2, error('P1 and P2 must have same number of rows'), end tomwalters@0: if c1~=c2, error('P1 and P2 must have same number of columns'), end tomwalters@0: if c1==2, p1=[p1,Zeros]; p2=[p2,Zeros]; tomwalters@0: elseif ~any([p1(:,3);p2(:,3)]), c1=2; end tomwalters@0: L=get(ax,'LineStyleOrder'); C=get(ax,'ColorOrder'); tomwalters@0: ST=get(ax,'DefaultSurfaceTag'); LT=get(ax,'DefaultLineTag'); tomwalters@0: EC=get(ax,'DefaultSurfaceEdgeColor'); tomwalters@0: if strcmp(get(ax,'nextplot'),'add') & strcmp(get(fig,'nextplot'),'add') tomwalters@0: Xr=get(ax,'xlim'); Yr=get(ax,'ylim'); Zr=get(ax,'zlim'); tomwalters@0: set(ax,'XLimMode','auto','YLimMode','auto','ZLimMode','auto'); tomwalters@0: xs=strcmp(get(ax,'xscale'),'log'); tomwalters@0: ys=strcmp(get(ax,'yscale'),'log'); tomwalters@0: zs=strcmp(get(ax,'zscale'),'log'); tomwalters@0: if zs, error('Z log scale not supported'), end tomwalters@0: xys=xs+ys; restore=1; tomwalters@0: if xys & any([p1(:,3);p2(:,3)]) tomwalters@0: error('3D log plot not supported') tomwalters@0: end tomwalters@0: else, restore=0; cla; view(c1); xys=0; tomwalters@0: set(fig,'nextplot','add'); set(ax,'UserData',[],'nextplot','add'); tomwalters@0: end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Style Control tomwalters@0: [vc,cn]=LocalColorTable(0); prefix=''; OneColor=0; tomwalters@0: if nargin<3, [c,ls,lw]=LocalValidateCLSW; % default Color, LineStyle/Width tomwalters@0: else, tomwalters@0: [c,ls,lw]=LocalValidateCLSW(s); tomwalters@0: if length(c)>1, if sum('_^'==c(1)), prefix=c(1); end, c=c(2); end tomwalters@0: if c=='x', c=cn(randperm(23),:); % random named color (less white) tomwalters@0: elseif c=='o', global ColorOrder % ColorOrder tomwalters@0: if length(ColorOrder) tomwalters@0: [c,failed]=LocalColorMap(lower(ColorOrder),vc,cn,beta); tomwalters@0: if failed, warning(['Invalid ColorOrder variable, ',... tomwalters@0: 'current ColorOrder property will be used']) tomwalters@0: else, C=c; end tomwalters@0: end, c=C; tomwalters@0: elseif ~sum(vc==c), c='k'; warning(['Invalid color switch, ',... tomwalters@0: 'default color (black) will be used']) tomwalters@0: end tomwalters@0: end tomwalters@0: if length(c)==1 % single color tomwalters@0: c=LocalColorMap([prefix,c],vc,cn,beta); OneColor=1; tomwalters@0: end tomwalters@0: set(ax,'ColorOrder',c); c=repmat(c,ceil(n/size(c,1)),1); tomwalters@0: if ls~='*', set(ax,'LineStyleOrder',ls); end % LineStyleOrder tomwalters@0: if lw=='/', global LineWidthOrder % LineWidthOrder tomwalters@0: if length(LineWidthOrder) tomwalters@0: lw=repmat(LineWidthOrder(:),ceil(n/length(LineWidthOrder)),1); tomwalters@0: else, lw=0.5; warning(['Undefined LineWidthOrder, ',... tomwalters@0: 'default width (0.5) will be used']) tomwalters@0: end tomwalters@0: end tomwalters@0: if nargin<7 | isempty(alpha), alpha=1; end tomwalters@0: a=repmat(alpha(:),ceil(n/length(alpha)),1); % FaceAlpha tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Log Plot tomwalters@0: if xys tomwalters@0: units=get(ax,'units'); set(ax,'units','points'); tomwalters@0: pos=get(ax,'position'); set(ax,'units',units); tomwalters@0: if strcmp(get(ax,'PlotBoxAspectRatioMode'),'auto') tomwalters@0: set(ax,'PlotBoxAspectRatio',[pos(3),pos(4),1]); tomwalters@0: end tomwalters@0: par=get(ax,'PlotBoxAspectRatio'); tomwalters@0: set(ax,'DataAspectRatio',[par(2),par(1),par(3)]); tomwalters@0: % map coordinates onto unit square tomwalters@0: q=[p1;p2]; xr=Xr; yr=Yr; tomwalters@0: if xs, xr=log10(xr); q(:,1)=log10(q(:,1)); end tomwalters@0: if ys, yr=log10(yr); q(:,2)=log10(q(:,2)); end tomwalters@0: q=q-repmat([xr(1),yr(1),0],2*n,1); tomwalters@0: dx=xr(2)-xr(1); dy=yr(2)-yr(1); tomwalters@0: q=q*diag([1/dx,1/dy,1]); tomwalters@0: q1=q(1:n,:); q2=q(n+1:end,:); tomwalters@0: else, xs=0; ys=0; dx=0; dy=0; xr=0; yr=0; end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Line tomwalters@0: set(ax,'DefaultLineTag','arrow3'); tomwalters@0: if length(lw)==1 tomwalters@0: if lw>0 tomwalters@0: if OneColor & ls~='*' % single color, linestyle, and linewidth tomwalters@0: P=zeros(3*n,3); i=1:n; tomwalters@0: P(3*i-2,:)=p1(i,:); P(3*i-1,:)=p2(i,:); P(3*i,1)=NaN; tomwalters@0: H1=plot3(P(:,1),P(:,2),P(:,3),'LineWidth',lw); tomwalters@0: else % single linewidth tomwalters@0: H1=plot3([p1(:,1),p2(:,1)]',[p1(:,2),p2(:,2)]',... tomwalters@0: [p1(:,3),p2(:,3)]','LineWidth',lw); tomwalters@0: end tomwalters@0: else, H1=[]; end tomwalters@0: else % use LineWidthOrder tomwalters@0: ls=repmat(cellstr(L),ceil(n/size(L,1)),1); tomwalters@0: H1=Zeros; tomwalters@0: for i=1:n tomwalters@0: H1(i)=plot3([p1(i,1),p2(i,1)],[p1(i,2),p2(i,2)],[p1(i,3),p2(i,3)],... tomwalters@0: ls{i},'Color',c(i,:),'LineWidth',lw(i)); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Scale tomwalters@0: ar=get(ax,'DataAspectRatio'); ar=sqrt(3)*ar/norm(ar); tomwalters@0: set(ax,'DataAspectRatioMode','manual'); tomwalters@0: if nargin<4 | isempty(w) % width tomwalters@0: if xys, w=1; tomwalters@0: else, xr=get(ax,'xlim'); yr=get(ax,'ylim'); zr=get(ax,'zlim'); tomwalters@0: w=norm([xr(2)-xr(1),yr(2)-yr(1),zr(2)-zr(1)])/72; tomwalters@0: end tomwalters@0: end tomwalters@0: w=repmat(w(:),ceil(n/length(w)),1); tomwalters@0: if nargin<5 | isempty(h), h=3*w; end % height tomwalters@0: h=repmat(h(:),ceil(n/length(h)),1); tomwalters@0: if nargin>5 & ~isempty(ip) % ip tomwalters@0: i=find(ip==0); ip(i)=w(i); tomwalters@0: ip=repmat(ip(:),ceil(n/length(ip)),1); tomwalters@0: else, ip=-ones(n,1); end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % UserData tomwalters@0: set(ax,'UserData',[get(ax,'UserData');... tomwalters@0: p1,p2,c(1:n,:),w(1:n),h(1:n),ip(1:n),a]); tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Arrowhead tomwalters@0: if xys, whip=[w,h,ip]*sqrt(2)/72; tomwalters@0: w=whip(:,1); h=whip(:,2); ip=whip(:,3); p1=q1; p2=q2; tomwalters@0: end tomwalters@0: W=(p1-p2)./repmat(ar,n,1); tomwalters@0: W=W./repmat(sqrt(sum(W.*W,2)),1,3); % new z direction tomwalters@0: U=[-W(:,2),W(:,1),Zeros]; tomwalters@0: N=sqrt(sum(U.*U,2)); i=find(N num tomwalters@0: tomwalters@0: set(ax,'DefaultSurfaceTag','arrow3','DefaultSurfaceEdgeColor','none'); tomwalters@0: [x,y,z]=cylinder([0,1],m); tomwalters@0: G=surface(x/2,y/2,z); dar=diag(ar); tomwalters@0: X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData'); tomwalters@0: H2=Zeros; [j,k]=size(X); tomwalters@0: for i=1:n % translate, rotate, and scale tomwalters@0: H2(i)=copyobj(G,ax); tomwalters@0: xyz=[w(i)*X(:),w(i)*Y(:),h(i)*Z(:)]*[U(i,:);V(i,:);W(i,:)]*dar; tomwalters@0: x=reshape(xyz(:,1),j,k)+p2(i,1); tomwalters@0: y=reshape(xyz(:,2),j,k)+p2(i,2); tomwalters@0: z=reshape(xyz(:,3),j,k)+p2(i,3); tomwalters@0: LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,... tomwalters@0: x,y,z,a(i),c(i,:),H2(i),oldver); tomwalters@0: end, delete(G); tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Initial Point Marker tomwalters@0: if any(ip>0) tomwalters@0: [x,y,z]=sphere(m); tomwalters@0: G=surface(x*ar(1)/2,y*ar(2)/2,z*ar(3)/2); tomwalters@0: X=get(G,'XData'); Y=get(G,'YData'); Z=get(G,'ZData'); tomwalters@0: H3=zeros(n,1); tomwalters@0: for i=1:n % translate tomwalters@0: if ip(i)>0 tomwalters@0: H3(i)=copyobj(G,ax); tomwalters@0: x=p1(i,1)+X*ip(i); y=p1(i,2)+Y*ip(i); z=p1(i,3)+Z*ip(i); tomwalters@0: LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,... tomwalters@0: x,y,z,a(i),c(i,:),H3(i),oldver); tomwalters@0: end tomwalters@0: end, delete(G); tomwalters@0: else, H3=[]; end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Finish tomwalters@0: if xys, xr=Xr; yr=Yr; zr=Zr; tomwalters@0: set(ax,'DataAspectRatioMode','auto'); tomwalters@0: else, set(fig,'Renderer','OpenGL'); tomwalters@0: w=max(w)*ar/2; ip=max([ip;0])*ar/2; tomwalters@0: xr=[min([p1(:,1)-ip(1);p2(:,1)-w(1)]),max([p1(:,1)+ip(1);p2(:,1)+w(1)])]; tomwalters@0: yr=[min([p1(:,2)-ip(2);p2(:,2)-w(2)]),max([p1(:,2)+ip(2);p2(:,2)+w(2)])]; tomwalters@0: zr=[min([p1(:,3)-ip(3);p2(:,3)-w(3)]),max([p1(:,3)+ip(3);p2(:,3)+w(3)])]; tomwalters@0: if restore tomwalters@0: xr=[min(xr(1),Xr(1)),max(xr(2),Xr(2))]; tomwalters@0: yr=[min(yr(1),Yr(1)),max(yr(2),Yr(2))]; tomwalters@0: zr=[min(zr(1),Zr(1)),max(zr(2),Zr(2))]; tomwalters@0: else, set(ax,'nextplot','replace'); end tomwalters@0: end tomwalters@0: set(ax,'LineStyleOrder',L,'ColorOrder',C,'DefaultLineTag',LT,... tomwalters@0: 'DefaultSurfaceTag',ST,'DefaultSurfaceEdgeColor',EC,... tomwalters@0: 'xlim',xr,'ylim',yr,'zlim',zr); tomwalters@0: if c1==3, set(ax,'CameraViewAngle',get(ax,'CameraViewAngle'),... tomwalters@0: 'PlotBoxAspectRatio',get(ax,'PlotBoxAspectRatio')); tomwalters@0: end tomwalters@0: if nargout, H=[H1(:);H2(:);H3(:)]; end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Update tomwalters@0: function LocalUpdate(fig,ax,ud,sf) tomwalters@0: p1=ud(:,1:3); p2=ud(:,4:6); c=ud(:,7:9); a=ud(:,13); tomwalters@0: w=sf(1)*ud(:,10); h=sf(2)*ud(:,11); ip=sf(3)*ud(:,12); tomwalters@0: H=get(ax,'children'); tag=get(H,'tag'); type=get(H,'type'); tomwalters@0: delete(H(strcmp(tag,'arrow3') & strcmp(type,'surface'))); tomwalters@0: set(fig,'nextplot','add'); set(ax,'ColorOrder',c,'nextplot','add'); tomwalters@0: global ColorOrder, ColorOrder=[]; arrow3(p1,p2,'o0',w,h,ip,a); tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % SetSurface tomwalters@0: function LocalSetSurface(xys,xs,ys,dx,dy,xr,yr,x,y,z,a,c,H,oldver) tomwalters@0: if xys tomwalters@0: x=x*dx+xr(1); y=y*dy+yr(1); tomwalters@0: if xs, x=10.^x; end tomwalters@0: if ys, y=10.^y; end tomwalters@0: end tomwalters@0: if oldver tomwalters@0: set(H,'XData',x,'YData',y,'ZData',z,'FaceColor',c); tomwalters@0: else tomwalters@0: set(H,'XData',x,'YData',y,'ZData',z,'FaceAlpha',a,'FaceColor',c); tomwalters@0: end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % ColorTable tomwalters@0: function [vc,cn]=LocalColorTable(n,beta) tomwalters@0: vc='kymcrgbadefhijlnpqstuvzw'; % valid color codes tomwalters@0: % k y m c tomwalters@0: 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: % r g b a tomwalters@0: 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: % d e f h tomwalters@0: 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: % i j l n tomwalters@0: 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: % p q s t tomwalters@0: 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: % u v z w tomwalters@0: 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: if n % plot color table tomwalters@0: name={'black','yellow','magenta','cyan',... tomwalters@0: 'red','green','blue','apple green',... tomwalters@0: 'dark gray','evergreen','fuchsia','honey',... tomwalters@0: 'indigo','jade','lilac','nutbrown',... tomwalters@0: 'pink','kumquat','sky blue','tan',... tomwalters@0: 'umber','violet','zinc','white'}; tomwalters@0: c=['yhtn';'gjae';'csbi';'plmv';'frqu';'wzdk']; tomwalters@0: clf, set(gcf,'DefaultAxesXTick',[],'DefaultAxesYTick',[],... tomwalters@0: 'DefaultAxesXTickLabel',[],'DefaultAxesYTickLabel',[],... tomwalters@0: 'DefaultAxesXLim',[0,0.75],'DefaultAxesYLim',[0,0.75],... tomwalters@0: 'DefaultRectangleEdgeColor','none'); tomwalters@0: for i=1:24 tomwalters@0: subplot(4,6,i); j=find(vc==c(i)); title(name{j}); tomwalters@0: dark=LocalBrighten(cn(j,:),-beta); tomwalters@0: light=LocalBrighten(cn(j,:),beta); tomwalters@0: rectangle('Position',[0,0.00,0.75,0.25],'FaceColor',dark); tomwalters@0: rectangle('Position',[0,0.25,0.75,0.25],'FaceColor',cn(j,:)); tomwalters@0: rectangle('Position',[0,0.50,0.75,0.25],'FaceColor',light); tomwalters@0: rectangle('Position',[0,0.00,0.75,0.75],'EdgeColor','k'); tomwalters@0: if rem(i,6)==1 tomwalters@0: set(gca,'YTickLabel',{'dark','normal','light'},... tomwalters@0: 'YTick',[0.125,0.375,0.625]); tomwalters@0: if i==19 tomwalters@0: text(0,-0.25,['{\bf\itARROW3} Named Color Table ',... tomwalters@0: '( \beta = ',num2str(beta),' )']); tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % ColorMap tomwalters@0: function [C,failed]=LocalColorMap(c,vc,cn,beta) tomwalters@0: n=length(c); failed=0; C=zeros(n,3); i=1; j=1; tomwalters@0: while 1 tomwalters@0: if isempty(find([vc,'_^']==c(i))), failed=1; break, end tomwalters@0: if sum('_^'==c(i)) tomwalters@0: if i+1>n, failed=1; break, end tomwalters@0: if ~sum(vc==c(i+1)), failed=1; break, end tomwalters@0: cc=cn(find(vc==c(i+1)),:); gamma=beta; tomwalters@0: if c(i)=='_', gamma=-beta; end tomwalters@0: C(j,:)=LocalBrighten(cc,gamma); i=i+2; tomwalters@0: else, C(j,:)=cn(find(vc==c(i)),:); i=i+1; end tomwalters@0: if i>n, break, end, j=j+1; tomwalters@0: end, if n>j, C(j+1:n,:)=[]; end tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Brighten tomwalters@0: function C=LocalBrighten(c,beta) tomwalters@0: C=c.^((1-min(1-sqrt(eps),abs(beta)))^sign(beta)); tomwalters@0: tomwalters@0: %========================================================================== tomwalters@0: % Generate valid value for color, linestyle and linewidth tomwalters@0: function [c,ls,lw]=LocalValidateCLSW(s) tomwalters@0: if nargin<1, c='k'; ls='-'; lw=0.5; tomwalters@0: else tomwalters@0: % identify linestyle tomwalters@0: if findstr(s,'--'), ls='--'; s=strrep(s,'--',''); tomwalters@0: elseif findstr(s,'-.'), ls='-.'; s=strrep(s,'-.',''); tomwalters@0: elseif findstr(s,'-'), ls='-'; s=strrep(s,'-',''); tomwalters@0: elseif findstr(s,':'), ls=':'; s=strrep(s,':',''); tomwalters@0: elseif findstr(s,'*'), ls='*'; s=strrep(s,'*',''); tomwalters@0: else, ls='-'; end tomwalters@0: tomwalters@0: % identify linewidth tomwalters@0: tmp=double(s); tomwalters@0: tmp=find(tmp>45 & tmp<57); tomwalters@0: if length(tmp) tomwalters@0: if any(s(tmp)=='/'), lw='/'; else, lw=str2num(s(tmp)); end tomwalters@0: s(tmp)=''; tomwalters@0: else, lw=0.5; end tomwalters@0: tomwalters@0: % identify color tomwalters@0: if length(s), s=lower(s); tomwalters@0: if length(s)>1, c=s(1:2); tomwalters@0: else, c=s(1); end tomwalters@0: else, c='k'; end tomwalters@0: end