示例#1
0
        public static Sphere CreateFromPoints(Vector3[] points)
        {
            Sphere sphere = new Sphere();
            AABB3D box    = AABB3D.CreateFromPoints(points);

            sphere.Pos = box.Pos;
            float maxDist = float.MinValue;

            for (int i = 0; i < points.Length; i++)
            {
                if ((points[i] - sphere.Pos).LengthSquared() > maxDist)
                {
                    maxDist = (points[i] - sphere.Pos).LengthSquared();
                }
            }

            maxDist = (float)Math.Sqrt(maxDist);

            sphere.Radius = maxDist;

            return(sphere);
        }