旋转矩阵给定角度和点在X,Y,Z [英] Rotation Matrix given angle and point in X,Y,Z
问题描述
我做的图像处理,我想旋转都基于一个角度,起源,和X,Y在XYZ空间像素和z坐标。
I am doing image manipulation and I want to rotate all of the pixels in xyz space based on an angle, the origin, and an x,y, and z coordinate.
我只需要设置正确的矩阵(4×4),然后我会好从那里。角度是在度,而不是弧度和将x,y,z的所有将要从-1到1(浮子)
I just need to setup the proper matrix (4x4) and then I will be good from there. The Angle is in degrees, not radians and the x,y,z are all going to be from -1 to 1 (floats)
编辑:
好吧,这里是code,我掀起了做有关的起源和X定义了一个给定行的旋转,Y,Z coorinate。
Ok, here is the code that I whipped up to do the rotation about a given line defined by the origin and an X, Y, Z coorinate.
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));
这是一个有点复杂,我用一个自定义的矩阵库,但没有在那里应该不会太难任何功能矩阵LIB实现。
It's a little complicated and I'm using a custom Matrix library, but nothing up there should be too hard to implement with any functioning Matrix lib.
呼,很多数学的!
推荐答案
完整的旋转矩阵推导,并在给定的<一个href=\"https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas\">https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas.
The complete rotation matrices are derived and given at https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas.
从纸:
5.2关于原点旋转简化矩阵
5.2 The simplified matrix for rotations about the origin
请注意这个假设(U,V,W)是旋转轴,美^ 2 + V ^ 2 + W ^ 2 = 1。
Note this assumes that (u, v, w) is a direction vector for the axis of rotation and that u^2 + v^2 + w^2 = 1.
如果您有要旋转点(X,Y,Z),那么我们可以得到的七个变量能够产生旋转点的功能:
If you have a point (x, y, z) that you want to rotate, then we can obtain a function of of seven variables that yields the rotated point:
的˚F的(X,Y,Z,U,V,W,THETA)=
f(x, y, z, u, v, w, theta) =
文中还包括了约一个任意轴的旋转矩阵和公式(不一定通过原点),爪哇$ C $提供Apache许可证下的c和一个Web应用程序,说明旋转的链接。
The paper also includes matrices and formulas for rotations about an arbitrary axis (not necessarily through the origin), Java code available under the Apache license, and a link to a web app that illustrates rotations.
这篇关于旋转矩阵给定角度和点在X,Y,Z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!