Beispiel #1
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);
        }