Real-life case (helps understand the question)
I am building a device that can freely rotate around all its axis (x, y, z) and is equipped with:
- an accelerometer (A) that gives me a vector pointing to the centre of the Earth (Va)
- a 3D magnetometer (M) that gives me the direction of the magnetic field of the Earth (Vm)
The two vectors share the same reference system (x, y, z), but what I am interested to find is the vector that points to the north relative to the Earth surface [think of a hand-held compass: I want to find where the needle should point to].
This video shows a "ball compass" that has pretty much the same behaviour that my device should replicate electronically.
The coding question
I did a bit of research, and it seems to me that I should use is 3D rotation matrices doing the following two steps:
- rotate the reference system of Vm from R to R', in such a way that y' will be parallel to Va,
- "flatten" the Vm vector setting its y' component to 0
Unluckily I am still confused on how I should proceed in concrete terms (I have no previous experience of working with vectors and matrices). One of the things that confuses me is that most of the material I could google, talks in terms of angles, but the data I am receiving from both sensors is in the form V(Vx, Vy, Vz), where Vz, Vy and Vz are the components of V along the reference system.
So my question really boils down to: what is the matrix I have to use in order to perform the transformation of which at step #1?
Thank you in advance for your time and expertise.