UnityEditor.MathUtils.ClosestPtRaySphere C# (CSharp) Method

ClosestPtRaySphere() public static method

public static ClosestPtRaySphere ( Ray ray, Vector3 sphereOrigin, float sphereRadius, float &t, Vector3 &q ) : bool
ray UnityEngine.Ray
sphereOrigin Vector3
sphereRadius float
t float
q Vector3
return bool
        public static bool ClosestPtRaySphere(Ray ray, Vector3 sphereOrigin, float sphereRadius, ref float t, ref Vector3 q)
        {
            Vector3 lhs = ray.origin - sphereOrigin;
            float num = Vector3.Dot(lhs, ray.direction);
            float num2 = Vector3.Dot(lhs, lhs) - (sphereRadius * sphereRadius);
            if ((num2 > 0f) && (num > 0f))
            {
                t = 0f;
                q = ray.origin;
                return true;
            }
            float f = (num * num) - num2;
            if (f < 0f)
            {
                f = 0f;
            }
            t = -num - Mathf.Sqrt(f);
            if (t < 0f)
            {
                t = 0f;
            }
            q = ray.origin + (t * ray.direction);
            return true;
        }