When a user has a phone in their pocket, I want to be able to capture acceleration along XYZ in the users coordinate system. I say users coordinate system for 2 reasons:
- The orientation of the device in their pocket should not matter, and should give me the same XYZ acceleration values regardless of orientation
- Walking direction with respect to the world coordinate system should not matter, so walking west to east and walking east to west should give me the same numbers
My question, is what is the math required to convert from device based acceleration to user based?
I have seen one similar thread on this: Android Convert device coordinate system to "user" coordinate system, but there is no answer, and furthermore I'd like to achieve this without a calibration phase (which that other thread allows for)
I have also seen threads on converting from a device coordinate system to a world coordinate system: Acceleration from device's coordinate system into absolute coordinate system
I have implemented that with the following:
float[] accelerometerMatrix = new float[3];
float[] accelerometerWorldMatrix = new float[3];
float[] gravityMatrix = new float[3];
float[] magneticMatrix = new float[3];
float[] rotationMatrix = new float[9];
<code to get and store the sensor values into the respective matrices>
SensorManager.getRotationMatrix(rotationMatrix, null, gravityMatrix, magneticMatrix);
accelerometerWorldMatrix[0] = rotationMatrix[0] * accelerometerMatrix[0] + rotationMatrix[1] * accelerometerMatrix[1] + rotationMatrix[2] * accelerometerMatrix[2];
accelerometerWorldMatrix[1] = rotationMatrix[3] * accelerometerMatrix[0] + rotationMatrix[4] * accelerometerMatrix[1] + rotationMatrix[5] * accelerometerMatrix[2];
accelerometerWorldMatrix[2] = rotationMatrix[6] * accelerometerMatrix[0] + rotationMatrix[7] * accelerometerMatrix[1] + rotationMatrix[8] * accelerometerMatrix[2];
That code, while it works for what it does, puts the accelerometer XYZ values in a world space. Now I need to get from that to the user space.
Ultimately, when a user is walking forwards, I want to be able to get that acceleration value irrespective of 1) which direction they're walking in, and 2) how the device is orientated in their pocket. With the code above, when a user walks forward while facing NorthEast, the XYZ values will be different than if they walked SouthWest, when for my purposes they need to be the same because the user is still moving "forward"
Is there a way to achieve this? I will consider answers with a calibration phase, but ideally I'd like to skip any calibration phases entirely for this