6

I am struck with a problem. I want to convert the CMAttitude information of an iPhone to Altitude (0 to 90deg) and Azimuth (0 to 360 deg). I have googled around and hit some threads which discuss about it, but none of threads turn out with a positive answer and most of the articles discussing Quaternion and Euler angles are too much mathematics to stuff into my brain!

Is there some open source material which does this task easy? Or someone has written code to perform this conversion?

Edit: First off, sorry for being so abstract!

Azimuth is the direction on the surface of the earth towards which the device is pointing. Like North = 0 deg, North East = 45deg, East = 90 deg, South = 180 deg and so on. Ranges between 0 deg to 360 deg:

enter image description here

Altitude is the angle made from the plane of the earth to an object in the sky: enter image description here

Thanks,

Raj

Raj Pawan Gumdal
  • 7,390
  • 10
  • 60
  • 92

1 Answers1

4

Using CMDeviceMotion, you can get a CMAttitude object with "roll, pitch and yaw" - where for example, given a phone held in portrait mode "yaw" is "azimuth", "pitch" is the tilt of the phone with respect to ground, or zenith, and "roll" is about the vector pointing through the screen and not what you're interested in.

Things get a bit tricky because "azimuth" is a projection of the 3D magnetic vector (pointing towards the magnetic north pole) on to the flat "ground" plane, which changes depending on device orientation, but given this understanding of the terms, threads like this one should be much more understandable. If you only need your application to work in one orientation things get much simpler.

P.S. "altitude" is almost exclusively used to refer to elevation or height about a given reference (sea level, geodetic height etc). "Zenith" or "pitch" are preferable, and since you're on iOS, you should stick to their coordinate scheme: (lat, lon, alt), (pitch, yaw, roll).

Community
  • 1
  • 1
dabhaid
  • 3,849
  • 22
  • 30
  • Altitude in this case is little different, please refer the attached images in the question and the question description. Also, I have added the comment to other answer. – Raj Pawan Gumdal May 04 '11 at 07:00
  • Ok, probably Joe has removed his previous answer. Well, I liked your conceptualization that Azimuth can be deduced using compass of iPhone 4, to deduce Altitude out of Pitch and Roll what will be the reference? Like true north is the reference for Azimuth, how shall we fix a fixed reference for altitude? Awarding you the bounty since this is the last day, but yes, keep helping me until I figure out the problem ;) – Raj Pawan Gumdal May 04 '11 at 12:55
  • Hi Raj, I had thought I added more information, I can't remember if it was a comment on Joe's answer, or as an edit I forgot to save. The summary was, the accelerometer values are all taken with respect to the gravity vector, so that is the reference for pitch and roll. At the end of this page: http://developer.apple.com/library/ios/#DOCUMENTATION/EventHandling/Conceptual/EventHandlingiPhoneOS/MotionEvents/MotionEvents.html#//apple_ref/doc/uid/TP40009541-CH4-SW1 it shows how to get orientation relative to a reference frame: you can use the frame of the phone in portrait orientation for example – dabhaid May 04 '11 at 14:06