Sign in to follow this  
polar01

quaternion/point rotation - wrong direction !

Recommended Posts

Hi, I have a quaternion and a point, I would like to rotate the point, so I have 2 methods : 1) r = q * P * q' 2) r = q.RotationMatrix * P In my code, the version 2 work fine, no problem. But the version 1, rotate in the inverse direction ! I have to negate the W to rotate in the correct direction. I would like to understand why I must do this and if it is correct, or maybe there is a problem somewhere else. NB: Is it possible that it is a left-hand / right-hand problem ? Thanks Some code --------- // method 1 public Vector3 Rotate(ref Vector3 point) { Quaternion conj = This.Clone(); conj.Normalize(); conj = conj.UnitInverse; Quaternion qNode = new Quaternion(0, point.x, point.y, point.z); qNode = This * qNode * conj; return new Vector3(qNode.x, qNode.y, qNode.z); } // Method 2 public Matrix3 ToRotationMatrix() { Matrix3 rotation = Matrix3.Identity.Clone(); float length = (x * x) + (y * y) + (z * z) + (w * w); float s = (length > 0f) ? 2f / length : 0f; float xx = x * x; float yy = y * y; float zz = z * z; float xw = x * w; float yw = y * w; float zw = z * w; float xz = x * z; float xy = x * y; float yz = y * z; rotation.M00 = 1f - (s * yy + s * zz); rotation.M10 = s * xy - s * zw; rotation.M20 = s * xz + s * yw; rotation.M01 = s * xy + s * zw; rotation.M11 = 1f - (s * xx + s * zz); rotation.M21 = s * yz - s * xw; rotation.M02 = s * xz - s * yw; rotation.M12 = s * yz + s * xw; rotation.M22 = 1f - (s * xx + s * yy); return rotation; }

Share this post


Link to post
Share on other sites
Did you read the replies to your other thread?

Anyway, it looks to me like you're using column vectors, but your quaternion rotation matrix is set up for row vectors (that is, it should be the transpose of what it is currently). Assuming that you're using 'standard' quaternion multiplication order, that would mean that it's actually version 1 that's correct, and version 2 that's rotating in the 'wrong' direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this