Android的旋转矩阵转换顺序 [英] order of android rotation matrix conversion

查看:148
本文介绍了Android的旋转矩阵转换顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android使用以下code来计算旋转矩阵:

android uses the following code to calculate rotation matrix:

    float Ax = gravity[0];
    float Ay = gravity[1];
    float Az = gravity[2];
    final float Ex = geomagnetic[0];
    final float Ey = geomagnetic[1];
    final float Ez = geomagnetic[2];
    float Hx = Ey*Az - Ez*Ay;
    float Hy = Ez*Ax - Ex*Az;
    float Hz = Ex*Ay - Ey*Ax;
    final float normH = (float)Math.sqrt(Hx*Hx + Hy*Hy + Hz*Hz);
    if (normH < 0.1f) {
        // device is close to free fall (or in space?), or close to
        // magnetic north pole. Typical values are  > 100.
        return false;
    }
    final float invH = 1.0f / normH;
    Hx *= invH;
    Hy *= invH;
    Hz *= invH;
    final float invA = 1.0f / (float)Math.sqrt(Ax*Ax + Ay*Ay + Az*Az);
    Ax *= invA;
    Ay *= invA;
    Az *= invA;
    final float Mx = Ay*Hz - Az*Hy;
    final float My = Az*Hx - Ax*Hz;
    final float Mz = Ax*Hy - Ay*Hx;
    if (R != null) {
        if (R.length == 9) {
            R[0] = Hx;     R[1] = Hy;     R[2] = Hz;
            R[3] = Mx;     R[4] = My;     R[5] = Mz;
            R[6] = Ax;     R[7] = Ay;     R[8] = Az;
        } else if (R.length == 16) {
            R[0]  = Hx;    R[1]  = Hy;    R[2]  = Hz;   R[3]  = 0;
            R[4]  = Mx;    R[5]  = My;    R[6]  = Mz;   R[7]  = 0;
            R[8]  = Ax;    R[9]  = Ay;    R[10] = Az;   R[11] = 0;
            R[12] = 0;     R[13] = 0;     R[14] = 0;    R[15] = 1;
        }
    }

我想知道这是什么逻辑背后
此外,什么是旋转的顺序使用?
我想用旋转矩阵来纠正旋转。所以计算由Android的顺序很重要。

i would like to know what is the logic behind this also, what is the order of rotation used? i want to correct the rotation using the rotation matrix. so the order of calculation by android is important.

推荐答案

Android的假设重力参数是趴在世界的天空轴矢量。也就是说,如果( W_1 的例句 w_3 )是世界的基础,其中 W_1 是一个单位矢量指向东的例句是指向北和单位矢量 w_3 是向着天空指向一个向量,则重力参数是的 w_3 。因此,重力参数的规范化为 w_3 。结果
此外,code假定地球磁场参数矢量躺在被跨越的平面的例句 w_3 因此,规范化地磁场参数的跨产品与重力正常化参数是一个单位向量的正交由的例句 w_3 跨越了飞机。因此,该产品是刚刚的 W_1 。结果
现在的叉积 w_3 W_1 的例句。因此,你从设备坐标到世界坐标基础上的变化。结果
我不明白你所说的旋转使用顺序的意思,因此不能回答这个问题。

Android assumes the gravity parameter is a vector lying on the world sky axis. That is if (w_1, w_2, w_3) is the world basis where w_1 is a unit vector pointing East, w_2 is a unit vector pointing North and w_3 is a vector pointing toward the sky, then the gravity parameter is a vector that is a multiple of w_3. Therefore the normalize of the gravity parameter is w_3.
Also, the code assume the geomagnetic field parameter is a vector lying on the plane spanned by w_2 and w_3 Thus the cross product of the normalize geomagnetic field parameter and the normalize gravity parameter is a unit vector orthogonal to the plane spanned by w_2 and w_3. Therefore this product is just w_1.
Now the cross product of w_3 and w_1 is w_2. Thus you get the change of basis from the device coordinate to the world coordinate.
I do not understand what do you mean by "the order of rotation used" and thus cannot answer that question.

这篇关于Android的旋转矩阵转换顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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