android - Using a rotation matrix to convert euler units to 360 degrees -
in android, using accelerometer , magnetic field sensor calculate spatial positioning, shown in code below. getrotationmatrix method generates values in real-world units azimuth, pitch , roll. azimuth , roll give values in range of 0 180 or 0 -180. pitch gives values 0 90 or 0 -90. that's problem app because in app need determine unique locations regardless how device oriented. roll, can have 2 locations same value.
i need apply matrix transformation remaps sensor values values range 0 360 degrees (actually, 360 wouldn't valid since it's same 0 , close 360 result in number 359.99999...)
i not mathematician , don't know how utilize matrixes, allow lone utilize them in android aware required 0 360 grade conversion. nice if matrix took care of azimuth , roll produce values 0 360 if isn't possible, that's fine since unique positions can still derived sensor values. suggestions how how create matrix transformation?
@override public void onsensorchanged(sensorevent event) { seek { if (event.sensor.gettype() == sensor.type_accelerometer) accelerometervalues = event.values; else if (event.sensor.gettype() == sensor.type_magnetic_field) magneticfieldvalues = event.values; if ((accelerometervalues != null) && (magneticfieldvalues != null)) { float[] r = new float[9]; float i[] = new float[9]; boolean success = sensormanager.getrotationmatrix(r, i, accelerometervalues, magneticfieldvalues); if (success) { float[] values = new float[3]; sensormanager.getorientation(r, values); // convert radians degrees if preferred. values[0] = (float) math.todegrees(values[0]); // azimuth values[1] = (float) math.todegrees(values[1]); // pitch values[2] = (float) math.todegrees(values[2]); // roll } } } grab (exception ex) { } }
edit: raw event values pitch not give unique values rotate device 360 degrees, highly uncertainty matrix transformation going produce results after. maybe using wrong sensors.
android sensor
No comments:
Post a Comment