-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathderive_angle.m
executable file
·62 lines (44 loc) · 1.5 KB
/
derive_angle.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
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
% Finds the x value of the point of intersection and the angle between the
% tangent of a 4th order polynomial, and a straight line.
% Inputs:
% f_lef: equation of a quartic function
% f_line: equation of a line
% I: an image file
% side_on: "string input" representing the side the angle is on
% boundary: set of XY points representing the boundary of the trace
function [angle_deg, sol_x] = derive_angle(f_lef, f_line, I, side_on, boundary)
syms t;
A = f_lef(1);
B = f_lef(2);
C = f_lef(3);
D = f_lef(4);
E = f_lef(5);
level_num = polyval(f_line, 1);
POI_mat = solve( A*t^4 + B*t^3 + C*t^2 + D*t + E - level_num, t );
mat_size = size(POI_mat);
num_rows = mat_size(1);
im_siz = size(boundary);
half_wid = im_siz(1)/2 + boundary(1,2);
if(strcmp(side_on, 'left'))
for i=1:num_rows
if isreal(POI_mat(i))
if (eval(POI_mat(i)) < half_wid)
sol_x = POI_mat(i);
end
end
end
end
if(strcmp(side_on, 'right'))
for i=1:num_rows
if isreal(POI_mat(i))
if (eval(POI_mat(i)) > half_wid)
sol_x = POI_mat(i);
end
end
end
end
der1 = polyder(f_lef);
m1 = polyval(der1, eval(sol_x));
angle = atan(m1);
angle_deg = abs((angle/pi)*180);
end