function D = DistanceToConicApprx(XY,XYproj,A) % Approximate distance from the point to conic % through the previously computed projected point % (helps evaluate the quality of the projection) % Nikolai Chernov, July 2012 Penalty = 1000; n = size(XY,1); for i=1:n if ~isfinite(norm(XYproj(i,:))) XYproj(i,:) = [100 100]; end end E0 = abs(A(1)*XYproj(:,1).*XYproj(:,1) + 2*A(2)*XYproj(:,1).*XYproj(:,2) +... A(3)*XYproj(:,2).*XYproj(:,2) + 2*A(4)*XYproj(:,1) + 2*A(5)*XYproj(:,2) + A(6)); E1 = 2*sqrt((A(1)*XYproj(:,1)+A(2)*XYproj(:,2)+A(4)*ones(n,1)).^2 +... (A(2)*XYproj(:,1)+A(3)*XYproj(:,2)+A(5)*ones(n,1)).^2); D = sqrt(sum((XYproj-XY).^2,2)) + Penalty*E0./E1; end