我已经实现了旋转矢量和方向矢量的监听器,虽然我知道它已经折旧我想测试两者.
我知道旋转矢量是一个融合传感器并推荐但是根据它,NORTH(getOrientation返回的值[0](rotationMatrix,value)geaving bearing 0)与Orientation传感器的NORTH不匹配.我还从playstore的不同应用程序中得出结论,方向传感器值似乎更接近它们.
此外很多次我从Rotation_Vector的方位角值[0]然后getOrientation刚刚射击并保持在-180到180之间振荡
PS"getRotationMatrix(float [] R,float [] I,float [] gravity,float [] geomagnetic)"也给出与旋转向量相同的结果.
public final void onSensorChanged(SensorEvent event)
{
float rotationMatrix[];
switch(event.sensor.getType())
{
.
.
.
case Sensor.TYPE_ROTATION_VECTOR:
rotationMatrix=new float[16];
mSensorManager.getRotationMatrixFromVector(rotationMatrix,event.values);
determineOrientation(rotationMatrix);
break;
case Sensor.TYPE_ORIENTATION:
sensorZValue.setText(""+event.values[0]); //rotation about geographical z axis
sensorXValue.setText(""+event.values[1]); //rotation about geographical x axis
sensorYValue.setText(""+event.values[2]); //rotation about geographical y axis
}//switch case ends
}
private void determineOrientation(float[] rotationMatrix)
{
float[] orientationValues = new float[3];
SensorManager.getOrientation(rotationMatrix, orientationValues);
double azimuth = Math.toDegrees(orientationValues[0]);
double pitch = Math.toDegrees(orientationValues[1]); …Run Code Online (Sandbox Code Playgroud) android magnetometer digital-compass rotational-matrices android-sensors
有没有人知道Android上的方向传感器和磁场传感器之间的区别?
我的理解:
因为我读过磁力计是数字罗盘的代名词,我有点困惑.他们真的是什么?
我需要为我的应用程序构建指南针.
从阅读文档看起来有两种合理的方法:
任何解决这个问题的建议都将不胜感激.
"在20世纪90年代末期,一位名叫Romke Jan Berhnard Sloot的荷兰电子技术人员宣布开发Sloot数字编码系统,这是数据传输方面的一项革命性进步,他声称可以将功能长度的电影减少到只有8KB的文件大小.解码算法是370MB,显然Sloot向飞利浦高管证明了这一点,他们通过64KB芯片同时播放16部电影让他们眼花缭乱.在得到一批投资者后,他于1999年9月11日神秘死亡.
这可能还是只是一个故事
无论当前的屏幕方向(横向或纵向),我都希望获得当前的磁性方向.
我找到了这个例子,但它不是独立的方向,对吧?而这也帮不了我.我也读过http://android-developers.blogspot.de/2010/09/one-screen-turn-deserves-another.html.
这是我目前采用的方法,我不想使用(短):
mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
private SensorEventListener sensorEventListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent event) {
/* Get measured value */
float current_measured_bearing = (float) event.values[0];
/* Compensate device orientation */
switch (((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
current_measured_bearing = current_measured_bearing + 90f;
break;
case Surface.ROTATION_180:
current_measured_bearing = current_measured_bearing - 180f;
break;
case Surface.ROTATION_270:
current_measured_bearing = current_measured_bearing - 90f;
break;
}
Run Code Online (Sandbox Code Playgroud)
但最后一部分肯定是错的!getRotationMatrix()在这种情况下,如何正确使用更新的方法?(方向独立)或者我只需要event.values[]根据旋转矩阵使用数组的其他值?或者我需要'重新映射坐标'?那么,是实现这一目标的正确方法是什么?
我正在为具有360°屏幕旋转和API Level 11+的设备开发.
我知道这些问题经常被问到,但我不能将他们的答案转移到我的问题上.
android ×4
magnetometer ×2
bearing ×1
compression ×1
file ×1
java ×1
orientation ×1
storage ×1