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

root/gliderproc/trunk/MATLAB/opnml/FEM/newdrawvec.m

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

Initial import of Stark code.

Line 
1 function hp=drawvec(xo,yo,um,vm,varargin)
2 %DRAWVEC draw arrows for vectors
3 % DRAWVEC draws vectors on the current axes, given vector origins
4 % and component magnitudes.  No scaling is performed; use
5 % VECPLOT to scale and draw the vectors.  This function
6 % is called primarily by VECPLOT and returns the handle
7 % of the vector object drawn.
8 %
9 % Inputs: xo,yo  - vector origins; arrow eminates from this point
10 %         um,vm  - vector magnitudes
11 %
12 % Outputs: hp    - the handle to the vector object drawn
13 %
14 % PN/PV pairs accepted by DRAWVEC:
15 %       ArrowAngle - angle (in degrees) that the arrow head wings
16 %                    make with the shaft. default=25
17 %       ArrowFac   - Length ratio of arrow head relative to
18 %                    shaft. default=.25
19 %
20 % All other pn-pv pairs are passed to LINE
21
22 % Call as:  hp=drawvec(xo,yo,um,vm,pn1,pv1,...);
23 %
24
25 fac = 3.14159/180.;
26
27 % Default PN/PV for DRAWVEC
28 ArrowAngle=25;
29 ArrowFac=.25;
30
31 % Strip off parameter/value pairs in varargin not related to
32 % "line" object properties.
33 k=1;
34 while k<length(varargin),
35   switch lower(varargin{k}),
36     case 'arrowangle',
37       ArrowAngle=varargin{k+1};
38       varargin([k k+1])=[];
39     case 'arrowfac',
40       ArrowFac=varargin{k+1};
41       varargin([k k+1])=[];
42     otherwise
43       k=k+2;
44   end;
45 end;
46 if length(varargin)<2
47    varargin={};
48 end
49
50 % Conv to rads
51 arrowtheta = ArrowAngle*fac;
52
53 % columnate the input vectors to ensure they are
54 % column-vectors, not row-vectors
55 xo=xo(:);
56 yo=yo(:);
57 um=um(:);
58 vm=vm(:);
59
60 % compute and draw arrow shaft
61 xe = xo + um;
62 ye = yo + vm;
63 arrowmag = ArrowFac*(sqrt((xo-xe).*(xo-xe)+(yo-ye).*(yo-ye)));
64 shafttheta = -atan2((ye-yo),(xe-xo));
65 xt = xe-arrowmag.*cos(arrowtheta);
66 yt = ye-arrowmag.*sin(arrowtheta);
67 x1 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
68 y1 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
69 xt = xe-arrowmag.*cos(-arrowtheta);
70 yt = ye-arrowmag.*sin(-arrowtheta);
71 x2 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
72 y2 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
73 x=ones(length(xo),6);
74 y=ones(length(xo),6);
75 x=[xo xe x1 xe x2 NaN*ones(size(xo))]';
76 y=[yo ye y1 ye y2 NaN*ones(size(yo))]';
77 x=x(:);
78 y=y(:);
79 hp=line(x,y,varargin{:});
80
81 %
82 %LabSig  Brian O. Blanton
83 %        Department of Marine Sciences
84 %        12-7 Venable Hall
85 %        CB# 3300
86 %        University of North Carolina
87 %        Chapel Hill, NC
88 %                 27599-3300
89 %
90 %        brian_blanton@unc.edu
91 %
Note: See TracBrowser for help on using the browser.