得到仰角? [英] Get angle of elevation?

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

问题描述

从加速度计,是有可能得到仰角?对于那些你们谁不知道,仰角为:

这可能与加速计测量?

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.

通过这样的假设,你可以使用<一个href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5B%5D,%20float%5B%5D,%20float%5B%5D,%20float%5B%5D%29" rel="nofollow">http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(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.

编辑:下面是一些code我放在一起。 在我的code的主要功能是:

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 :\n");
    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("\n\nGives :\n");
    for(i=0;i<orientation.length; i++) {
        str.append(orientation[i]);
        str.append(", ");
    }
    text.setText(str);
}

我没有尝试真正的设备上,只能在模拟器并使用的 SensorSimulator

如果你想整个源代码包与夫妇的工具,你需要为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.

,你其实可以得到来自指南针。 你正在寻找的是在球场上,这是在取向[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天全站免登陆