iOS device screen magnetic direction based on maxi

2019-07-16 04:50发布

问题:

OK I don't think this question has been asked and its time either I get an answer quicker or I will add the answer once I have it as I must be close.

Let me explain:

Considering iOS device pitch and roll (forget yaw) we have the angles being as this

 *         r+
 *    ------------
 *    |           |
 * p- °           |p+
 *    |           |
 *    ------------
 *         r-

So based on the body reference frame.

We know that when either pitch or roll is 0 the other is the max inclination of the device. But when the device has inclination in both roll and pitch then we need to go Quaternion and the following answer will get us the screen normal. https://stackoverflow.com/a/10836923/2332101

The normal vector with the vertical reference vector will give us the max inclination.

Therefore, to get the normal vector projected on the horizontal plane with the heading direction provided in CLHeading, the angle between (call it x axis, as it is the iOS body frame coord) and the x of the CLHeading should give us the correct magnetic heading (forget true heading).

That is in this example:

 *         
 *    ------------
 *    |           |
 *    °           |-> (magnetic heading)
 *    |           |
 *    -----|------
 *         v (max inclination example where p = 0)

So in the above example we know it is CLHeading.magneticHeading + 90° but I do not want to go down that route as I have already been. I want to do it mathematically using all the clever API's provided.

IT is that simple, but I have tried tons of choices without success.

Please help me find out where I am thinking the wrong way!

回答1:

So here is the answer:

From the normal mentioned in the question:

  1. Multiplying the vertical vector with the normal we get a horizontal vector based on the right hand rule.
  2. Multiplying the result with the normal again, will give us the direction of the maximum inclination.
  3. Using atan function and giving it atan2(finalVector.y,finalVector.x) as we know that the x axis is pointing to the north.

Done!

The question is this: why the two methods give different readings? That is working from Core Location Framework's CLHeading and Core Motion's CMAttitude gives slightly different results or I am doing something sloppy?

Thanks