Hi,
I thought I understood the idea behind quaternions--they have the form <scalar, 3d vector>, where the scalar is an angle. Then where q = <alpha, qv> is a quaternion and v is a 3d vector, q * v * conjugate(q) produces v', which is the rotation of v around qv by angle alpha. The q*v*conj(q) is conveniently encapsulated in QVector3D QQuaternion::rotatedVector(QVector3D).
Anyway, I clearly do *not* understand quaternions, or at least not QQuaternions. Here is the code I am using to do vector rotations:
Qt Code:
double vecx, vecy, vecz, angle, quatx, quaty, quatz; ... //The above arguments are initialized... QVector3D vpre(vecx, vecy, vecz), vpost; QQuaternion quat(angle*pi/180.0,quatx,quaty,quatz); vpost = quat.rotatedVector(vpre);To copy to clipboard, switch view to plain text mode
Now here is what happens, in pseudocode. NB I use degrees below for convenience, but my code converts them to radians as per above.
I've spent about a day trying to crack the system that is being used to calculated the rotation, with no luck. Could someone please please lead me out of my confusion?vpre(1,0,0)
quat(90,0,0,1)
Expected: vpost = (0,1,0) //Rotation about z axis
Actual: vpost = (1.4674, pi, 0)
vpre(1,0,0)
quat(90,1,0,0)
Expected: vpost = (1,0,0) //vpre is the unit x vector, so this rotation shouldn't change anything
Actual: vpost = (3.4674, 0, 0)
vpre(1,0,0)
quat(0,0,0,1)
Expected: vpost = (1,0,0) //angle== 0, so expect no rotation
Actual: vpost = (-1,0,0) //Rotated 180 degrees
vpre(1,0,0)
quat(0,0,0,5)
Expected: vpost = (1,0,0) or (-1,0,0) given the above //The length of the vector shouldn't matter, just its direction
Actual: vpost = (-25,0,0)
vpre(1,0,0)
quat(360,0,0,1) //Now, rotating in a full circle
Expected: vpost = (1,0,0) or (-1,0,0) given the above
Actual: vpost = (38.4784,12.5664,0)
Matt
Bookmarks