Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I have two orientation quaternions, how do I find the rotation quaternion needed to go from one to the other?

I'm using quaternions in my game, and I'm wondering how, when I have two orientation quaternions, I can get the rotation quaternion needed to go from the first one, q1, to the second one, q2. I'm self taught, so there may be obvious solutions missing from my vocabulary.

In equations, what I'm doing when I rotate from the first one to the other is as follows: q2 = r * q1

However, now r is the unknown. Do the rules of algebra count here too? If that's the case, I'd end up dividing a quaternion by another, something I can't find a good explanation for on the internet.

I'm using a program called game maker

like image 843
Sindre Avatar asked Jan 08 '12 20:01

Sindre


People also ask

How do you find the rotation between two quaternions?

Using quaternions¶ The distance between rotations represented by unit quaternions p and q is the angle of the difference rotation represented by the unit quaternion r = p q ∗ . with ⟨ p , q ⟩ = p 1 q 1 + p 2 q 2 + p 3 q 3 + p 4 q 4 and | ⋅ | the modulus function.

How do you rotate a quaternion by another quaternion?

Use the Quaternion operator * . In Unity, when you multiply two quaternions, it applies the second quaternion (expressed in global axes) to the first quaternion along the local axes produced after the first Quaternion ). So, if you want to do the equivalent of Rotate(q2, Space.

Can two quaternions represent same rotation?

If a quaternion is multiplied by any real number, it still represents the same rotation in R3. That's the only way two quaternions can represent the same rotation.

How do you find the quaternion between two vectors?

You can convert to a quaternion by using q=cos(θ/2)+(uxˆi+uyˆj+uzˆk)sin(θ/2), where ux, uy and uz are the components of the rotation axis, θ is the rotation angle and ˆi, ˆj and ˆk are the components of the quaternion.


2 Answers

You should have a look to this page (euclideanspace), it is really interesting for self-teaching and understanding quaternions.

Here you have the arithmetics for quaternions and also a calculator that makes the operations for you:

http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/arithmetic/index.htm

Hope it helps.

like image 52
Jav_Rock Avatar answered Oct 12 '22 13:10

Jav_Rock


In order to "divide" with a quaternion, you invert it so that it's the opposite rotation. In order to invert a quaternion, you negate either the w component or the (x, y, z) components, but not both since that would leave you with the same quaternion you started with (a fully negated quaternion represents the same rotation).

Then, remember that quaternions aren't commutative. So:

q2 = r*q1
q2*q1' = r

Where q1' is the inverted quaternion and it must be multiplied on the right side of q2 to get the right result.

like image 34
JCooper Avatar answered Oct 12 '22 13:10

JCooper