I see a lot of answers online and they all have similar copy pasted code but none really have an explanation of the math that they use. I have a URL to the code on tutorialspoint which is the same as the answers I see on stackoverflow. However can someone explain to me this portion of the code:
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x * x + y * y + z * z));
float delta = mAccelCurrent - mAccelLast;
// What is this doing?
mAccel = mAccel * 0.9f + delta;
if (mAccel > 12) {
Toast.makeText(getApplicationContext(), "Shake event detected", Toast.LENGTH_SHORT).show();
}
}
What is this line supposed to be doing
mAccel = mAccel * 0.9f + delta;
Where did the 0.9f come from and why are we multiplying it by itself and adding the delta? My physics isn't strong so it's not obvious to me.
https://www.tutorialspoint.com/how-to-detect-shake-event-in-android-app