java Android 旋转矩阵
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2767407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Rotate Matrix
提问by jitm
I have matrix. This matrix represents array x and y coordinates. For example
我有矩阵。此矩阵表示数组 x 和 y 坐标。例如
float[] src = {7,1,7,2,7,3,7,4};
I need to rotate this coordinates to 90 degrees.
I use android.graphics.Matrixlike this:
我需要将此坐标旋转 90 度。我这样使用 android.graphics.Matrix:
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.
它适用于 360 度的区域。以及如何从 0 到 90 的区域旋转?我需要在这个区域设置圆心,但如何设置?
谢谢。
回答by Mark
Use setRotate, not preRotate:
使用setRotate,而不是preRotate:
setRotateinitializes the matrix as a rotation matrix.preRotatemultiplies the current matrix by a rotation matrixM' = M x R
setRotate将矩阵初始化为旋转矩阵。preRotate将当前矩阵乘以旋转矩阵M' = M x R
Since you called the default constructor your starting with the identity matrix.
由于您从单位矩阵开始调用默认构造函数。
Remember matrix multiplication is not commutative.
记住矩阵乘法不是可交换的。
回答by cobbal
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.
我不熟悉android,但是如果在旋转后进行平移,则可以围绕特定点进行旋转。找到您的中心点将旋转到的位置,然后将其转换回原来的位置。
回答by Ribo
Use the MatrixpreRotate(float degrees, float px, float py)method (preRotatedocumenation)
使用MatrixpreRotate(float degrees, float px, float py)方法(preRotate文档)
This preRoate(degrees)is equivalent to preRotate(degrees, 0, 0).
这preRoate(degrees)相当于preRotate(degrees, 0, 0).

