Basically, I am programming an iOS application where I use attitude of the device in quaternion format. Problem is following:


I have a device that does a measurement #1 of magnetic field relative to it's orientation and saves it. After that this device is placed in some other point in space, rotated somehow and does a measurement #2 of magnetic field relative to it's orientation again.

Question: how magnetic field #3 will be different from #1, if after #2 we rotate device back to same orientation as during the measurement #1 ( instead of rotating device we can rotate field #2 ).


We have a Latin reference system $O_lxyz$ and two Greek reference systems systems $O\xi\eta\zeta$ and $O'\xi'\eta'\zeta'$. Rotation of Greek systems relative to Latin system is defined by quaternions $q, q'$.

As well, we know coordinates of vector $\vec{F} = (F_\xi, F_\eta, F_\zeta)$ relative to $O\xi\eta\zeta$ and coordinates of vector $\vec{F'} = (F'_{\xi'}, F'_{\eta'}, F'_{\zeta'})$ relative to $O'\xi'\eta'\zeta'$.

Question: find difference between $\vec{F}$ and vector $\vec{F''}$ that can be obtained by rotating $O'\xi'\eta'\zeta'$ to match $O\xi\eta\zeta$.

My solution:

Magnetic field $\vec{F'}$ must be rotated in opposite direction to rotation from $O'\xi'\eta'\zeta'$ to $O\xi\eta\zeta$. Thus, rotation from $O'\xi'\eta'\zeta'$ to $O\xi\eta\zeta$ is defined by quaternion $qq'$, rotation of the field by quaternion $(qq')^{-1} = q' {q}^{-1} \Rightarrow \vec{F''} = q' {q}^{-1} \vec{F'} q{q'}^{-1} = (F''_{\xi}, F''_{\eta}, F''_{\zeta})$. Now $\vec{F''}$ can be compared with $\vec{F}$.

Can't attach sketch directly because of rating:


I get updates from the sensor and print components of $\vec{F}$ and $\vec{F''}$. Obvious, that they must be same (at least near) if device is just rotated, but not translated.


1) If I rotate device in $Oxy$ plane, then it works fine, components are same.

2) If I rotate it in not $Oxy$ plane, then components change significantly.

What is wrong with my approach?

Thank You in advance!

  • $\begingroup$ This is a dumb question, but in your model, are you assuming a realistic spherical earth for your magnetic field? Or are you approximating with flat map-like earth? $\endgroup$ – rschwieb Jul 28 '15 at 17:52
  • $\begingroup$ I don't get the question. I have a device (read compass), that is rotated. How shape of the Earth is related? $\endgroup$ – Tzoiker Jul 28 '15 at 20:14
  • $\begingroup$ For one thing, when you do this step "After that this device is placed in some other point in space" it matters for your orientation after translation. If you were on a "flat earth" and oriented pointing down, then translating would never change that you are pointing down. But translating near a round earth would change your down into up after you get to the opposite side of the globe. $\endgroup$ – rschwieb Jul 28 '15 at 20:45
  • $\begingroup$ Oh, OK, translation is supposed to be local. $\endgroup$ – Tzoiker Jul 28 '15 at 20:47
  • $\begingroup$ For the second thing, it changes how magnetic north moves: if you translate perpendicularly to the north-south on flat earth while oriented pointing west, the compass and orientation never change with respect to each other, but on round earth they do: the compass swings to follow magnetic north while the orientation stays pointing the same direction in 3 space $\endgroup$ – rschwieb Jul 28 '15 at 20:47

I believe your formula for $\vec F''$ should be $\vec F'' = q^{-1} q' \vec F' {q'}^{-1} q$. The idea is that you first want to convert $\vec F'$ back to the Latin reference system by conjugating by $q'$, and only then conjugate by $q^{-1}$ to go back to the first Greek reference system. In general, it makes a difference which order we do this in, unless both rotations are along the same axis. If this still doesn't work, then you may need to replace $q$ and $q'$ everywhere by their inverses, in case they are defined the opposite way from how I'm interpreting your definition.

  • $\begingroup$ Referring to my sketch, If You apply $q'$ first, then $\vec{F'}$ will rotate clockwise in $O'\xi'\eta'\zeta'$. After that, applying $q^{-1}$ will rotate it clockwise again. Thus, it will not be rotated as supposed for sure. $\endgroup$ – Tzoiker Jul 28 '15 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.