【问题标题】:Can't Correctly rotate 3D Point A to B (on X, Y, Z axis)无法正确将 3D 点 A 旋转到 B(在 X、Y、Z 轴上)
【发布时间】:2017-04-26 16:19:57
【问题描述】:

我已经不知疲倦地研究了三个星期,将3D点'A'旋转到3D点'B'的每一个程序,以下是我尝试过的技术,但没有成功:

  • 旋转矩阵
  • 欧拉角到旋转矩阵
  • 轴角度到旋转矩阵
  • 四元数坐标旋转
  • 三角法多轴旋转

我想在 java 中同时执行 3d 3 轴(所以,X,Y,Z)旋转(请知道我不是特别了解它背后的数学,我希望答案是在 java 代码中,与我展示的示例一样)。

e.g. 
Pointf a = new Pointf(0f, 2f, 0f);
Pointf b = new Pointf(2f, 0f, 2f);

// ~~~ Start of Rotation Matrix ~~~

// azimuth (Z Axis)
float azimuth = (float) Math.toRadians(90f);
// elevation (Y Axis)
float elevation = (float) Math.toRadians(0f);
// tilt (X Axis)
float tilt = (float) Math.toRadians(90f);

/*
public static Matrix4x4f createRotationMatrix(double azimuth, double elevation, double tilt) {
        // Assuming the angles are in radians.
        //Precompute sines and cosines of Euler angles
        double su = sin(tilt);
        double cu = cos(tilt);
        double sv = sin(elevation);
        double cv = cos(elevation);
        double sw = sin(azimuth);
        double cw = cos(azimuth);

        //Create and populate RotationMatrix
        Matrix4x4f A = Matrix4x4f.create();
        A.values[0] = (float) (cv*cw);
        A.values[1] = (float) ((su*sv*cw) - (cu*sw));
        A.values[2] = (float) ((su*sw) + (cu*sv*cw));
        A.values[4] = (float) (cv*sw);
        A.values[5] = (float) ((cu*cw) + (su*sv*sw));
        A.values[6] = (float) ((cu*sv*sw) - (su*cw));
        A.values[8] = (float) -sv;
        A.values[9] = (float) (su*cv);
        A.values[10] = (float) (cu*cv);      

        return A;
    }
*/

// Multiplies the Z * Y * X Rotation Matrices to form 'Matrix4x4f m' 
Matrix4x4f m = Matrix4x4.createRotationMatrix(azimuth, elevation, tilt);

// Multiple point 'a' with Matrix4x4f 'm' to get point 'b'
m.transform(a); // Should return {2, 0, 2} same 'b', but returns {2, 0, 0}

// ~~~ End of Rotation Matrix ~~~

仅供参考。我的主要信息来源如下:

http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/index.htm

谢谢大家

【问题讨论】:

  • PointfMatrix4x4f 是什么?你用的是什么库?
  • 另外,您不能将点 a 旋转到点 b,因为它们与原点的距离不同(点 a 的距离是 2,而点 b 的距离是 sqrt(2^2 + 2^2) = 2.83)。
  • 谢谢,我没有意识到(PointfMatrix4x4f 分别是 3D 点对象和 4 x 4 矩阵对象的任意表示)

标签: java matrix 3d rotation quaternions


【解决方案1】:

我可以解释一个寻找旋转矩阵的算法,虽然我没有代码。

每次旋转都围绕一个轴。我假设您想要一个穿过原点 O 的轴。在这种情况下,旋转发生在由三个点 O、A 和 B 定义的平面内。作为旋转轴,您可以使用向量,即两个向量 OA 和 OB 的叉积。 Here 是公式。

为了简单起见,我们将这个方向向量的三个分量称为轴 (u,v,w)(我们假设它是标准化的)。接下来求OA和OB之间的夹角theta,这是由standard formula找到的两个向量之间的夹角。

最后,困难的部分在this site 为您完成,其中links 到以下围绕原点旋转的 3D 矩阵,它将 A 旋转到 B。这个矩阵的 Java 代码可以在这个站点下载.

您可以以交互方式查看一些旋转here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    • 2021-07-12
    • 1970-01-01
    • 2020-06-05
    • 2021-04-25
    相关资源
    最近更新 更多