/// <summary> /// SUbtract a quaternion from this quaternion. /// </summary> public Quaternion Subtract( Quaternion q ) { return new Quaternion( qw - q.qw, qx - q.qx, qy - q.qy, qz - q.qz ); }
/// <summary> /// Raise the quaternion to a given power. /// </summary> public Quaternion Pow( Quaternion power ) { return power.Multiply(Ln()).Exp(); }
/// <summary> /// Multiply a quaternion with this quaternion. /// </summary> public Quaternion Multiply( Quaternion q ) { double ci = +qx * q.qw + qy * q.qz - qz * q.qy + qw * q.qx; double cj = -qx * q.qz + qy * q.qw + qz * q.qx + qw * q.qy; double ck = +qx * q.qy - qy * q.qx + qz * q.qw + qw * q.qz; double cr = -qx * q.qx - qy * q.qy - qz * q.qz + qw * q.qw; return new Quaternion(cr, ci, cj, ck); }
/// <summary> /// Multiplies a Quaternion with the inverse of another /// Quaternion (q*q<sup>-1</sup>). Note that for Quaternions /// q*q<sup>-1</sup> is not the same then q<sup>-1</sup>*q, /// because this will lead to a rotation in the other direction. /// </summary> public Quaternion Divide( Quaternion q ) { return Multiply(q.Inverse()); }
/// <summary> /// Add a quaternion to this quaternion. /// </summary> public Quaternion Add( Quaternion q ) { return new Quaternion( qw + q.qw, qx + q.qx, qy + q.qy, qz + q.qz ); }
/// <summary> /// Returns the distance |a-b| of two quaternions, forming a metric space. /// </summary> public static double Distance( Quaternion a, Quaternion b ) { return a.Subtract(b).Abs; }