user1396033
user1396033

Reputation: 215

Magnetic Fields, Rotation Matrix And global coordinates

I think that i've read all the posts about this subject, but still i cant understand a few things:

Q1: To get the magnetic field vector in global coords i need to multiply the inverted rotation matrix and the magnetic field vector, why do i need to invert the rotation matrix?

Q2: Lets say that i have a device and i can calculate the azimuth based on the rotation along the Z-axis using getOrientation(...) method. can i use the rotation matrix or some other method to calculate the azimuth to magnetic north regardless to the phone attitude? So if i will rotate the phone the angle between me and the magnetic north will remain the same?

Q3: When i multiply the magnetic vector(4th col is zero) with the inverted rotation matrix i get that x is very close to zero. i know that this is o.k from other posts but i cant understand why?

Q4: In theory, lets say that i have two devices located 1 meter from each other, is it possible to make a spatial position of the two devices based only on their magnetic fields (in global coords)

Thanks in advanced.

P.S I've already read these posts: Getting magnetic field values in global coordinates, How can I get the magnetic field vector, independent of the device rotation?

Convert magnetic field X, Y, Z values from device into global reference frame

Upvotes: 1

Views: 4010

Answers (2)

Hoan Nguyen
Hoan Nguyen

Reputation: 18151

If you read my answer at Convert magnetic field X, Y, Z values from device into global reference frame You still do not understand it.

A1. You multiply the Rotation matrix with the coordinates of the magnetic field vector in device coordinate system to get the coordinates of the magnetic field vector in the world coordinate system.

Let me emphasize: The above said Rotation matrix and not inverted rotation matrix.

The Rotation matrix obtained by calling getRotationMatrix is the change of basis matrix from the device basis to the world basis. That is given any vector v with coordinates in device coordinate sytem, the coordinates in world coordinate system of the same vector v can be obtained by multiply the rotation matrix with the coordinates in device system coordinate.

The inverted rotation matrix is the change of basis matrix from the world basis to the device basis. Thus when you multitply this matrix with a coordinates, it is interpreted as multiply the matrix with the coordinates of a vector in world coordinate system to obtain the coordinates of the same vector in device coordinate system. Therefore if you multiply the inverted rotation matrix with the coordinates of the magnetic field vector as returned by the magnetic sensor. Then the coordinates is interpreted as the coordinates of a vector in the world coordinate system and thus do not represent the magnetic field vector and the resulting product is not the coordinates of the magnetic field vector in the world coordinates system. Actually it is the coordinates of a vector in device coordinate system.

A2. getOrientation is meaningful only if the device is flat. For me it just a bunch of angle calculations. I look at what I try to do geometrically and then use the rotation matrix to calculate what I want. For example, to calculate the direction where the back camera pointed, I look at it as the direction of -z (the opposite of the vector orthogonal to the screen). Thus to find this direction, I projected -z to the world East-North plane and calculate the angle between this projection vector and the North axis. Now if you think this way then rotation of the device will not change the direction of -z, thus the projection vectors are the same as you rotate the device. If you use getOrientation then you have to precall remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR) for getOrientation to give you the correct result.

A3. The getRotationMatrix assumes that the geomagnetic parameter is the coordinates of a vector lying entirely in the North-Sky plane. Well any vector lying in this plane has to have x coordinate equal to 0. This is just basic linear algebra.

A4. The answer is no. To get the spatial position you have to be to express these vectors relative to a fixed coordinate system. with only coordinates of these vectors in device coordinate system, there is no way you can find a fixed basis that allow you to calculate the change of basis matrix from the device basis to this fixed basis. The 2 conditions stated in my link above need to be satisfied to calculate the change of basis.

Upvotes: 4

lenik
lenik

Reputation: 23556

A1. rotation matrix tells the position of your phone in the world coordinates. if you want to convert the magnetic vector from your phone coordinates to the world coordinates you have to multiply to the inverse.

A2. don't quite understand the question, sorry.

A3. x coordinate is the lateral component of the magnetic force which is corresponds to the deviation of the north pole from the magnetic pole or something like that. it's supposed to be quite small, same as z coordinate, which is the vertical component.

A4. in theory this might work, but with the precision of the sensors you have in your Android device, this approach seems not very feasible.

Upvotes: 1

Related Questions