Questions tagged [quaternions]

Unit quaternions are a mathematical representation of 3D rotations. They have 4 dimensions (one real and 3 imaginary) and can be represented as follows: a + i b + j c + k d or in terms of axis-angles: q = cos(a/2) + i ( x * sin(a/2)) + j (y * sin(a/2)) + k ( z * sin(a/2)) where: - a=angle of rotation. - x,y,z = vector representing axis of rotation.

A quaternion is a representation of a rotation from one coordinate frame to another coordinate frame. The mathematical relationship is given below:

If we have a quaternion:

q =  qw + i qx + j qy + k qz ;

The direction cosine matrix that represents the same rotation is given by:

   | 1 - 2*qy2 - 2*qz2   2*qx*qy - 2*qz*qw  2*qx*qz + 2*qy*qw |
   | 2*qx*qy + 2*qz*qw   1 - 2*qx2 - 2*qz2  2*qy*qz - 2*qx*qw |
   | 2*qx*qz - 2*qy*qw   2*qy*qz + 2*qx*qw  1 - 2*qx2 - 2*qy2 |

More information:

1469 questions
132
votes
9 answers

Why are quaternions used for rotations?

I'm a physicist, and have been learning some programming, and have come across a lot of people using quaternions for rotations instead of writing things in matrix/vector form. In physics, there are very good reasons we don't use quaternions…
JMP
  • 1,457
  • 2
  • 10
  • 5
132
votes
10 answers

Finding quaternion representing the rotation from one vector to another

I have two vectors u and v. Is there a way of finding a quaternion representing the rotation from u to v?
sdfqwerqaz1
  • 1,447
  • 2
  • 10
  • 8
69
votes
15 answers

"Average" of multiple quaternions?

I'm trying to make the switch from matrices to quaternions for skeletal animation in my OpenGL program, but I've encountered a problem: Given a number of unit quaternions, I need to get a quaternion that when used to transform a vector will give a…
jonathan
  • 791
  • 1
  • 6
  • 6
48
votes
5 answers

Component of a quaternion rotation around an axis

I'm having trouble finding any good information on this topic. Basically I want to find the component of a quaternion rotation, that is around a given axis (not necessarily X, Y or Z - any arbitrary unit vector). Sort of like projecting a quaternion…
Ben Hymers
  • 25,586
  • 16
  • 59
  • 84
41
votes
6 answers

Extracting Yaw from a Quaternion

I have a rotation quaternion and want to extract the angle of rotation about the Up axis (the yaw). I am using XNA and as far as I can tell there is no inbuilt function for this. What is the best way to do this? Thanks for any help, Venatu
Venatu
  • 1,264
  • 1
  • 13
  • 24
32
votes
8 answers

Is there an algorithm for converting quaternion rotations to Euler angle rotations?

Is there an existing algorithm for converting a quaternion representation of a rotation to an Euler angle representation? The rotation order for the Euler representation is known and can be any of the six permutations (i.e. xyz, xzy, yxz, yzx, zxy,…
Will Baker
  • 2,747
  • 4
  • 20
  • 17
28
votes
2 answers

'Difference' between two quaternions

I'm working in Ogre, but it's a general quaternion problem. I have an object, to which I apply a rotation quaternion Q1 initially. Later, I want to make it as if I initially rotated the object by a different quaternion Q2. How do I calculate the…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
27
votes
8 answers

quaternion libraries in C/C++

Any good libraries for quaternion calculations in C/C++ ? Side note: any good tutorials/examples? I've google it and been to the first few pages but maybe you have have some demos/labs from compsci or math courses you could/would share? Thanks
cbrulak
  • 15,436
  • 20
  • 61
  • 101
27
votes
6 answers

Quaternion and normalization

I know that quaternions need to be normalized if I want to rotate a vector. But are there any reasons to not automatically normalize a quaternion? And if there are, what quaternion operations do result in non-normalized quaternions? Multiplying…
Sebastian Krysmanski
  • 8,114
  • 10
  • 49
  • 91
26
votes
5 answers

Difference between the two quaternions

Solved I'm making a 3D portal system in my engine (like Portal game). Each of the portals has its own orientation saved in a quaternion. To render the virtual scene in one of the portals I need to calculate the difference between the two…
Tom
  • 1,027
  • 2
  • 16
  • 35
23
votes
2 answers

What's a quaternion rotation?

Is quaternion rotation just a vector with X,Y,Z which the object will rotate towards, and a roll which turns the object on its axis? Is it that simple? Meaning if you have X=0, Z=0 and Y=1 the object will face upwards? And if you have Y=0, Z=0 and…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
22
votes
6 answers

When do I need to use quaternions?

I have been carrying out 2D and 3D operations, including graphics, for many years and have never used quaternions so I don't have a feel for them. I know that they can be used for certain operations that are difficult in Euler angles and also that…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
22
votes
4 answers

Implementing a complex rotation-based camera

I am implementing a 3D engine for spatial visualisation, and am writing a camera with the following navigation features: Rotate the camera (ie, analogous to rotating your head) Rotate around an arbitrary 3D point (a point in space, which is…
David
  • 13,360
  • 7
  • 66
  • 130
21
votes
1 answer

Converting a direction vector to a quaternion rotation

I can find a ton of questions about turning a quaternion into a direction vector but none for the other way around which makes me think I'm doing something wrong, but bear with me. What I'm trying to do is simply display the direction of a…
Caustic
  • 377
  • 1
  • 2
  • 9
21
votes
4 answers

Convert Quaternion rotation to rotation matrix?

Basically, given a quaterion (qx, qy, qz, qw)... How can i convert that to an OpenGL rotation matrix? I'm also interested in which matrix row is "Up", "Right", "Forward" etc... I have a camera rotation in quaternion that I need in vectors...
DigitalZebra
  • 39,494
  • 39
  • 114
  • 146
1
2 3
97 98