Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: getAngleChange - weird results
    primarykey
    data
    text
    <p>I'm currently experimenting with some sensors of Android phones. For testing, I'm using a Samsung Galaxy S. As it does not have a gyroscope, I'm using accelerometer and sensor for magnetic field.</p> <p>What I basically want to do, is to get a certain angle, when moving the device. I try to explain: consider you are holding the phone in landscape mode in front of your face and then you turn yourself by 90 degrees to the right. </p> <p>I use the following code to get the current rotation matrix:</p> <pre><code>@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { mGravity = event.values.clone(); } if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { mGeomagnetic = event.values.clone(); } if (mGravity != null &amp;&amp; mGeomagnetic != null) { float R[] = new float[9]; float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic); } } </code></pre> <p>This works well and then I use <code>SensorManager.getAngleChange(angleChange, R, lastR);</code> to achieve the angle change. I then get (roughly) 65° in <code>angleChange[1]</code> if I turn myself as described above and do not tilt the phone or change anything else...</p> <p>But if I also tilt the phone by 90° when turning myself (so that display is looking to the ceiling afterwards) I get (roughly) 90° in <code>angleChange[1]</code>.</p> <p>I'm very confused now, why such a rotation affects the value in <code>angleChange[1]</code> and on the other hand why it is needed to get the expected 90°.</p> <p>What I want to achieve is to get the angle when moving the phone as described above (not in 90° degree steps but this sort of orientation change) no matter which other orientation changes (along the two other axes) are made.</p> <p>Is there any possibility for this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload