Pergunta

I know how to get the coordinates of the magnetic heading: heading.x, heading.y, heading.z The thing is that I'd need the (x, y, z)-vector of the trueHeading. How can I create this vector?

Thank you!

Foi útil?

Solução

Edit: I have changed my answer quite a bit...

Basically you need to rotate the magnetic north vector in the opposite direction to the Magnetic Declination angle.

The hard part is that you need to rotate the vector on a horizontal plane. For that you need to know the orientation of the phone.

Here is what you need to do:

  1. Get the magnetic north vector.

  2. Get the gravity vector from the accelerometer.

  3. Now calculate / look up the Magnetic Declination (it depends where you are in the world and it also varies slowly with time).

  4. Rotate the magnetic north vector X degrees about the gravity vector (where -X = Magnetic Declination). This will be the tricky part, you will need to brush up on some 3d trig.

Outras dicas

Thank's for the edit...funny, that's exactly what I did then. I took the magnetic north vector and rotated it with a rotation matrix around the gravity vector with the variation between the magneticHeading and the trueHeading.

The thing is that I'm dependent on the magnetic vector in this case. In some situations I noticed that the magnetic vector was going absolutely crazy and the sensor delivered weird values.

So what I wanted is to get the vector of the trueHeading which is independent from the magnetic vector. Ok, what a silly thought - the true heading is most probably anyway dependent on the magnetic heading already.

However - thank's for the answer :)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top