Why my point does not move in the direction specified by quaternion?

102 Views Asked by At

I have a quaternion q and want to obtain 3 points f, a, b where f (forward) is at the r distance in the direction pointed by the quaternion and a, b are at the r distance in both other two directions, prependicular to the direction pointed by the quaternion. For this, I create the unit vectors pointing in the needed direction, multiply it by the quaternion and then multiply by the distance required, and expect my points to be:

  • f = p + [1,0,0,0] * q * r
  • a = p + [0,1,0,0] * q * r
  • b = p + [0,0,1,0] * q * r

This works well in majority of cases but time to time it ... just does not. Why does it sometimes works and sometimes not? I tried to set the 4th member of the vector also to 1, this sometimes helps but the I get other, different points incorrect. What I am doing wrong? To multiply a vector by the quaternion that has four components, it must be the four member vector. Should I also use the 4th component of my transation vector? If so, how?

1

There are 1 best solutions below

0
On

Do not use the quaternion, use rotation matrix:

  • f = p + [1,0,0] * m * r
  • a = p + [0,1,0] * m * r
  • b = p + [0,0,1] * m * r

where m is a 3x3 rotation matrix (the vectors now only have 3 elements). The solution seems much more stable with the rotation matrix.

Of course, for some this may raise another problem how to convert quaternion to rotation matrix, but in my case it was possible to obtain the rotation matrix directly.