/// <summary> /// Calculates the distance between two vectors /// </summary> /// <param name="value1">The first vector</param> /// <param name="value2">The second vector</param> /// <returns>The distance between the two vectors</returns> public static float Distance(Vector4 value1, Vector4 value2) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; float w = value1.W - value2.W; return(Mathematics.Sqrt(x * x + y * y + z * z + w * w)); }
/// <summary> /// Exponentiates a quaternion /// </summary> /// <param name="value">The quaternion to exponentiate</param> /// <returns>The exponentiated quaternion</returns> public static Quaternion Exponential(Quaternion value) { Quaternion result = new Quaternion(); float angle = Mathematics.Sqrt((value.X * value.X) + (value.Y * value.Y) + (value.Z * value.Z)); float sin = Mathematics.Sin(angle); if (Mathematics.Abs(sin) >= 0f) { float coeff = sin / angle; result.X = coeff * value.X; result.Y = coeff * value.Y; result.Z = coeff * value.Z; } else { result = value; } result.W = Mathematics.Cos(angle); return(result); }
/// <summary> /// Calculates the length of the quaternion /// </summary> /// <returns>The length of the vector</returns> public static float Magnitude(Quaternion value) => Mathematics.Sqrt(Mathematics.Pow(value.X, 2)) + Mathematics.Sqrt(Mathematics.Pow(value.Y, 2)) + Mathematics.Sqrt(Mathematics.Pow(value.Z, 2)) + Mathematics.Sqrt(Mathematics.Pow(value.W, 2));
/// <summary> /// Calculates the length of the vector /// </summary> /// <returns>May be preferred when only the relative length is needed and speed is of the essence</returns> public static float Magnitude(Vector4 value) => Mathematics.Sqrt(Mathematics.Pow(value.X, 2) + Mathematics.Pow(value.Y, 2) + Mathematics.Pow(value.Z, 2) + Mathematics.Pow(value.W, 2));