コード例 #1
0
ファイル: Sphere.cs プロジェクト: bschwind/Graphics-Toolkit
        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;
        }
コード例 #2
0
ファイル: AABB3D.cs プロジェクト: bschwind/Graphics-Toolkit
 public static AABB3D CreateFromSphere(Sphere s)
 {
     return new AABB3D(s.Pos, new Vector3(s.Radius, s.Radius, s.Radius));
 }