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

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

Revision 495 (checked in by cbc, 11 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 hp=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    arrowmag = .25*(sqrt((xo-xe).*(xo-xe)+(yo-ye).*(yo-ye)));
36    shafttheta = -atan2((ye-yo),(xe-xo));
37    xt = xe-arrowmag.*cos(arrowtheta);
38    yt = ye-arrowmag.*sin(arrowtheta);
39    x1 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
40    y1 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
41    xt = xe-arrowmag.*cos(-arrowtheta);
42    yt = ye-arrowmag.*sin(-arrowtheta);
43    x2 = (xt-xe).*cos(shafttheta)+(yt-ye).*sin(shafttheta)+xe;
44    y2 = (yt-ye).*cos(shafttheta)-(xt-xe).*sin(shafttheta)+ye;
45    x=ones(length(xo),6);
46    y=ones(length(xo),6);
47    x=[xo xe x1 xe x2 NaN*ones(size(xo))]';
48    y=[yo ye y1 ye y2 NaN*ones(size(yo))]';
49    x=x(:);
50    y=y(:);
51    hp=line(x,y,'LineStyle','-','Color',lcolor);
52 %
53 %        Brian O. Blanton
54 %        Curr. in Marine Sciences
55 %        15-1A Venable Hall
56 %        CB# 3300
57 %        Uni. of North Carolina
58 %        Chapel Hill, NC
59 %                 27599-3300
60 %
61 %        919-962-4466
62 %        blanton@marine.unc.edu
63 %
64
65
Note: See TracBrowser for help on using the browser.