

but anyway don't worry about that for now. Here is one of many answers from SO: UIAccelerationValue angleīTW as you can probably see, you can get a rough result by taking the ratio of simply the raw x by raw y value, rather than the ratio of the two sines, in the 'adjustmentAngle' expression.

You must TEST this by writing the three angles on the screen and then moving it around, in other words "physically unit test" that section you write, before you proceed! distanceFactor = square root of (x^2 + y^2 + z^2)Īngle X axis = acos ( x / distanceFactor )Īngle y axis = acos ( y / distanceFactor )Īngle z axis = acos ( z / distanceFactor) ) An example result might look like this: // This is a JS example const test 'Hello' console. These are put on a page using Markdown 'code fences', as described in Example code blocks. Quite right, I forgot to mention it sorry. By static examples, we are talking about static code blocks that show how a feature might be used in code. "the accelerometer doesn't provide the raw data in angles. PS, here's the incredibly handy diagram you may want to bookmark: Static inline float degreestoradians (double degrees) If ( LR > 0 ) finalResult = 90 - adjustmentAngle If TA is flat (0), the answer is either 90 or 270, depending on the sign of LR.ĪdjustmentAngle = arctan( sin(TA) / sin(LR) ) If LR is flat (0), the answer is either 0 or 180, depending on the sign of TA. If both LR and TA is zero, the machine is flat. The solutionAngle will be like a clock hand, clockwise, with 12 distant from you. You won't be able to do anything until that is working. (TA negative is leaning towards your belly.)ĭisplay both those numbers on your screen, and move the device around, so you are certain you have that right to begin with.

So LR runs from -90 to 90, TA from -90 to 90. Hold the iPad in front of you, let LR be the left / right tilt, TA the towards you / away from you tilt. If you don't like the above, here's a simpler way to get a reasonable result!
