1

Android中Rotation-Vector-Sensor的Scalar组件有什么用?

文档说明它是可选的,示例不使用它。可选是否意味着不是每个支持传感器的设备都支持它?

我习惯于四元样式的旋转符号,其中前 3 个值定义向量,第四个值定义围绕该向量的旋转。但是android似乎使用了不同的方法。

4

1 回答 1

2

As the doc says:

SensorEvent.values[0] Rotation vector component along the x axis (x * sin(θ/2)). Unitless 
SensorEvent.values[1] Rotation vector component along the y axis (y * sin(θ/2)). 
SensorEvent.values[2] Rotation vector component along the z axis (z * sin(θ/2)). 
SensorEvent.values[3] Scalar component of the rotation vector ((cos(θ/2)).1 

this is a unit quaternion (X,Y,Z,W) used by android. Since W=sqrt(X^2+Y^2+Z^2), you can calculate values[3] by yourself with values[0], values1, values[2]. My experience is that most android devices do not ouput the values[3] value.

The quaternion used by android (X,Y,Z,W) could be converted to what you were using (x,y,z,θ), just as the doc says

X=x * sin(θ/2)
Y=...
Z=...
W=cos(θ/2)

so you can get (x,y,z,θ):

x=X/sin(θ/2)
y=...
z=...
θ=arcsin(sqrt(X^2+Y^2+Z^2))*2
于 2013-10-29T07:21:36.047 回答