Represents a bounding sphere.
Example #1
0
        /// <summary>
        /// Creates a merged bounding sphere.
        /// </summary>
        /// <param name="original">
        /// The original.
        /// </param>
        /// <param name="additional">
        /// The additional.
        /// </param>
        /// <returns>
        /// The merged bounding sphere.
        /// </returns>
        public static BoundingSphere CreateMerged(BoundingSphere original, BoundingSphere additional)
        {
            var vector = additional.center - original.center;
            var distance = vector.Length;
            if (original.radius + additional.radius >= distance)
            {
                if (original.radius - additional.radius >= distance)
                {
                    return original;
                }

                if (additional.radius - original.radius >= distance)
                {
                    return additional;
                }
            }

            var vector3 = vector * (1 / distance);
            var r1 = Math.Min(-original.radius, distance - additional.radius);
            var r2 = (Math.Max(original.radius, distance + additional.radius) - r1) * 0.5;
            return new BoundingSphere { Center = original.Center + (vector3 * (r2 + r1)), Radius = r2 };
        }
Example #2
0
 /// <summary>
 /// Determines if the sphere intersects with the specified sphere.
 /// </summary>
 /// <param name="sphere">
 /// The sphere to check against.
 /// </param>
 /// <returns>
 /// True if the spheres intersect.
 /// </returns>
 public bool Intersects(BoundingSphere sphere)
 {
     double d2 = this.center.DistanceToSquared(sphere.center);
     return (this.radius * this.radius) + (2.0 * this.radius * sphere.radius) + (sphere.radius * sphere.radius) > d2;
 }
Example #3
0
        /// <summary>
        /// Determines if the sphere intersects with the specified sphere.
        /// </summary>
        /// <param name="sphere">
        /// The sphere to check against.
        /// </param>
        /// <returns>
        /// True if the spheres intersect.
        /// </returns>
        public bool Intersects(BoundingSphere sphere)
        {
            double d2 = this.center.DistanceToSquared(sphere.center);

            return((this.radius * this.radius) + (2.0 * this.radius * sphere.radius) + (sphere.radius * sphere.radius) > d2);
        }