FromToRotation背后的数学是什么? Unity3d

时间:2018-07-27 00:58:42

标签: unity3d math quaternions

我试图更好地理解四元数,但是我不知道FromToRotation背后的数学原理。我尝试查找此内容,但找不到任何结果。

1 个答案:

答案 0 :(得分:2)

You may know that a rotation can be represented by a quaternion of the following form:

cos (phi / 2)
sin (phi / 2) * axis.x
sin (phi / 2) * axis.y
sin (phi / 2) * axis.z

axis is the rotation axis and phi is the rotation angle. These are the two measures you need to define your quaternion.

There are multiple rotations that map a vector from to another vector to. The shortest rotation is the one where the axis is perpendicular to both of the vectors. Hence, the axis is:

axis = normalize(from x to)

x denotes the cross product.

And the angle is the angle between the two vectors:

phi = acos(dot(from, to) / (norm(from) * norm(to))

norm is the vector norm or vector length.

With these values, you can then calculate the quaternion.