Jump to content
  • Advertisement
Sign in to follow this  
obhi

Rotating vectors using quaternion.

This topic is 3349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

please help me out here: I've been trying to rotate a vector using a rotation matrix and then the same vector by a normalized quaternion generated from the same matrix. Both yield different results. Now I tried my own functions then tried D3DX* functions, but that did not change the results. Where did I go wrong?? My input matrix (in D3D format (row major)): -0.96281999 -0.27014399 0.00000000 0.00000000 0.012030500 -0.042872600 -0.99900800 0.00000000 -0.26987600 0.96186501 -0.044528902 0.00000000 0.00000000 0.00000000 0.00000000 1.0000000 My input vector: (19.533800, 0, 0)

Share this post


Link to post
Share on other sites
Advertisement
Just a tiny unrelated pendantic point. I believe the term you meant was "row vector" not "row major."

Majorness is how the values are stored in memory. Vectoredness is how the basis vectors are stored in the matrix, regardless of how they're stored in memory.

If you values, in the format you posted, were correlated with memory indices.

Row major would look like this:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

Where as Column major would look like this:
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

As you can see, the index mapping is irrelevant in your case (that is the majorness). What is important is that we know where the basis vectors are stored, in rows or in columns.

Share this post


Link to post
Share on other sites
Quote:
Original post by bzroom
Just a tiny unrelated pendantic point. I believe the term you meant was "row vector" not "row major."

Majorness is how the values are stored in memory. Vectoredness is how the basis vectors are stored in the matrix, regardless of how they're stored in memory.

If you values, in the format you posted, were correlated with memory indices.

Row major would look like this:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15

Where as Column major would look like this:
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

As you can see, the index mapping is irrelevant in your case (that is the majorness). What is important is that we know where the basis vectors are stored, in rows or in columns.


In fact majorness does not matter here. Anyways since I mentioned D3D it should have been understood that the matrix is row vector.

Share this post


Link to post
Share on other sites
Strangely when I tested it in the last few minutes, I also found that after converting the rotation matrix into a quaternion and back from that quaternion to another rotation matrix and then rotating the same vector using this later one yields the same result as the quaternion did. So the two matrices have different basis because the starting matrix yields a different result. I am pretty confused right now :(


making it more clear:
D3DXMATRIX rotation,rerot; // initial rotation matrix
D3DXQUATERNION quat,normquat;
D3DXVECTOR4 ret1,ret2;
D3DXVECTOR3 v(19.3f,0,0); // the value is inaccurate
InitializeMatrix(rotation);
D3DXQuaternionRotationMatrix(&quat,&rotation)
D3DXQuaternionNormalize(&normquat,&quat);
D3DXMatrixRotationQuaternion(&rerot,&normquat);
D3DXVec3Transform(&ret1,&v,&rerot); //
D3DXVec3Transform(&ret2,&v,&rotation); //
// ret1 is different from ret2
rotating v with normquat will give ret1

Share this post


Link to post
Share on other sites
Given the input I specified earlier, the D3DX functions actually do not work. I also checked if the input matrix was orthogonal and results were fine.
D3DX functions work for any other input however.
I think I found my error.

SOLVED:
Decomposing the matrix returns a proper quaternion. Probably the problem occured due to inverse scaling ((1,1,-1) i.e. ). I'm not sure but the decomposition shows this scaling.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!