Search code examples
swiftios8core-motion

CoreMotion convert Iphone Pitch: raidians to degrees


I am trying to convert radians to degrees. I already know: 1 radian = 180/PI This does give me degrees.

You can check out my code here: github

Here is my problem:

enter image description here

I am getting radian data that only goes from 0 to 1.5 and then back to 0 then from 0 to -1.5 and back to 0. So when I do the conversion I get 0 to 90 and back to 0 and then 0 to -90 and back to 0.

What I want is to be able to go from 0 to 360 as I move the pitch of the Iphone. I am pretty sure its an easy map and when I see it i will slam my hand into my forehead.

Thanks for the help!


Solution

  • I think your issue is a typo.
    The function in your repo is:

    var degrees = (radians * M_PI)

    but as you noted at the beginning of your question, it should be

    var degrees = radians * (180.0 / M_PI)