gpt4 book ai didi

c# - 旋转矩阵给定角度和 X、Y、Z 中的点

转载 作者:太空狗 更新时间:2023-10-30 00:27:47 25 4
gpt4 key购买 nike

我正在进行图像处理,我想根据角度、原点以及 x、y 和 z 坐标旋转 xyz 空间中的所有像素。

我只需要设置适当的矩阵 (4x4),然后就可以了。角度以度为单位,而不是弧度,x、y、z 都将从 -1 到 1( float )

编辑:

好的,这是我编写的代码,用于围绕由原点和 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));

它有点复杂,我使用的是自定义 Matrix 库,但使用任何正常运行的 Matrix 库应该都不会太难实现。

哎呀,很多数学知识!

最佳答案

完整的旋转矩阵是在 https://sites.google.com/site/glennmurray/glenn-murray-ph-d/rotation-matrices-and-formulas/rotation-about-an-arbitrary-axis-in-3-dimensions 推导和给出的.

来自论文:

5.2 绕原点旋转的简化矩阵

请注意,这里假设 (u, v, w) 是旋转轴的方向向量,并且 u^2 + v^2 + w^2 = 1。

Simplified 3D matrix for rotations about the origin.

如果您有一个点 (x, y, z) 想要旋转,那么我们可以获得一个包含七个变量的函数来生成旋转后的点:

f(x、y、z、u、v、w、theta)=

Formula for rotated point.

该论文还包含用于围绕任意轴(不一定通过原点)旋转的矩阵和公式、在 Apache 许可下可用的 Java 代码,以及指向说明旋转的 Web 应用程序的链接。

关于c# - 旋转矩阵给定角度和 X、Y、Z 中的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5188876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com