Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Rotate Matrix

Tags:

java

android

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.

like image 675
jitm Avatar asked May 04 '10 17:05

jitm


People also ask

What is rotation matrix in Android?

In the context of Android sensors, the rotation matrix is telling you how to map a point from the co-ordinate system of the phone (where the phone itself lies in the x-y plane) to the real world North/East/"Gravity-direction" co-ordinate system. Android uses either 3x3 or 4x4 rotation matrices.

What is matrix in Android?

Just think of a matrix as an array of numbers. In this case, an Android Matrix has 3 rows of 3 numbers. Each number tells an Android graphics function what to do to scale (bigger/smaller), translate (move), rotate (turn) or skew (distort in a 2D plane) the "thing" which the matrix is applied to.

What is image matrix in Android?

Matrix is the class that be used to process images in android. This article will show you examples of how to use android. graphics. Matrix to rotate, scale, skew and translate bitmap images in android.


1 Answers

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.

like image 124
Mark Avatar answered Sep 27 '22 19:09

Mark