https://math.stackexchange.com/questions/256100/how-can-i-find-the-points-at-which-two-circles-intersect https://gist.github.com/jupdike/bfe5eb23d1c395d8a0a1a4ddd94882ac
(c0 Point, r0 float64, c1 Point, r1 float64)
| 818 | // https://math.stackexchange.com/questions/256100/how-can-i-find-the-points-at-which-two-circles-intersect |
| 819 | // https://gist.github.com/jupdike/bfe5eb23d1c395d8a0a1a4ddd94882ac |
| 820 | func intersectionCircleCircle(c0 Point, r0 float64, c1 Point, r1 float64) (Point, Point, bool) { |
| 821 | R := c0.Sub(c1).Length() |
| 822 | if R < math.Abs(r0-r1) || r0+r1 < R || c0.Equals(c1) { |
| 823 | return Point{}, Point{}, false |
| 824 | } |
| 825 | R2 := R * R |
| 826 | |
| 827 | k := r0*r0 - r1*r1 |
| 828 | a := 0.5 |
| 829 | b := 0.5 * k / R2 |
| 830 | c := 0.5 * math.Sqrt(2.0*(r0*r0+r1*r1)/R2-k*k/(R2*R2)-1.0) |
| 831 | |
| 832 | i0 := c0.Add(c1).Mul(a) |
| 833 | i1 := c1.Sub(c0).Mul(b) |
| 834 | i2 := Point{c1.Y - c0.Y, c0.X - c1.X}.Mul(c) |
| 835 | return i0.Add(i1).Add(i2), i0.Add(i1).Sub(i2), true |
| 836 | } |