问题
What I am trying to do?
Using the sensor of Android, I have collected lot of acceleration values when some diabetic patients were running to do physical exercise. Each acceleration value consists of three components: Acceleration in x axis, acceleration in y axis, acceleration in z axis. Then, I need to calculate the total magnitude of each acceleration value and it's direction.
Then, what does create the problem?
In my data, the direction of acceleration components (x, y, z) are represented in sign (+ or -). For example: x axis component of an acceleration value: +5.4ms^-2, y axis: -2.3ms^-2, z axis: -6.7ms^-2.Therefore, I wanted such direction (+ or -) for total magnitude of each acceleration value.
I have calculated the magnitude of each acceleration using the formula square_root(x^2 + y^2 + z^2). However, I do not know how I can calculate the direction of that magnitude? That is, I do not know the direction (+ or -) of total acceleration?
Note:
I have checked a lot of Q&A (e.g. 1, 2, 3) of SO. I have checked the android document also. Though the document talked a little bit about the direction, I did not understand how can I implement to find the specific direction (either + or -) of the total acceleration magnitude. Moreover, I have checked many articles regarding acceleration. Still, the problem is not solved.
回答1:
You can get the direction just by using simple math- y/x=tan theta, where theta is the angle from origin in the xy plane. Similar math can get you the other angle involved. The problem for you is all that is relative to the phone, not to the user. So if his phone was at an angle in his pocket, you won't get the answers you want. Worse if it was upside down.
That said- I question the actual need for this. If you're trying to get relative effort of their exercising, magnitude should be enough. If you're trying to do something like mapping, acceleration data is too noisy for accuracy.
回答2:
You should consider the directions of each component of acceleration. Think about A 3D vector. There’s no way to determine positivity or negativity; it’s direction is denoted by a unit vector pointing the same way. So in essence, 3D vectors (total acceleration) are not positive or negative (unless of course all 3 components are one or the other). So you should consider the positivity of each in your code.
来源:https://stackoverflow.com/questions/61201292/how-to-find-the-direction-of-acceleration-magnitude-from-three-axes-components-o