已知圆上三点坐标求圆心和半径

时间:2021-05-11 09:43:13

R半径 PCenter圆点坐标 

        public void GetCircular(PointF P1,PointF P2,PointF P3,ref float R,ref PointF PCenter)
        {
            float a = 2 * (P2.X - P1.X);
            float b = 2 * (P2.Y - P1.Y);
            float c = P2.X * P2.X + P2.Y * P2.Y - P1.X * P1.X - P1.Y * P1.Y;
            float d = 2 * (P3.X - P2.X);
            float e = 2 * (P3.Y - P2.Y);
            float f = P3.X * P3.X + P3.Y * P3.Y - P2.X * P2.X - P2.Y * P2.Y;
            float x = (b * f - e * c) / (b * d - e * a);
            float y = (d * c - a * f) / (b * d - e * a);
            float r = (float)Math.Sqrt( (double)((x - P1.X) * (x - P1.X) + (y - P1.Y) * (y - P1.Y)));
            R = r;
            PointF pc = new PointF(x,y);
            PCenter = pc;
        }