4

我有 2 个向量(V1{x1, y1, z1}, V2{x2, y2, z2}),我想V1X 轴Y 轴Z 轴旋转以平行于V2。我想找到3个旋转角度。有什么通用公式可以用来找到它们吗?

4

2 回答 2

3

我会这样做:

    A = V1xV2; //Cross product, this gives the axis of rotation
    sin_angle =  length(A)/( |V1| |V2|); //sine of the angle between vectors

    angle = asin(sin_angle);
    A_n = normalize(A);

现在你可以用角度和 A_n 构建一个四元数。

    q = (A_n.x i + A_n.y j + A_n.z k)*sin(angle/2) + cos(angle/2);

并使用这些公式来获得你的欧拉角。

于 2012-04-15T11:38:05.770 回答
1

Do you really need the rotation angles, or is it a rotation matrix you're looking for. If the latter, you can do it the way it's done in OpenFOAM: http://github.com/OpenFOAM/OpenFOAM-2.1.x/blob/master/src/OpenFOAM/primitives/transform/transform.H#L45

Note that in OpenFOAM for vector the & operator denotes the inner product, the ^ operator the cross product and * is the outer product. The sqr function computes the element-wise squares, magSqr the square of the magnitude of a vector (i.e. v&v).

于 2012-04-15T12:25:19.220 回答