5

通过event.accelerationIncludingGravity在Android上使用,它返回一个值

x: -0.2
y: +0.1
z: +9.1

在平坦的表面上休息时。但是,我想在没有重力的情况下获得加速度,但event.acceleration不支持。有没有办法通过数学转换它?在HTML5Rocks中有一个删除重力因素的示例,但它似乎不起作用。

  // Convert the value from acceleration to degrees acceleration. x|y is the 
  // acceleration according to gravity, we'll assume we're on Earth and divide 
  // by 9.81 (earth gravity) to get a percentage value, and then multiply that 
  // by 90 to convert to degrees.                                
  var tiltLR = Math.round(((acceleration.x) / 9.81) * -90);
  var tiltFB = Math.round(((acceleration.y + 9.81) / 9.81) * 90 * facingUp);

绘制加速度值的示例脚本(不是来自 HTML5Rocks)

4

1 回答 1

0

我懂了。您得到的 x 和 y 轴的数字基本上为 0,继续测量放置在平面上的设备并分别平均所有 x 和 y 值,您将获得每个方向的误差程度。加速度以 m/s^2 为单位。(米每秒平方)。地球表面的重力加速度为9.86m/s^2。在一个理想的物理问题中,你所要做的就是减去这个数字,你就会得到答案。如果你试图计算速度,那么这将是一个更复杂的问题,但地球的重力加速度不会加速。您确实在 z 轴上有较大程度的误差,但如果您将误差程度计算为实际值的百分比,则不会。或者你在海拔300公里左右。

于 2013-04-30T16:02:47.160 回答