# quaternion/point rotation - wrong direction !

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

## 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 on other sites

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.

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632943
• Total Posts
3009349
• ### Who's Online (See full list)

There are no registered users currently online

×