/// <summary> /// Raise the quaternion to a given power. /// </summary> public Quaternion Pow(Quaternion power) { return power.Multiply(Ln()).Exp(); }
/// <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> /// 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; }
public Quaternion Subtract(Quaternion q) { return new Quaternion(qw - q.qw, qx - q.qx, qy - q.qy, qz - q.qz); }
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); }
public Quaternion Add(Quaternion q) { return new Quaternion(qw + q.qw, qx + q.qx, qy + q.qy, qz + q.qz); }
/// <summary> /// Subtract a quaternion from this quaternion. /// </summary> public Quaternion Subtract(Quaternion q) { return new Quaternion( _w - q._w, _x - q._x, _y - q._y, _z - q._z); }
/// <summary> /// Multiply a quaternion with this quaternion. /// </summary> public Quaternion Multiply(Quaternion q) { double ci = (+_x * q._w) + (_y * q._z) - (_z * q._y) + (_w * q._x); double cj = (-_x * q._z) + (_y * q._w) + (_z * q._x) + (_w * q._y); double ck = (+_x * q._y) - (_y * q._x) + (_z * q._w) + (_w * q._z); double cr = (-_x * q._x) - (_y * q._y) - (_z * q._z) + (_w * q._w); return new Quaternion(cr, ci, cj, ck); }
/// <summary> /// Add a quaternion to this quaternion. /// </summary> public Quaternion Add(Quaternion q) { return new Quaternion( _w + q._w, _x + q._x, _y + q._y, _z + q._z); }
Distance( Quaternion a, Quaternion b ) { return a.Subtract(b).Abs; }