public static bool Overlap(Circle c1, Circle c2, Circle c3) { if (!CircleOverCircle(c1, c2)) { return(false); } if (CircleInCircle(c1, c2)) { return(CircleOverCircle(c1.Radius < c2.Radius ? c1 : c2, c3)); } float r1 = c1.Radius, r2 = c2.Radius, r3 = c3.Radius; XY o1 = c1.Center, o2 = c2.Center, o3 = c3.Center; float rr1 = r1 * r1; float dist = XY.Distance(o1, o2); float a = 0.5f * ((rr1 - r2 * r2) / dist + dist); float h = Mathf.Sqrt(rr1 - a * a); var i = (o2 - o1) / dist; var o = o1 + i * a; i.Rotate90CCW(); var i1 = o + i * h; var i2 = o - i * h; if (XY.Cross(i1 - o1, o3 - o1) >= 0 && XY.Cross(o3 - o2, i1 - o2) >= 0) { return(XY.SqrDistance(o3, i1) <= r3 * r3); } if (XY.Cross(i2 - o2, o3 - o2) >= 0 && XY.Cross(o3 - o1, i2 - o1) >= 0) { return(XY.SqrDistance(o3, i2) <= r3 * r3); } return(CircleOverCircle(c1, c3) && CircleOverCircle(c2, c3)); }
public bool ContainsPoint(XY p) { for (int i = 0, j = Vertices.Length - 1; i < Vertices.Length; j = i++) { if (XY.Cross(Vertices [i] - Vertices [j], p - Vertices [i]) < 0) { return(false); } } return(true); }
public static float DistancePointToLine(XY p, XY a, XY b) { float s = XY.Cross(p - a, p - b); return(System.Math.Abs(s / p.Length)); }