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

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

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

Initial import of Stark code.

Line 
1 %
2 % DRAWVEC draw arrows for vectors
3 %
4 % DRAWVEC drawvec(xo,yo,um,vm,atheta,lcolor) is a routine to
5 %         draw vectors. This is a fairly low-level routine
6 %         in that in does no scaling to the vectors.  This function
7 %         is called primarily by VECPLOT and returns the handle
8 %         of the vector object drawn.
9 %
10 % Inputs: xo,yo  - vector origins; arrow eminates from this point
11 %         um,vm  - vector magnitudes
12 %         atheta - arrow-head angle, in degrees
13 %         lcolor - linecolor , 'r' = red, etc.
14 %
15 % Outputs: hp    - the handle to the vector object drawn
16 %
17 % Call as:  hp=drawvec(xo,yo,um,vm,atheta,lcolor)
18 %
19 % Written by: Brian O. Blanton
20 %
21    function [hshaft,hhead]=drawvec(xo,yo,um,vm,atheta,lcolor)
22    fac = 3.14159/180.;
23    arrowtheta = atheta*fac;
24
25 % columnate the input vectors to ensure they are
26 % column-vectors, not row-vectors
27    xo=xo(:);
28    yo=yo(:);
29    um=um(:);
30    vm=vm(:);
31
32 % compute and draw arrow shaft
33    xe = xo + um;
34    ye = yo + vm;
35 % ALTER THIS LINE FOR SCALING (.25 term)
36    arrowmag = .25*(sqrt((xo-xe).*(xo-xe)+(yo-ye).*(yo-ye)));
37    shafttheta = -atan2((ye-yo),(xe-xo));
38    xt = xe-arrowmag.*cos(arrowtheta);
39    yt = ye-arrowmag.*sin(arrowtheta);
40    x1 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
41    y1 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
42    xt = xe-arrowmag.*cos(-arrowtheta);
43    yt = ye-arrowmag.*sin(-arrowtheta);
44    x2 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
45    y2 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
46 %   x=ones(length(xo),6);
47 %   y=ones(length(xo),6);
48 %   x=[xo xe x1 xe x2 NaN*ones(size(xo))]';
49 %   y=[yo ye y1 ye y2 NaN*ones(size(yo))]';
50    xhead=[x1 xe x2 NaN*ones(size(xo))]';
51    yhead=[y1 ye y2 NaN*ones(size(yo))]';
52    xshaft=[xo xe NaN*ones(size(xo))]';
53    yshaft=[yo ye NaN*ones(size(yo))]';
54    xhead=xhead(:);
55    yhead=yhead(:);
56    xshaft=xshaft(:);
57    yshaft=yshaft(:);
58    hhead=line(xhead,yhead,'LineStyle','-','Color',lcolor); hold on;
59    hshaft=line(xshaft,yshaft,'LineStyle','-','Color',lcolor);
60 %
61 %        Brian O. Blanton
62 %        Curr. in Marine Sciences
63 %        15-1A Venable Hall
64 %        CB# 3300
65 %        Uni. of North Carolina
66 %        Chapel Hill, NC
67 %                 27599-3300
68 %
69 %        919-962-4466
70 %        blanton@marine.unc.edu
71 %
72
73
Note: See TracBrowser for help on using the browser.