2
我想获得设备旋转,并且我已经实现了某种程度,但代码不工作,哪个设备与Magentic传感器,方向传感器和陀螺仪传感器不在一起。但我已经看到一些应用程序,像XClinometer和iHandy level free在设备上运行。有设备htc资源管理器没有提供价值,因为这些传感器不存在。请告诉我如何实现此任务。 我已经使用这个代码,但作为传感器不可用,所以没有得到任何值,所以没有旋转矩阵。如何使RotationMatrix在设备中只有加速度传感器
@Override
public void onSensorChanged(SensorEvent event) {
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
// copy new accelerometer data into accel array and calculate
// orientation
System.arraycopy(event.values, 0, accel, 0, 3);
calculateAccMagOrientation();
break;
case Sensor.TYPE_GYROSCOPE:
// process gyro data
gyroFunction(event);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
// copy new magnetometer data into magnet array
System.arraycopy(event.values, 0, magnet, 0, 3);
break;
}
}
,并且该方法是
public void calculateAccMagOrientation() {
if (SensorManager.getRotationMatrix(rotationMatrix, null, accel,
magnet)) {
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X,
SensorManager.AXIS_Y, mValuesOrientation);
SensorManager.getOrientation(rotationMatrix, mValuesOrientation);
}else{
//float[] array = new float[9];
if(magnet[0]<=0){
System.out.println("herr.....");
System.out.println();
}else{
System.out.println("null so herr.....");
}
/*on htc device it is coming here so i need code here to get angle as only received accelerometer sensor data.
*/
}
}
倾斜角度我需要做什么过程。 – Manmohan
正在使用Math.atan2(y/x)是有效的或其他方式..btw我使用这个 – Manmohan
我不知道我理解你的问题。是的,你可以通过一个反三角函数得到角度。您必须对您感兴趣的倾斜角度和您使用的符号给出清晰的定义。 – Ali