-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseekline.m
141 lines (127 loc) · 3.54 KB
/
seekline.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function [pnlines]=seekline(bpnt,cang1,sang1,fa1,fa2,xc,ss)
% SEEKLINE
% FAUCCAL supporting function for tracing a line
% Estimate next line's point position
gnpnt(1)=cang1*fa1+bpnt(1);
gnpnt(2)=sang1*fa1+bpnt(2);
cbr1=0;
pnen=2;
pnlines=bpnt;
efan=nan;
sfan=nan;
while cbr1<3
clear xcn2
% Call line for tracing point
[xcn]=seekpnt(gnpnt,fa1,xc);
[xcn2]=xcn;
% Seek point on opposite direction for later
% segment length recalculation
gnpnt(1)=-cang1*fa2+bpnt(1);
gnpnt(2)=-sang1*fa2+bpnt(2);
[xcn2(:,2)]=seekpnt(gnpnt,fa2,xc);
if length(xcn2(xcn2>0))>2
segs=zeros(2,1);
for i=1:2
segs(i)=norm([xcn2(1,i)-bpnt(1);xcn2(2,i)-bpnt(2)]);
end
fa1_t=(2*segs(1)+segs(2))/3;
if (~(fa1_t/fa1>1.5) && ~(fa1_t/fa1<0.68))
fa1=fa1_t;
end
end
xcn=xcn2(:,1);
% Calculate angle difference between two sequent
% segments
if ss==1
efn=(xcn(2,1)-bpnt(2))/(xcn(1,1)-bpnt(1));
ang_dif=abs(abs(atan(efn))-abs(atan(efan)));
else
sfn=(xcn(2,1)-bpnt(2))\(xcn(1,1)-bpnt(1));
ang_dif=abs(abs(acot(sfn))-abs(acot(sfan)));
end
% Test if above segments are collinear
if (length(xcn(xcn>0))>0 && ((ss==1 && (ang_dif<0.03 || isnan(efan)))...
|| (ss==2 && (ang_dif<0.03 || isnan(sfan)))))
if ss==1
efan=efn;
else
sfan=sfn;
end
pnlines(pnen,:)=[xcn(1,1) xcn(2,1)];
% Make new point a base point and estimate next line's
% point position
bpnt(:)=xcn(:,1);
gnpnt(1)=cang1*fa1+bpnt(1);
gnpnt(2)=sang1*fa1+bpnt(2);
cbr1=0;
pnen=pnen+1;
else
cbr1=cbr1+1;
gnpnt(1)=cang1*(1+cbr1)*fa1+bpnt(1);
gnpnt(2)=sang1*(1+cbr1)*fa1+bpnt(2);
end
end
efan=nan;
sfan=nan;
cbr1=0;
fa1=fa2;
if ~isempty(pnlines)
bpnt(:)=pnlines(1,:);
end
gnpnt(1)=-cang1*fa2+bpnt(1);
gnpnt(2)=-sang1*fa2+bpnt(2);
% Same proceedure as above for the other half line
while cbr1<3
clear xcn2
[xcn]=seekpnt(gnpnt,fa2,xc);
[xcn2]=xcn;
gnpnt(1)=cang1*fa1+bpnt(1);
gnpnt(2)=sang1*fa1+bpnt(2);
[xcn2(:,2)]=seekpnt(gnpnt,fa1,xc);
if length(xcn2(xcn2>0))>2
for i=1:2
segs(i)=norm([xcn2(1,i)-bpnt(1);xcn2(2,i)-bpnt(2)]);
end
fa2_t=(2*segs(1)+segs(2))/3;
if (~(fa2_t/fa2>1.5) && ~(fa2_t/fa2<0.68))
fa2=fa2_t;
end
end
xcn=xcn2(:,1);
if ss==1
efn=(xcn(2,1)-bpnt(2))/(xcn(1,1)-bpnt(1));
ang_dif=abs(abs(atan(efn))-abs(atan(efan)));
else
sfn=(xcn(2,1)-bpnt(2))\(xcn(1,1)-bpnt(1));
ang_dif=abs(abs(acot(sfn))-abs(acot(sfan)));
end
if (length(xcn(xcn>0))>0 && ((ss==1 && (ang_dif<0.03 || isnan(efan)))...
|| (ss==2 && (ang_dif<0.03 || isnan(sfan)))))
if ss==1
efan=efn;
else
sfan=sfn;
end
pnlines(pnen,:)=[xcn(1,1) xcn(2,1)];
bpnt(:)=xcn(:,1);
gnpnt(1)=-cang1*fa2+bpnt(1);
gnpnt(2)=-sang1*fa2+bpnt(2);
cbr1=0;
pnen=pnen+1;
else
cbr1=cbr1+1;
gnpnt(1)=-cang1*(1+cbr1)*fa2+bpnt(1);
gnpnt(2)=-sang1*(1+cbr1)*fa2+bpnt(2);
end
end
if size(pnlines,1)<4
pnlines=[];
end
% Sort line's points in ascending(descending) order
if ~isempty(pnlines)
[srt,srtind]=sort(pnlines(:,ss));
for k=1:size(pnlines(:,ss))
pnlntmp(k,:)=[pnlines(srtind(k),1) pnlines(srtind(k),2)];
end
pnlines(:,:)=pnlntmp;
end