Пример #1
0
        // Check if two bounding spheres intersect
        public static bool IntersectTest(BoundingSphere a, BoundingSphere b)
        {
            Vec3 dist = b.center - a.center;
            double radius = a.radius + b.radius;

            return (dist.ComputeMagnitudeSquared() < radius * radius);
        }
Пример #2
0
        // Return a BoudingSphere which fully contains the specified bounding sphere and vertex
        // Like Combine, but simpler because the added point hasn't got a radius
        public static BoundingSphere Expand(BoundingSphere a, Vec3 b)
        {
            Vec3 dif = b - a.center;
            double distance = dif.ComputeMagnitude();

            // degenerate cases... one sphere completely inside the other
            if (a.radius > distance)
                return new BoundingSphere { center = a.center, radius = a.radius };

            // otherwise some actual work must be done... not too bad though
            double radius = (distance + a.radius) * 0.5;
            Vec3 center = a.center + Vec3.Normalize(dif, radius - a.radius);

            return new BoundingSphere { center = center, radius = radius };
        }