Skip to content

Commit

Permalink
prevent infinite loop to find the ellipse
Browse files Browse the repository at this point in the history
  • Loading branch information
CPernet committed Jan 30, 2022
1 parent 41dabb8 commit 08e1697
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions skipped_correlation.m
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@
YE = ycmin + bmin * st;
XEmin = XE * ct0 - YE * st0;
YEmin = XE * st0 + YE * ct0;
end;

end

% Previous part found the best matching ellipse for any group of 4 points
% That's fine, but may be there exist better matches using groups of 3 points
Expand All @@ -550,6 +549,7 @@

% Newton iterative method
theta = pi; error = 1;
tic;
while abs(error) > 1e-6
cth = cos(theta); sth = sin(theta);
a1 = a(1) * cth + b(1) * sth; b1 = -a(1) * sth + b(1) * cth;
Expand All @@ -561,6 +561,9 @@
dfth = 2*(da1.*db1 - da2.*db2).*(db1.^2 - db3.^2 + da1.^2 - da3.^2)- 2*(db1.*da1 - db3.*da3).*(da1.^2 - da2.^2 + db1.^2 - db2.^2);
error = - fth / dfth;
theta = theta + error;
if toc > 2 % should have converged quickly
break
end
end
cth = cos(theta); sth = sin(theta);
a1 = a(1) * cth + b(1) * sth; b1 = -a(1) * sth + b(1) * cth;
Expand Down

0 comments on commit 08e1697

Please sign in to comment.