0

Can anyone tell me how to get the inverse of quaternion.

q-1=q'/(q*q')

q' = Quaternion conjugate

(q*q') = norm of a quaternion * norm of a quaternion

I have my quaternion: (C language)

quat.x = 0.0;
quat.y = 1.0;
quat.z = 0.0;
quat.w = 45.0;

First conjugate:

quat.conjx =  0.0;
quat.conjy = -1.0;
quat.conjz =  0.0;
quat.conjw = 45.0;

Next: Norm

quat.norm = sqrt(quat.x*quat.x + quat.y*quat.y + quat.z*quat.z + quat.w*quat.w);

Ok but... How do I calculate the inverse using C syntax? This is right?:

quat.invx = quat.conjx / (quat.norm*quat.norm);
quat.invy = quat.conjy / (quat.norm*quat.norm);
quat.invz = quat.conjz / (quat.norm*quat.norm);
quat.invw = quat.conjw / (quat.norm*quat.norm);

Thank you very much for your help

Javier Ramírez
  • 1,001
  • 2
  • 12
  • 23
  • In this post using C syntax? – Javier Ramírez Mar 15 '13 at 05:39
  • This is not a duplicate. The other question answered in Haskell. – 101010 Feb 19 '16 at 14:31
  • The formula for the inverse is as follows: `inverse = conjugate(q) / norm(q)` [I wrote a C-library that does this.](https://github.com/dagostinelli/hypatia/blob/master/src/quaternion.c) I would create a new answer, but this is a closed question. – 101010 Feb 19 '16 at 14:31

1 Answers1

3

The conjugate of a quaternion x + i y + j z + k w is defined as x - i y - j z - k w. There aren't three separate conjugates. Also, don't try putting norm, invx, invy, invz, conjx, etc. into your quaternion structure. Just write:

typedef struct {
    double x;
    double y;
    double z;
    double w;
} quaternion;

and then write functions that take quaternions as arguments and return them. For example, write:

// Construct and return the conjugate of q.
quaternion q_conjugate(const quaternion q) { ...}
// Divide quaternion q by scalar d
quaternion q_divide(const quaternion q, const double divisor) {...}
// Compute the squared norm of q
double q_squared_norm(const quaternion q) {...}
// Compute the inverse of q
quaternion q_inverse(const quaternion q);
Eric Jablow
  • 7,874
  • 2
  • 22
  • 29
  • Ah then the conjugate of my quaternion is 0-1-0-45 = -46.0 ? – Javier Ramírez Mar 15 '13 at 05:44
  • No, it's 0.0 - 1.0 i - 0.0 j - 45.0 k. Just as a complex number *x* + i *y* can be thought of as a vector in the plane, a quaternion can be thought of as a vector in R^4. Its conjugate is another vector in R^4. Adding the components is meaningless. – Eric Jablow Mar 15 '13 at 06:14
  • All right but, can you tell me how to do calculate q_inverse using C syntax. Thank you – Javier Ramírez Mar 15 '13 at 16:36