Пример #1
0
 /// <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)
     });
Пример #2
0
 /// <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);
 }
Пример #3
0
 /// <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);
 }
Пример #4
0
        /// <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));
        }
Пример #5
0
 /// <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)
 {
 }