Exemplo n.º 1
0
        public static SphereF Merge(SphereF a, SphereF b)
        {
            if (a == b)
            {
                return(a);
            }

            var c1 = a.Origin;
            var c2 = b.Origin;
            var r1 = a.Radius;
            var r2 = b.Radius;

            var r = (c1 - c2).Length();

            if (r + r1 < r2)
            {
                return(b);
            }
            if (r + r2 < r1)
            {
                return(a);
            }

            var newR = (r1 + r2 + r) * 0.5f;
            var newC = c1 + (c2 - c1) * (newR - r1) / r;

            return(new SphereF(newC, newR));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the given sphere intersects the current instance of <see cref="ConeF"/>.
        /// </summary>
        /// <param name="sphere">The sphere to check.</param>
        /// <returns>True if the given sphere intersects the current instance of <see cref="ConeF"/>; False otherwise.</returns>
        public bool Intersects(SphereF sphere)
        {
            float sinAngle = MathEx.Sin(Angle);
            float cosAngle = MathEx.Cos(Angle);
            float invSin   = 1.0f / sinAngle;
            float cosSqr   = cosAngle * cosAngle;

            Vector3F cmv       = sphere.Origin - Origin;
            Vector3F d         = cmv + (sphere.Radius * invSin) * Axis;
            float    lengthSqr = d.LengthSquared();
            float    e         = Vector3F.Dot(d, Axis);

            if (e > 0 && e * e >= lengthSqr * cosSqr)
            {
                float sinSqr = sinAngle * sinAngle;
                lengthSqr = cmv.LengthSquared();
                e         = -Vector3F.Dot(cmv, Axis);
                if (e > 0.0f && e * e >= lengthSqr * sinSqr)
                {
                    float rSqr = sphere.Radius * sphere.Radius;
                    return(lengthSqr <= rSqr);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
 public bool Equals(SphereF v, float epsilon)
 {
     if (!Origin.Equals(ref v.Origin, epsilon))
     {
         return(false);
     }
     if (Math.Abs(Radius - v.Radius) > epsilon)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public bool Intersects(ref SphereF s)
        {
            float x         = s.Origin.X - Origin.X;
            float y         = s.Origin.Y - Origin.Y;
            float z         = s.Origin.Z - Origin.Z;
            float lengthSqr = x * x + y * y + z * z;
            float r         = s.Radius + Radius;

            if (lengthSqr > r * r)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
 public SphereF(SphereF source)
 {
     Origin = source.Origin;
     Radius = source.Radius;
 }
Exemplo n.º 6
0
 public bool Contains(SphereF s)
 {
     return(Contains(ref s));
 }
Exemplo n.º 7
0
 public bool Contains(ref SphereF s)
 {
     return((Origin - s.Origin).Length() + s.Radius <= Radius);
 }
Exemplo n.º 8
0
 public bool Intersects(SphereF s)
 {
     return(Intersects(ref s));
 }
Exemplo n.º 9
0
 public Sphere(SphereF source)
 {
     Origin = source.Origin.ToVector3();
     Radius = source.Radius;
 }