Question

Calculate resultant acceleration from x and y. Calculate angle of resultant acceleration.

Was it helpful?

Solution

You can use vector maths to calculate the vector's length and angle:

length = sqrt(x * x + y * y)
angle = atan2(y, x) //this might be changed depending on your angle definitions

OTHER TIPS

You dont need the x and y acceleration, just calculate the acceleration as speed change per time.
For Gps i reccommend to use the speed attribute of the location, which is much more accurate then the positions.
If you dont have speed, then calculate speed as distance per time.

Distance: use any distance formula you find for calculate distance between two lat/lon coordinates.

If you want to use the values you got from the acceleration sensor, then you should use 3-axis acceleration vector:
See also how-do-i-get-the-total-acceleration-from-3-axes

One further tipp to check if implementation is plausible:
Sum up all your (one dimension) accelerations, they shoud be near 0.

If you want the direction of the acceleration with respect to the world coordinate system, then you have to register for both TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD. Using the results you call getRotationMatrix and then multiply the accelerometer values by this matrix will give you the coordinates of the acceleration in term of the world coordinate system. The first 2 coordinates would be the x and y coordinates.
Actually you better also register for TYPE_GRAVITY and pass the results together with the magnetic field results to the getRotationMatrix, so that you do not have to filter accelerometer values yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top