获取仰角? [英] Get angle of elevation?

查看:29
本文介绍了获取仰角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从加速度计,是否可以得到仰角?对于那些不知道的人,仰角是:

这可以通过加速度计测量实现吗?

From the accelerometer, is it possible to get the angle of elevation? For those of you who don't know, the angle of elevation is:

Is this possible with the accelerometer measurements?

推荐答案

由于您不知道用户在哪里,因此无法真正获得视线的仰角"...

It is not really possible to get that "elevation angle" to the line of sight since you have no idea where the user is...

您可以做的是假设用户将设备屏幕直接朝向他的眼睛.

What you can do though is assume that the user orients the screen of the device straight towards his eyes.

有了这个假设,你可以使用 http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[]) 得到设备的方向,得到y轴和(x,z)平面的夹角.

With that assumption, you can use http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[]) to get the orientation of the device and get the angle between the y axis and the (x,z) plane.

它的作用是利用3轴上的加速度计来查看重力的方向.

What it does is that it uses the accelerometer on the 3 axis to see what is the direction of the gravitation force.

这仅在设备静止时有效.如果您需要通过运动更好地处理它,您应该使用陀螺仪(如果它存在于设备中).

This will work only if the device is stationary. If you need to handle it better with motion, you should use the gyroscope if it exists in the device.

另一件事是,根据您的应用程序,如果这是您正在研究的应用程序类型,您可能需要查看一些增强现实框架.

Another thing is that depending on your application, you might want to look at some Augmented Reality frameworks if that's the kind of application you are looking into.

这是我整理的一些代码.我的代码中的主要功能是:

Edit : Here is some code I put together. The main function in my code is :

public void onSensorChanged(SensorEvent event) {
    int sensor = event.type;
    float[] values = event.values;
    int i;
    StringBuffer str=new StringBuffer();
    // do something with the sensor data
    TextView text = (TextView) findViewById(R.id.my_text);
    float[] R = new float[9]; // rotation matrix
    float[] magnetic = new float[3];
    float[] orientation = new float[3];

    magnetic[0]=0;
    magnetic[1]=1;
    magnetic[2]=0;

    str.append("From Sensor :
");
    for(i=0;i<values.length; i++) {
        str.append(values[i]);
        str.append(", ");
    }

    SensorManager.getRotationMatrix(R, null, values, magnetic);
    SensorManager.getOrientation(R, orientation);


    str.append("

Gives :
");
    for(i=0;i<orientation.length; i++) {
        str.append(orientation[i]);
        str.append(", ");
    }
    text.setText(str);
}

我没有在真实设备上尝试,只是在模拟器上并使用 SensorSimulator.

I did not try on a real device, only on the emulator and using the SensorSimulator.

如果您想要完整的源代码包以及传感器模拟器所需的几个工具,请给我发电子邮件,我已经打包好了.

If you want the whole source package with the couple of tools you would need for the sensorsimulator, email me, I have that all packaged.

您实际上可以从指南针中获取这些数据,而不是编造磁性数据.您正在寻找的是音高,在 orientation[1] 中,它在 -pi/2 和 pi/2 之间变化.

Instead of making up the magnetic data, you can actually get those from the compass. What you are looking for is the pitch, that's in orientation[1], it varies between -pi/2 and pi/2.

希望有所帮助.

这篇关于获取仰角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆