/// <summary> /// Vector equality check /// </summary> /// <param name="obj">object to check against</param> /// <returns>true if the object is a vector and the components match</returns> public override bool Equals(object obj) { return(obj switch { Quat other => this.X == other.X && this.Y == other.Y && this.Z == other.Z && this.W == other.W, _ => base.Equals(obj) });
/// <summary> /// Linearly interpolate between two quaternions /// </summary> /// <param name="a">first quaternion</param> /// <param name="b">second quaternion</param> /// <param name="t">interpolation factor</param> /// <returns>interpolated quaternion</returns> public static Quat Lerp(Quat a, Quat b, double t) { return((1 - t) * a + t * b); }
/// <summary> /// Dot product of two quaternion vectors /// </summary> /// <param name="a">first quaternion</param> /// <param name="b">second quaternion</param> /// <returns>vector dot product</returns> public static double Dot(Quat a, Quat b) { return(a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W); }
/// <summary> /// Angle between two quaternions /// </summary> /// <param name="a">first quaternion</param> /// <param name="b">second quaternion</param> /// <returns>angle</returns> public static double Angle(Quat a, Quat b) { var d = Dot(a, b); return(Math.Acos(Math.Min(Math.Abs(d), 1) * 2)); }
/// <summary> /// Copy an existing quaternion /// </summary> /// <param name="other">quaternion to copy</param> public Quat(Quat other) : this(other.X, other.Y, other.Z, other.W) { }