android uses the following code to calculate rotation matrix:
android使用以下代码来计算旋转矩阵:
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;
}
}
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的计算顺序很重要。
1 个解决方案
#1
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假设重力参数是一个位于世界轴上的矢量。也就是说,如果(w_1, w_2, w_3)是世界基,其中w_1是指向东方的单位向量,w_2是指向北方的单位向量,w_3是指向天空的向量,那么重力参数是w_3的倍数。因此,重力参数的归一化是w_3。同时,代码假设地磁场参数是一个位于由w_2和w_3张成平面的矢量,因此正火地磁场参数和正火重力参数的叉积是一个单位矢量,正交于由w_2和w_3张成平面。因此这个乘积就是w_1。w_3和w_1的外积是w_2。这样你就可以从设备坐标变换到世界坐标。我不明白你所说的“使用的旋转顺序”是什么意思,因此不能回答这个问题。
#1
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假设重力参数是一个位于世界轴上的矢量。也就是说,如果(w_1, w_2, w_3)是世界基,其中w_1是指向东方的单位向量,w_2是指向北方的单位向量,w_3是指向天空的向量,那么重力参数是w_3的倍数。因此,重力参数的归一化是w_3。同时,代码假设地磁场参数是一个位于由w_2和w_3张成平面的矢量,因此正火地磁场参数和正火重力参数的叉积是一个单位矢量,正交于由w_2和w_3张成平面。因此这个乘积就是w_1。w_3和w_1的外积是w_2。这样你就可以从设备坐标变换到世界坐标。我不明白你所说的“使用的旋转顺序”是什么意思,因此不能回答这个问题。