8

我已经为 Rotation Vector 和 Orientation Vector 实现了监听器,虽然我知道它已经贬值了,但我想测试两者。

我知道 Rotation Vector 是一种融合传感器并被推荐,但根据它, NORTH(由 getOrientation(rotationMatrix,value) geaving bearing 0 返回的 value[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


    }

我想确定手机的 Y 轴和指向北方的向量之间的角度,这是我最初的实现。请建议。

4

1 回答 1

2

我认为这会有所帮助...

可以补偿倾斜和俯仰的 Android 指南针

这使用更可靠的来源计算北。

希望这可以帮助。

于 2014-02-03T19:15:16.443 回答