tags:

views:

542

answers:

2

Hello, I have matrix. This matrix represents array x and y coordinates. For example

float[] src = {7,1,7,2,7,3,7,4};

I need to rotate this coordinates to 90 degrees. I use android.graphics.Matrix like this:

    float[] src = {7,1,7,2,7,3,7,4};
    float[] dist = new float[8];
    Matrix matrix = new Matrix();
    matrix.preRotate(90.0f);
    matrix.mapPoints(dist,src);

after operation rotate I have array with next values

-1.0    7.0     -2.0    7.0     -3.0    7.0     -4.0    7.0

Its is good for area with 360 degrees. And how do rotate in area from 0 to 90? I need set up center of circle in this area but how ?
Thanks.

A: 

I'm not familiar with android, but if you translate after you rotate you can get a rotation around a specific point. Find where your center point would be rotated to, then translate it back to it's original position.

cobbal
I think you mean: "If you rotate after you translate you can get a rotation around a specific point"
Eyal Schneider
@Eyal either works actually, but the translation is different in each case
cobbal
@cobbal: you are right. However, I believe that in the translate-rotate-translate approach, the translation parameters are much simpler to compute, right?
Eyal Schneider
+1  A: 

use setRotate not preRotate

setRotate initializes the matrix as a rotation matrix

preRotate multiplies the current Matrix by a Rotation matrix M` = M x R

Since you called the default constructor your starting with the identity matrix.

Remember matrix multiplication is not commutative.

Mark
setRotate returns the same result :(
jitm
I'm confused, i actually looked at your numbers and rotating the points (7,1), (7,2), (7,3), (7,4) 90 degrees around the origin should result in (7,-1), (7,-2), (7,-3), (7,-4). Which is what you got. You example is the correct rotation of these points.
Mark
Why, I did rotation for 90 degrees and my points moved from area 0 -90 to area 90-180. The second area contains positive Y and negative X. So you wrote (7,-1), (7,-2), (7,-3), (7,-4) where first number is X and second is Y. I think this incorrect because area 90 -180 does not contain negative Y.
jitm
Yes, you was correct setRotate(90,x,y) but set rotate with center of rotation ... not only value of angel.
jitm