I posted this in the astronomy stack exchange forum, but considering that it is a very math intensive question I figured there could also be people on here that could help.
For a project with my astronomy professor, we are hooking up an array of 4 smaller telescopes to observe objects in space together.
To do this, we wanted to put an accelerometer and magnetometer on each telescope and have it read data from the gravitational pull on the accelerometer and the pull from the north magnetic pole on the magnetometer.
The accelerometer would measure the altitude, or the absolute height of measure point where accelerometer is at on the telescope. This would be converted to the angle of the telescope from its initial plane (when it makes a 90 degree angle with its stand and Cartesian z is zero).
The magnetometer would measure the pull of the of the magnetic north pole, and be able to give the azimuth angle, or the angle (from 0-360) that the telescope is pointing away from the magnetic north pole (0 degrees in the x direction would be pointing at the magnetic north pole).
Both readings are recorded in microteslas.
My professor said he was able to solve the altitude equation, but doesn't have time for the azimuth. He suggested treating the telescope itself as a 3D vector, normalizing it, and the projecting it down onto a flat plane, i.e. where it makes a 90 degree angle with the stand.
Would I use a rotational matrix for this? And should I treat the magnetometer and accelerometer vectors as two separate matrix vectors and use one to solve the other? What would the end equation look like?
You can use a Rotation Matrix or alternatively by Vector Maths.
I'm assuming that the Accel and the Magnetometer are aligned in the same orientation, i.e. the X, Y and Z axis are pointing in the same directions, also, that the Z Axis is the Axis that you want to use for the Azimuth angle.
If you take your Vectors of G (Accel), H (Magnetometer) and Z (Axis of Azimuth Calc) values: $$ G = \begin{bmatrix} Gx & Gy & Gz \end{bmatrix} \\ H = \begin{bmatrix} Hx & Hy & Hz \end{bmatrix} \\ Z = \begin{bmatrix} 0 & 0 & 1 \end{bmatrix} $$
You then need to Calculate:
$$ B = G \times Z \\ A = G \times H $$
The Azimuth Angle $ \theta $ is then:
$$ \cos \theta = \frac{(A \bullet B)}{\lvert A \rvert \bullet \lvert B \rvert} $$