[英]What is wrong with my rotation matrix?
//---------------------------------------------------------------------------
// arbitraryRotate - rotates v theta degrees around n
//---------------------------------------------------------------------------
private static Vector3D arbitraryRotate(Vector3D v, Vector3D n, double theta)
{
theta = Math.toRadians(theta);
double cosTheta = Math.cos(theta);
double sinTheta = Math.sin(theta);
double M11 = n.x * n.x * (1 - cosTheta) + cosTheta;
double M12 = n.x * n.y * (1 - cosTheta) + (n.z * sinTheta);
double M13 = n.x * n.z * (1 - cosTheta) - (n.y * sinTheta);
double M21 = n.x * n.y * (1 - cosTheta) - (n.z * sinTheta);
double M22 = n.y * n.y * (1 - cosTheta) + cosTheta;
double M23 = n.y * n.z * (1 - cosTheta) + (n.x * sinTheta);
double M31 = n.x * n.z * (1 - cosTheta) + (n.y * sinTheta);
double M32 = n.y * n.z * (1 - cosTheta) - (n.x * sinTheta);
double M33 = n.z * n.z * (1 - cosTheta) + cosTheta;
return new Vector3D(v.x * M11 + v.y * M21 + v.z * M31,
v.x * M12 + v.y * M22 + v.z * M32,
v.x * M13 + v.y * M23 + v.z * M33);
}
Could anyone tell me what is wrong with my matrix please? 谁能告诉我我的矩阵出了什么问题? Rotation around the Z-Axis works perfectly however X and Y axis rotations result in distortions. 绕Z轴旋转的效果很好,但是X和Y轴旋转会导致变形。
Your matrix is set up improperly. 您的矩阵设置不正确。 Here is how you rotate properly 这是您正确旋转的方式
You get 你得到
new vector = (Rx^-1)(Ry^-1)RzRyRx(original vector)
Here's a link that spells it out well. 这里的链接说明得很好。 You don't have to extend your vectors and matrices to 4 dimensions - that's only for the purpose of translation if you're rotating about an arbitrary line in space, not a vector stemming from the origin. 您不必将向量和矩阵扩展到4维-仅出于绕空间中的任意线旋转而不是源于原点的向量旋转的目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.