function flag = IsCrossingWindow(A,R) % Checks if the given conic crosses the given window % (the square of size 2*R centered at the origin) % Nikolai Chernov, March 2012 flag = 0; RR = R*R; F0 = (A(1) + 2*A(2) + A(3))*RR + 2*(A(4) + A(5))*R + A(6); if ((A(1) - 2*A(2) + A(3))*RR + 2*(A(4) - A(5))*R + A(6))*F0 <= 0 flag = 1; return; end if ((A(1) - 2*A(2) + A(3))*RR - 2*(A(4) - A(5))*R + A(6))*F0 <= 0 flag = 1; return; end if ((A(1) + 2*A(2) + A(3))*RR - 2*(A(4) + A(5))*R + A(6))*F0 <= 0 flag = 1; return; end y = (-A(2)*R-A(5))/A(3); if abs(y) < R if (A(1)*RR + 2*A(2)*R*y + A(3)*y*y + 2*A(4)*R + 2*A(5)*y + A(6))*F0 <= 0 flag = 1; return; end end y = (A(2)*R-A(5))/A(3); if abs(y) < R if (A(1)*RR - 2*A(2)*R*y + A(3)*y*y - 2*A(4)*R + 2*A(5)*y + A(6))*F0 <= 0 flag = 1; return; end end x = (-A(2)*R-A(4))/A(1); if abs(x) < R if (A(1)*x*x + 2*A(2)*R*x + A(3)*RR + 2*A(4)*x + 2*A(5)*R + A(6))*F0 <= 0 flag = 1; return; end end x = (A(2)*R-A(4))/A(1); if abs(x) < R if (A(1)*x*x - 2*A(2)*R*x + A(3)*RR + 2*A(4)*x - 2*A(5)*R + A(6))*F0 <= 0 flag = 1; return; end end XY = -[A(1) A(2); A(2) A(3)]\[A(4); A(5)]; if max(abs(XY(1)),abs(XY(2))) < R if (A(1)*XY(1)^2 + 2*A(2)*XY(1)*XY(2) + A(3)*XY(2)^2 + 2*A(4)*XY(1) + 2*A(5)*XY(2) + A(6))*F0 <= 0 flag = 1; return; end end end