Question

I am using this tutorial: http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/ Which gives me a rotating dialer based on an image view. However I am trying to extend it by adding functionality. In order to add this functionality however, I need to get the current clicked position. However, since it uses a rotationMatrix to rotate the imageview, I cannot get a singular position to analyze where the user clicks. Is there a way to crunch the 9 values found in a rotation matrix into one variable which indicates where the user touches?

Was it helpful?

Solution

This is more a computer graphics question than it is an Android question. Using homogeneous coordinates, a clockwise rotation about the origin would be represented as (I'm using Octave / MATLAB notation here to express this):

rotationMatrix = [ cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1 ]

Assuming that the matrix is just doing a rotation about the origin, you can call java.lang.Math.acos and pass in the first value in the array returned by Matrix.getValues to get your theta. That value is in radians, so if you want degrees you'll need to convert it.

OTOH, depending on what you are doing you might just want to call Matrix.invert to obtain the inverse and multiply the point containing the touch coordinates with that inverse Matrix to "undo" the transformations.

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