Beispiel #1
0
        public static (Vector2 center, float radius) Circumcircle(Vector2 a, Vector2 b, Vector2 c)
        {
            Vector2 SqSub(Vector2 p0, Vector2 p1) => Vector2.Scale(p0, p0) - Vector2.Scale(p1, p1);

            Vector2 BA     = a - b;
            Vector2 CA     = a - c;
            Vector2 s13    = SqSub(a, c);            // the heck is this
            Vector2 s21    = SqSub(b, a);
            Vector2 noot   = BA * (s13.x + s13.y) + CA * (s21.x + s21.y);
            Vector2 center = new Vector2(noot.y, -noot.x) / (2 * Mathfs.Determinant(CA, BA));
            float   boop   = -a.x * a.x - a.y * a.y + 2 * center.x * a.x + 2 * center.y * a.y;
            float   radius = Mathf.Sqrt(center.sqrMagnitude - boop);

            return(center, radius);
        }