How to find correct rotation from one vector to another?

后端 未结 3 1534
南方客
南方客 2021-01-01 02:25

I have two objects, and each object has two vectors:

  • normal vector
  • up vector

Like on this image:

3条回答
  •  无人及你
    2021-01-01 02:52

    The quaternion code rotates just one vector to another without "Up" vector.

    In your case simply build rotation matrix from 3 orthogonal vectors

    1. normalized (unit) direction vector
    2. normalized (unit) up vector
    3. cross product of direction and up vectors.

    Than you will have R1 and R2 matrix (3x3) representing rotation of object in two cases.

    To find rotation from R1 to R2 just do

     R1_to_R2 = R2 * R1.inversed()
    

    And matrix R1_to_R2 is the transformation matrix from one orientation to other. NOTE: R1.inversed() here can be replaced with R1.transposed()

提交回复
热议问题