title: Getting the intersection points of 2 circles
body: <p>I need to be able to calculate the intersection points between 2 circles. I know for sure that there will always be 2 intersection points. Not 1, not 0, not infinite, always 2. Here is a diagram of what I'm trying to do:</p>
  
  <p><img src="https://i.stack.imgur.com/Sdus7.png" alt=""></p>
  
  <p>Here is my current attempt:</p>
  
  <pre><code>public static List&lt;Vector2&gt; intersect(Vector3 c1, Vector3 c2, float rad1, float rad2)
  {
      List&lt;Vector2&gt; rLp = new List&lt;Vector2&gt;();
      float d = Vector2.Distance(c1, c2);
  
      if (d &gt; (rad1 + rad2))
          return rLp;
      else if (d == 0 &amp;&amp; rad1 == rad2)
          return rLp;
      else if ((d + Mathf.Min(rad1, rad2)) &lt; Mathf.Max(rad1, rad2))
          return rLp;
      else
      {
          float a = (rad1 * rad1 - rad2 * rad2 + d * d) / (2 * d);
          float h = Mathf.Sqrt(rad1 * rad1 - a * a);
  
          Vector2 p2 = new Vector2((float)(c1.x + (a * (c2.x - c1.x)) / d), (float)(c1.y + (a * c2.y - c1.y) / d));
  
          Vector2 i1 = new Vector2((float)(p2.x + (h * (c2.y - c1.y)) / d), (float)(p2.y - (h * (c2.x - c1.x)) / d));
          Vector2 i2 = new Vector2((float)(p2.x - (h * (c2.y - c1.y)) / d), (float)(p2.y + (h * (c2.x - c1.x)) / d));
  
          if (d == (rad1 + rad2))
              rLp.Add(i1);
          else
          {
              rLp.Add(i1);
              rLp.Add(i2);
          }
  
          return rLp;
      }
  }
  </code></pre>
  
  <p>It gives me the following result:</p>
  
  <p><img src="https://i.stack.imgur.com/qxkGm.png" alt=""></p>
  
  <p>As you can see, the white squares representing the intercepting points between the two circles are in the wrong place. I could really use some help in this area. Can anyone see what's wrong?</p>