title: Align IMU orientations and then get relative rotations
body: <p>I am using two IMUs of the same type (BHI160, i.e. orientation is relative to the north and on alignment with north, the IMU's local y-axis points into the north direction) on two objects, let's say pens, with the added difficulty that if I place the two objects in parallel, both IMUs' z-axes point upwards, but one IMU is rotated 180° around the z-axis relative to the other.</p>
  
  <p>Now, if I understand the math here correctly, the quaternion data I receive from an IMU is the half-angle-rotation relative to the north direction, so that <code>q * north_dir * q_inv = IMU_y_axis</code> (with <code>north_dir</code> and <code>IMU_y_axis</code> being 3D vectors in global space, or pure quaternions for the sake of this computation).</p>
  
  <p>Due to the rotation of the IMUs, I would assume that when both pens are pointing in the same direction, I should be able to compute the second pen's orientation as <code>q_2 = q_rot_z * q_1</code>, where <code>q_rot_z</code> equals a 90° rotation around the z-axis -- following the intuition that if I point both pens towards the north, I would obtain the global direction of pen 2's y-axis (i.e. pen 1's y-axis rotated around the z-axis by 180°) by computing <code>q_rot_z * north_dir * q_rot_z_inv</code></p>
  
  <p>Is it thus correct that if I want to know the relative rotation of the pen tips (say, the rotation I need to go from the first pen's tip to the tip of the second one), I need to compute <code>q_r = q_2 * q_rot_z_inv * q_1_inv</code> in order to get from tip 1 to tip 2 by computing <code>q_r * q_1</code>? Or does the "prior" rotation around the z-axis not matter in this case and I only need to compute <code>q_r = q_2 * q_1_inv</code> as usual?</p>
  
  <p>Edit:
  this is basically an extension of <a href="https://stackoverflow.com/questions/25149231/how-do-you-rotate-2-quaternions-back-to-starting-position-and-then-calculate-the">this question</a>, but I would like to know if the same answer also applies in my case or whether the known relative IMU rotation would in my case need to be included as well</p>