function handles = plot_2d_vector( origin,myVector,name,varargin ) x1=origin(1); y1=origin(2); z1=origin(3); x2=myVector(1); y2=myVector(2); z2=myVector(3); text((x2-x1)/2,(y2-y1)/2,(z2-z1)/2,['\it', name],'HorizontalAlignment','left','FontSize',18) % % plot_2d_vector - plots an arrow to the current plot % % format: handles = plot_2d_vector( x1,y1,x2,y2 [,options...] ) % % input: x1,y1 - starting point % x2,y2 - end point % options - come as pairs of "property","value" as defined for "line" and "patch" % controls, see matlab help for listing of these properties. % note that not all properties where added, one might add them at the end of this file. % % additional options are: % 'headwidth': relative to complete arrow size, default value is 0.07 % 'headheight': relative to complete arrow size, default value is 0.15 % (encoded are maximal values if pixels, for the case that the arrow is very long) % % output: handles - handles of the graphical elements building the arrow % % Example: plot_2d_vector( origin, vector,'linewidth',2,'color',[0.5 0.5 0.5],'facecolor',[0.5 0.5 0.5] ); % plot_2d_vector( origin, vector,'linewidth',2,'headwidth',0.25,'headheight',0.33 ); % ============================================= % constants (can be edited) % ============================================= alpha = 0.15; % head length beta = 0.07; % head width max_length = 22; max_width = 10; % ============================================= % check if head properties are given % ============================================= % if ratio is always fixed, this section can be removed! if ~isempty( varargin ) for c = 1:floor(length(varargin)/2) try switch lower(varargin{c*2-1}) % head properties - do nothing, since handled above already case 'headheight',alpha = max( min( varargin{c*2},1 ),0.01 ); case 'headwidth', beta = max( min( varargin{c*2},1 ),0.01 ); end catch fprintf( 'unrecognized property or value for: %s\n',varargin{c*2-1} ); end end end % ============================================= % calculate the arrow head coordinates % ============================================= den = x2 - x1 + eps; % make sure no devision by zero occurs teta = atan( (y2-y1)/den ) + pi*(x2