|
I want to find a relative rotation between two quaternions quatA and quatB, i.e. quatC is a quaternion rotation that if applied to quatA would result in quatB. Basically I want something like this:
The only way I can think of to do it is to make two Transforms modA and modB, with modB the child of modA, and use the following code:
However I would prefer not to use Transforms, and just use quaternions instead. This previous answer suggests the following code would work:
But it doesn't appear to work after all, as it only inputs two direction vectors, not rotations. To demonstrate this, attach the following script to a basic cube dragged into an empty scene. The code will position and size the cube. Modify rotations for models A and/or B. Model C should display the RELATIVE rotation FROM A TO B. In other words, applying C's rotation to A's rotation should result in B's rotation. Model D shows the ACTUAL result of applying C's rotation to A's rotation. If C showed the actual relative rotation, D would be identical to B. As you will see, this is NOT the case. Hopefully I'm just missing something, but if not, is there a way to get quatC only with code?
(comments are locked)
|
|
This should do it: Nearly! I tested it both ways and it's actually the other way round - "Quaternion relative = Quaternion.Inverse(a) * b;" works a charm. Thanks! I'll tick this answer, maybe you could update it?
Nov 27 '10 at 05:23 PM
robinking
Oh strange, I tested that like 5 times, I must have had a thinko when I wrote it in here. Fixing it now
Nov 27 '10 at 05:50 PM
Mike 3
Thanks! It helped me too. I used to have headache from some problem with planets, and had been suffered with that for weeks, and with this solution anything got to work. Thanks again.:)
Mar 30 '12 at 08:44 AM
Mahamed9628
Very handy!
Sep 22 '12 at 06:03 AM
Favo Yang
(comments are locked)
|
