Reputation: 1648
I can't seem to get my quaternion math right... Even the basic concepts are beyond my simple brain right now...
Trying to figure out reference frames and how to rotate from one to another. I'm using Unity to test this stuff, so LH-ed.
Suppose I want to rotate a point at 0,0,1 through 90 degrees around X first, then 80 degrees around Z. It should end up at 0.9848, -0.1730, 0. I can do this math with graph paper.
But the quaternion to supposedly rotate from rotation A to rotation B, I can't remember what I'm doing wrong, but it's certainly wrong. Something fundamental about my understanding about moving from one reference frame to another is off, and I'm too tired to figure it out...
Thought A.Inverse() * B would "rotate from A's reference frame to B through a rotation" and calculate the delta "B-A". When I apply this to vector 0, 0, 1, it results in V' = 0.9848, 0, 0.1736. Somehow, the 0.1736 ended up in Z instead of Y.
Quaternion A = Quaternion.Euler(90, 0, 0);
Quaternion B = Quaternion.Euler(0, 0, 80);
// Q(B-A) = QFromAtoB = QA.Inverse * QB
Quaternion q = Quaternion.Inverse(A) * B;
Vector3 pStart = new Vector3(0, 0, 1);
Vector3 pRotatedToA = A * pStart;
Vector3 pRotatedToB = B * pRotatedToA;
Vector3 pWrong = q * pRotatedToA; // gets us from A to B?
Upvotes: 0
Views: 309
Reputation: 1410
A is your first rotation; B is your second rotation.
R = B * A is the total rotation.
The "pure" quaterion Q = (0,0,0,1) represents the Vector (0,0,1).
The rotated "pure" quaternion = R * Q * Quaternion.Inverse(R).
This gives what you expect: (0, .985, -.174, 0).
You are not changing reference frames, and any delta is not involved.
Upvotes: 1