簡體   English   中英

無法正確旋轉 3D 點 A 到 B(在 X、Y、Z 軸上)

[英]Can't Correctly rotate 3D Point A to B (on X, Y, Z axis)

我已經不知疲倦地研究了三個星期,將3D點'A'旋轉到3D點'B'的每一個程序,以下是我嘗試過的技術,但沒有成功:

  • 旋轉矩陣
  • 歐拉角到旋轉矩陣
  • 軸角度到旋轉矩陣
  • 四元數坐標旋轉
  • 三角法多軸旋轉

我想在 java 中同時執行 3d 3 軸(所以,X,Y,Z)旋轉(請知道我不是特別了解它背后的數學,我希望答案在 Z93F725A04,4423D21F486F 示例代碼中)我顯示)。

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

謝謝大家

我可以解釋一個找到旋轉矩陣的算法,盡管我沒有代碼。

每次旋轉都圍繞一個軸。 我假設您想要一個穿過原點 O 的軸。在這種情況下,旋轉發生在由三個點 O、A 和 B 定義的平面內。作為旋轉軸,您可以使用向量,即兩個向量 OA 和 OB 的叉積。 是公式。

在此處輸入圖像描述

為簡單起見,我們將這個方向向量的三個分量稱為軸 (u,v,w)(我們假設它是標准化的)。 接下來找到OA和OB之間的角度θ,這是通過兩個向量之間角度的標准公式找到的。

最后,在這個站點為您完成了最困難的部分,它鏈接到以下關於原點旋轉的 3D 矩陣,它將 A 旋轉到 B。可以在此站點下載該矩陣的 Java 代碼。

在此處輸入圖像描述

您可以在此處以交互方式查看一些旋轉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM