このドキュメントを読むことをお勧めします: Isolating the Gravity Component from Acceleration Dataと、その下の「Isolating Instantaneous Motion from Acceleration Data」というセクション。
基本的に、スムーズな動きを得るには、重力を除外する必要があります。リンクはサンプルコードを提供します。
編集: UIAccelerometer は iOS 5.0 で廃止され、付属のドキュメントも削除されたようです。
将来の参考のために、私はいくつかの掘り下げを行い、元のサンプルコードの「カーボンコピー」と思われるものを見つけました(source):
// This example uses a low-value filtering factor to generate a value that uses 10 percent of the
// unfiltered acceleration data and 90 percent of the previously filtered value
// Isolating the effects of gravity from accelerometer data
#define kFilteringFactor 0.1
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
// Use a basic low-pass filter to keep only the gravity component of each axis.
accelX = (acceleration.x * kFilteringFactor) + (accelX * (1.0 - kFilteringFactor));
accelY = (acceleration.y * kFilteringFactor) + (accelY * (1.0 - kFilteringFactor));
accelZ = (acceleration.z * kFilteringFactor) + (accelZ * (1.0 - kFilteringFactor));
// Use the acceleration data.
}
// shows a simplified high-pass filter computation with constant effect of gravity.
// Getting the instantaneous portion of movement from accelerometer data
#define kFilteringFactor 0.1
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
// Subtract the low-pass value from the current value to get a simplified high-pass filter
accelX = acceleration.x - ( (acceleration.x * kFilteringFactor) + (accelX * (1.0 - kFilteringFactor)) );
accelY = acceleration.y - ( (acceleration.y * kFilteringFactor) + (accelY * (1.0 - kFilteringFactor)) );
accelZ = acceleration.z - ( (acceleration.z * kFilteringFactor) + (accelZ * (1.0 - kFilteringFactor)) );
// Use the acceleration data.
}