我正在进行图像处理,我想根据角度,原点以及x,y和z坐标旋转xyz空间中的所有像素.
我只需要设置正确的矩阵(4x4)然后我就会很好.角度是度,而不是弧度,x,y,z都是从-1到1(浮点数)
编辑:
好的,这是我为了由原点和X,Y,Z坐标定义的给定线进行旋转而编写的代码.
float ang = angD * (float)(Math.PI / 180); // from degrees to radians, if needed
//U = n*n(t) + cos(a)*(I-n*n(t)) + sin(a)*N(x).
var u = MatrixDouble.Identity(4); // 4x4 Identity Matrix
u = u.Multiply(Math.Cos(ang));
var n = new MatrixDouble(1, 4, new List<double> { x, y, z, 0 });
var nt = n.Transpose();
// This next part is the N(x) matrix. The data is inputted in Column
// first order and fills in the 4x4 matrix with the given 16 Doubles
var nx = new MatrixDouble(4, 4, new List<double> { 0, z, -y, 0, -z, 0, x, 0, y, -x, 0, 0, 0, 0, 0, 1 });
nx = nx.Multiply(Math.Sin(ang));
var ret = nt.Multiply(n);
ret[3, 3] = 1;
u = u.Subtract(ret);
u = ret.Add(u.Add(nx));
Run Code Online (Sandbox Code Playgroud)
这有点复杂,我正在使用一个自定义的Matrix库,但没有任何东西应该太难实现任何功能的Matrix lib.
P,很多数学!
完整的轮播矩阵派生自https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas.
从论文:
5.2关于原点旋转的简化矩阵
注意,这假设(u,v,w)是旋转轴的方向向量,并且u ^ 2 + v ^ 2 + w ^ 2 = 1.

如果你有一个想要旋转的点(x,y,z),那么我们可以得到七个变量的函数,产生旋转点:
f(x,y,z,u,v,w,theta)=

本文还包括关于任意轴(不一定是通过原点)的旋转的矩阵和公式,Apache许可下可用的Java代码,以及说明旋转的Web应用程序的链接.