Exemple #1
0
        /**
         * Refraction
         *
         * @param incoming incoming vector
         * @param normal normal of the reflectio area
         * @param outgoing result of the computation
         */

        public static Vect3 RefractOn(this Vect3 incoming, Vect3 normal, double refractionIndex)
        {
            //test implementation - working but propably slow
            Vect3 result = incoming.ProjectOnNormal(normal);

            result = result / refractionIndex;
            double quadLen = result.QuadLength();

            if (quadLen >= 1) //total reflection
            {
                result = incoming.ReflectOn(normal);
            }
            else
            {
                result = result + (normal * -System.Math.Sqrt(1 - quadLen));
                result = result.Normalize();
            }
            return(result);
        }