title: How to find points of intersection between ellipse and line?
body: <p>I'm completely stuck.
  I have an ellipse, and a line. Line is set by two points, ellipse - by bottom-left and top-right corners. I have to find their points of intersection, using java.
  I tried to solve an equation system:</p>
  
  <pre><code>(1) y = kx + m;
  x^2/a^2 + y^2/b^2 = 1;
  </code></pre>
  
  <p>but I could't make things work properly. I assume it's because of java's coordinate system, but it also may be my own mistake somewherem beacuse I'm confused with it.</p>
  
  <p>Is there any better way to find points of intersection and, if not, how can I get them properly? </p>
  
  <p>Thank you in advance.</p>
  
  <p>Code:</p>
  
  <pre><code>double r1 = in_y2-in_y;
  double r2 = in_x2-in_x;
  double k = r1/r2;
  double m = in_y2 - k*in_x2;
  double a =  Math.abs((double)x2 - (double)x)/2;
  double b =  Math.abs((double)y2 - (double)y)/2;
  
  double A1 = 1/(a*a) + (k*k)/(b*b);
  double B1 = (2*k*m)/b*b;
  double C1 = (m*m)/(b*b);
  double D = Math.sqrt(B1*B1 - 4*A1*C1);
  double ex1 = (-B1 + D/(2*A1));
  double ey1 = k*ex1 + m;
  double ex2 = (-B1 - D/(2*A1));
  double ey2 = k*ex2 + m;
  </code></pre>