pxm*_*pxm 8 android magnetometer digital-compass rotational-matrices android-sensors
我已经实现了旋转矢量和方向矢量的监听器,虽然我知道它已经折旧我想测试两者.
我知道旋转矢量是一个融合传感器并推荐但是根据它,NORTH(getOrientation返回的值[0](rotationMatrix,value)geaving bearing 0)与Orientation传感器的NORTH不匹配.我还从playstore的不同应用程序中得出结论,方向传感器值似乎更接近它们.
此外很多次我从Rotation_Vector的方位角值[0]然后getOrientation刚刚射击并保持在-180到180之间振荡
PS"getRotationMatrix(float [] R,float [] I,float [] gravity,float [] geomagnetic)"也给出与旋转向量相同的结果.
public final void onSensorChanged(SensorEvent event)
{
float rotationMatrix[];
switch(event.sensor.getType())
{
.
.
.
case Sensor.TYPE_ROTATION_VECTOR:
rotationMatrix=new float[16];
mSensorManager.getRotationMatrixFromVector(rotationMatrix,event.values);
determineOrientation(rotationMatrix);
break;
case Sensor.TYPE_ORIENTATION:
sensorZValue.setText(""+event.values[0]); //rotation about geographical z axis
sensorXValue.setText(""+event.values[1]); //rotation about geographical x axis
sensorYValue.setText(""+event.values[2]); //rotation about geographical y axis
}//switch case ends
}
private void determineOrientation(float[] rotationMatrix)
{
float[] orientationValues = new float[3];
SensorManager.getOrientation(rotationMatrix, orientationValues);
double azimuth = Math.toDegrees(orientationValues[0]);
double pitch = Math.toDegrees(orientationValues[1]);
double roll = Math.toDegrees(orientationValues[2]);
sensorZValue.setText(String.valueOf(azimuth)); //rotation about geographical z axis
sensorXValue.setText(String.valueOf(pitch)); //rotation about geographical x axis
sensorYValue.setText(String.valueOf(roll)); //rotation about geographical y axis
}
Run Code Online (Sandbox Code Playgroud)
我想确定手机的Y轴和指向北的Vector之间的角度,这是我最初的实现.请建议.
| 归档时间: |
|
| 查看次数: |
8530 次 |
| 最近记录: |