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
12
votes
7 answers

Euler angles vs. Quaternions - problems caused by the tension between internal storage and presentation to the user?

Quaternions are arguably an appropriate choice for representing object rotations internally. They are simple and efficient to interpolate and represent a single orientation unambiguously. However, presenting quaternions in the user interface is…
Will Baker
  • 2,747
  • 4
  • 20
  • 17
12
votes
4 answers

Limit camera pitch

How can I efficiently limit camera pitch when I have only camera quaternion? Do I have to convert to euler angles and then back to quaternion or is there any other way?
Wert
  • 121
  • 3
12
votes
4 answers

How to interpolate rotations?

I have two vectors describing rotations; a start rotation A and a target rotation B. How would I best go about interpolating A by a factor F to approach B? Using a simple lerp on the vectors fails to work when more than one dimension needs to be…
uhuu
  • 181
  • 1
  • 2
  • 4
12
votes
5 answers

Quaternions and numerical stability

I'm learning about unit quaternions and how to use them to represent and compose rotations. Wikipedia says they are more numerically stable than matrix representations, but doesn't give a reference. Can anyone explain to me (preferably with some…
rmp251
  • 5,018
  • 4
  • 34
  • 46
12
votes
4 answers

dot product of two quaternion rotations

I understand that the dot (or inner) product of two quaternions is the angle between the rotations (including the axis-rotation). This makes the dot product equal to the angle between two points on the quaternion hypersphere. I can not, however,…
Kent
  • 713
  • 2
  • 8
  • 19
12
votes
4 answers

Can i switch X Y Z in a quaternion?

i have a coordinate system where the Y axis is UP. I need to convert it to a coordinate system where Z is UP. I have the rotations stored in quaternions, so my question is : if i have a quaternion X,Y,Z can i switch the Y with the Z and get the…
Captain GouLash
  • 1,257
  • 3
  • 20
  • 33
11
votes
2 answers

From quaternions to OpenGL rotations

I have an object which I want to rotate via keys. The object should yaw, pitch and roll. After trying a lot, I figured out that glRotate has its limitations and it won't be possible to implement something like that with that function. I've…
buddy
  • 821
  • 2
  • 12
  • 30
11
votes
6 answers

Efficient way to apply mirror effect on quaternion rotation?

Quaternions represent rotations - they don't include information about scaling or mirroring. However it is still possible to mirror the effect of a rotation. Consider a mirroring on the x-y-plane (we can also call it a mirroring along the z-axis). A…
runevision
  • 339
  • 1
  • 2
  • 10
11
votes
5 answers

How to update quaternion based on 3d gyro data?

I've got an initial quaternion , q0. And I get angular velocity measurments, I integrate the the velocities so I got 3 angles at 50Hz or so. How can make a quaternion based on the 3 angles? I can't just make 3 quaternions, can I? So to make it…
user3598726
  • 951
  • 2
  • 11
  • 27
11
votes
1 answer

Attitude change - angles and axis issue - quaternion math

I have an app that records angles as user is walking around an object, while pointing device (preferably) at the center of the object. Angle gets reset on user's command - so reference attitude gets reset. Using Euler angles produces Gimbal lock, so…
Andrei G.
  • 1,710
  • 1
  • 14
  • 23
11
votes
2 answers

"Looking At" an object with a Quaternion

So I am currently trying to create a function that will take two 3D points A and B, and provide me with the quaternion representing the rotation required of point A to be "looking at" point B (such that point A's local Z axis passes through point B,…
GarrickW
  • 2,181
  • 5
  • 31
  • 38
11
votes
2 answers

Combining quaternions with different pivot point

Background: I am currently implementing a skeletal animation shader in GLSL, and to save space and complexity I am using Quaternions for the bone rotations, using weighted quaternion multiplication (of each bone) to accumulate a "final rotation" for…
StrangeQuark
  • 143
  • 8
11
votes
3 answers

Efficient C++ quaternion multiplication using cv::Mat

I want to multiply 2 quaternions, which are stored in a cv::Mat structure. I want the function to be as efficient as possible. I have the following code so far: /** Quaternion multiplication * */ void multiplyQuaternion(const Mat& q1,const Mat&…
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
10
votes
2 answers

Quaternions vs Axis + angle

I have been trying to find the difference between the 2 but to no luck minus this The primary diff erence between the two representations is that a quaternion’s axis of rotation is scaled by the sine of the half angle of rotation, and instead…
Chris Condy
  • 626
  • 2
  • 9
  • 25
10
votes
2 answers

Calculate Quaternion Inverse

Hi i'm trying to figure out how to calculate the inverse of a quaternion. A code example would be awesome. Cheers
user346443
  • 4,672
  • 15
  • 57
  • 80
1 2
3
97 98