简体   繁体   English

使用传感器管理器获取手机的方向(滚动,俯仰,偏航)角度?

[英]getting the orientation(Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager?

I'm trying to get the orientation (Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager ,and according to what is written in android developers website, the method 我正在尝试使用传感器管理器获取移动电话的方向(滚动,俯仰,偏航)角度,并根据android开发人员网站上的内容编写该方法

getInclination(float[] I) Computes the geomagnetic inclination angle in radians from the inclination matrix I >returned by getRotationMatrix(float[], float[], float[], float[]).` and getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic) getInclination(float [] I)从由getRotationMatrix(float [],float [],float [],float [])返回的倾斜矩阵I>计算弧度的地磁倾斜角。 float [] I,float []重力,float []地磁)

Computes the inclination matrix I as well as the rotation matrix R transforming a vector >from the device coordinate system to the world's coordinate system which is defined as a >direct orthonormal basis. 计算将向量从设备坐标系转换为世界坐标系的倾角矩阵I和旋转矩阵R,该坐标系被定义为>直接正交基。 ` and it returns boolean value. `,它返回布尔值。

My question is, How to get the orientation using the methods mentioned? 我的问题是,如何使用上述方法获得方向?

Code

@Override
public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub

    float []I = new float[9];
    float []R = new float[9];

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];

        tvX.setText(Float.toString(x));
        tvY.setText(Float.toString(y));
        //tvZ.setText(Float.toString(sm.getInclination(I)));    
    }
}
Display disp = (Display)getSystemService(Context.WINDOW_SERVICE);
int orientation = disp.getOrientation();

Use the above two lines to get orientation of mobile phone 使用以上两行来获取手机的方向

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM