简体   繁体   English

无法正确旋转 3D 点 A 到 B(在 X、Y、Z 轴上)

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

I has tirelessly been researching for three weeks now, each and every procedure for rotating a 3D Point 'A' to 3D Point 'B', the following are the techniques I attempted with no success:我已经不知疲倦地研究了三个星期,将3D点'A'旋转到3D点'B'的每一个程序,以下是我尝试过的技术,但没有成功:

  • Rotation Matrix旋转矩阵
  • Euler Angles to Rotation Matrix欧拉角到旋转矩阵
  • Axis Angle to Rotation Matrix轴角度到旋转矩阵
  • Quaternion Coordinate Rotation四元数坐标旋转
  • Trigonometry Multiple Axis Rotation三角法多轴旋转

I would like to perform a simultaneous 3d 3 axis (so, X, Y, Z) rotation in java (please know I don't particularly understand the mathematics behind it, I would prefer the answer to be in java code, with the example I displayed).我想在 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 ~~~

FYI.供参考。 My main source of information was from the following:我的主要信息来源如下:

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

Thanks All谢谢大家

I can explain an algorithm for finding the matrix of rotation, though I don't have code for it.我可以解释一个找到旋转矩阵的算法,尽管我没有代码。

Every rotation is around an axis.每次旋转都围绕一个轴。 I assume that you want an axis that goes through the origin O. In that case, the rotation takes place in the plane defined by the three points O, A, and B. As the rotation axis, you can use the vector which is the cross product of the two vectors OA and OB.我假设您想要一个穿过原点 O 的轴。在这种情况下,旋转发生在由三个点 O、A 和 B 定义的平面内。作为旋转轴,您可以使用向量,即两个向量 OA 和 OB 的叉积。 Here is the formula.是公式。

在此处输入图像描述

Let's call the three components of this direction vector for the axis (u,v,w), for simplicity (and we'll assume its normalized).为简单起见,我们将这个方向向量的三个分量称为轴 (u,v,w)(我们假设它是标准化的)。 Next find the angle theta between OA and OB, this is found by the standard formula for the angle between two vectors.接下来找到OA和OB之间的角度θ,这是通过两个向量之间角度的标准公式找到的。

Finally, the hard part is done for you at this site , which links to the following 3D matrix of rotation about the origin, which will rotate A to B. Java code for this matrix can be downloaded at this site.最后,在这个站点为您完成了最困难的部分,它链接到以下关于原点旋转的 3D 矩阵,它将 A 旋转到 B。可以在此站点下载该矩阵的 Java 代码。

在此处输入图像描述

You can check out some rotations interactively here .您可以在此处以交互方式查看一些旋转。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我该如何处理2D图像并将其围绕X,Y或Z轴旋转,就好像它是3D image.in Java一样? - how can i do to a 2D image and spin it around it's X, Y, or Z axis as if it were a 3D image.in java? 处理:使用四元数旋转3D对象适用于x轴,但不适用于y或z轴吗? - Processing: Rotating a 3D object using Quaternions works for x-axis, but not for y or z axis? 向量围绕3D空间中具有特定x,y&z角度的点的旋转[JAVA] - Rotation of a Vector around a point in 3D space with specific x,y&z angles [JAVA] (处理)如何根据屏幕的XY轴移动3D对象,而不是世界的X,Y,Z(PeasyCam) - (Processing)How to move a 3D object according to the screen's XY axis, instead of the world's X,Y,Z(PeasyCam) 透视投影:确定3D空间(x,y,z)中点的2D屏幕坐标(x,y) - Perspective Projection: determine the 2D screen coordinates (x,y) of points in 3D space (x,y,z) JFreeChart 3D 条形图——不能增加 Z 轴深度 - JFreeChart 3D bar chart— can't increase Z axis depth 如何获取Point2D的X轴和Y轴? - How to retrieve the X- and Y- axis of a Point2D? 有没有一种简单的方法可以使用Java绕z轴旋转图像而无需跳入Java 3d? - Is there any easy way to rotate an image about z axis using java without jumping into java 3d? 如何使用Java3D API在java中绘制简单的3D点(x,y,z)? - How to draw simple 3D points(x,y,z) in java using Java3D API? 在JavaFX中正确旋转3轴上的3D对象 - Rotate a 3D object on 3 axis in JavaFX properly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM