Example #1
0
 /// <summary>
 /// Raise the quaternion to a given power.
 /// </summary>
 public Quaternion Pow(Quaternion power)
 {
     return power.Multiply(Ln()).Exp();
 }
Example #2
0
 /// <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());
 }
Example #3
0
 /// <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;
 }
Example #4
0
 public Quaternion Subtract(Quaternion q)
 {
     return new Quaternion(qw - q.qw, qx - q.qx, qy - q.qy, qz - q.qz);
 }
Example #5
0
 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);
 }
Example #6
0
 public Quaternion Add(Quaternion q)
 {
     return new Quaternion(qw + q.qw, qx + q.qx, qy + q.qy, qz + q.qz);
 }
Example #7
0
 /// <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);
 }
Example #8
0
 /// <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);
 }
Example #9
0
 /// <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);
 }
Example #10
0
 Distance(
     Quaternion a,
     Quaternion b
     )
 {
     return a.Subtract(b).Abs;
 }