forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrow.m
38 lines (26 loc) · 799 Bytes
/
arrow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% this mfile plots an arrow with tail at the point (x0, y0) and
% tip at the point (x0+a, y0+b). Writing P = [x0, y0] and
% V = [a,b], the the complete call is arrow(P,V, color). The third argument,
% color, is optional. If the call is simply arrow(P,V), the
% arrow will be blue. To get a red arrow, use arrow(P,V, 'r').
function y = arrow(P,V,color)
if nargin < 3
color = 'b';
end
x0 = P(1); y0 = P(2);
a = V(1); b = V(2);
l = max(norm(V), eps);
u = [x0 x0+a]; v = [y0 y0+b];
hchek = ishold;
plot(u,v,color)
hold on
h = l - min(.2*l, .2) ; v = min(.2*l/sqrt(3), .2/sqrt(3) );
a1 = (a*h -b*v)/l;
b1 = (b*h +a*v)/l;
plot([x0+a1, x0+a], [y0+b1, y0+b], color)
a2 = (a*h +b*v)/l;
b2 = (b*h -a*v)/l;
plot([x0+a2, x0+a], [y0+b2, y0+b], color)
if hchek == 0
hold off
end