InverseSqrtFast() public static method

Returns an approximation of the inverse square root of left number.
This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/
public static InverseSqrtFast ( double x ) : double
x double A number.
return double
コード例 #1
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <param name="result">The normalized vector</param>
        public static void NormalizeFast(ref Vector4 vec, out Vector4 result)
        {
            float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);

            result.X = vec.X * scale;
            result.Y = vec.Y * scale;
            result.Z = vec.Z * scale;
            result.W = vec.W * scale;
        }
コード例 #2
0
        /// <summary>
        /// Scales the Vector4 to approximately unit length.
        /// </summary>
        public void NormalizeFast()
        {
            float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W);

            X *= scale;
            Y *= scale;
            Z *= scale;
            W *= scale;
        }
コード例 #3
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <returns>The normalized vector</returns>
        public static Vector3d NormalizeFast(Vector3d vec)
        {
            double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);

            vec.X *= scale;
            vec.Y *= scale;
            vec.Z *= scale;
            return(vec);
        }
コード例 #4
0
        /// <summary>
        /// Scale a vector to approximately unit length
        /// </summary>
        /// <param name="vec">The input vector</param>
        /// <returns>The normalized vector</returns>
        public static Vector4 NormalizeFast(Vector4 vec)
        {
            float scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W);

            vec.X *= scale;
            vec.Y *= scale;
            vec.Z *= scale;
            vec.W *= scale;
            return(vec);
        }