-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotArrow.m
More file actions
75 lines (49 loc) · 1.34 KB
/
annotArrow.m
File metadata and controls
75 lines (49 loc) · 1.34 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function annotArrow(hlines, x0)
n = length(hlines);
xdata = get(hlines, 'Xdata');
ydata = get(hlines, 'Ydata');
%x = vertcat(x{:});
%y = vertcat(y{:});
k = ceil(n/2);
x = xdata{k};
y = ydata{k};
l = getPerpLine(hlines(k), x0);
[u, v] = l([-100 100]);
p1 = [u(1) v(1)];
p2 = [u(2) v(2)];
arrow(p1, p2);
line(u, v);
%annotation('arrow', u, v);
%plot(u, v);
end
function fun = getPerpLine(hline, x0)
xcurve = get(hline, 'Xdata');
ycurve = get(hline, 'Ydata');
hAx = ancestor(hline, 'axes');
xlim = get(hAx, 'XLim');
ylim = get(hAx, 'YLim');
s = abs(diff(ylim)./diff(xlim));
px = diff(xcurve);
py = diff(ycurve);
[~, i] = min(abs(xcurve - x0));
x0 = xcurve(i);
y0 = ycurve(i);
%plot(x0, y0, 'o', 'LineWidth', 10);
vx = -py(i)/s;
vy = px(i)*s;
function [x, y] = straightline(t)
x = x0 + t*vx;
y = y0 + t*vy;
end
fun = @straightline;
end
function [x, y] = intersect(curvex, curvey, secant)
function d = distance(t)
[secx, secy] = secant(t);
dx = secx - curvex;
dy = secy - curvey;
d = min(dx.^2 + dy.^2);
end
t = fminsearch(@distance, t0);
[x, y] = secant(t);
end