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
10
votes
4 answers

Combine Rotation Axis Vectors

I'm experimenting with using axis-angle vectors for rotations in my hobby game engine. This is a 3-component vector along the axis of rotation with a length of the rotation in radians. I like them because: Unlike quats or rotation matrices, I can…
EricP
  • 3,395
  • 3
  • 33
  • 46
10
votes
1 answer

Quaternion to Rotation Matrix, incorrect values using Eigen Library

I am trying to rotate an object by 45 degrees using quaternions about Y-Axis. After Specifying the Quaternion i am trying to get the Rotation Matrix. But the values I see are incorrect Eigen::Quaterniond q; q.x() = 0; q.y() = 1; q.z() = 0; q.w() =…
DollarAkshay
  • 2,063
  • 1
  • 21
  • 39
10
votes
3 answers

C++ / openGL: Rotating a QUAD toward a point using quaternions

When I have a QUAD at a certain position, how can I rotate it in such a way that its normal points toward a given point? Imagine the colored blocks are just rectangular quads, then this image shows a bit what I mean. The quads are all oriented in…
pollux
  • 779
  • 2
  • 14
  • 30
10
votes
6 answers

Euler to Quaternion / Quaternion to Euler using Eigen

I'm trying to implement a functionality that can convert an Euler angle into an Quaternion and back "YXZ"-convention using Eigen. Later this should be used to let the user give you Euler angles and rotate around as Quaternion and convert Back for…
Little-God
  • 183
  • 1
  • 3
  • 16
10
votes
4 answers

Quaternion based camera

I try to implement an FPS camera based on quaternion math. I store a rotation quaternion variable called _quat and multiply it by another quaternion when needed. Here's some code: void Camera::SetOrientation(float rightAngle, float upAngle)//in…
McLovin
  • 3,295
  • 7
  • 32
  • 67
10
votes
2 answers

How to multiply two quaternions with minimal instructions?

After some thought, I came up with the following code for multiplying two quaternions using SSE: #include /* SSE3 intrinsics */ /* multiplication of two quaternions (x, y, z, w) x (a, b, c, d) */ __m128 _mm_cross4_ps(__m128 xyzw,…
Guilherme Amadio
  • 372
  • 2
  • 13
10
votes
5 answers

Converting glm::lookat matrix to quaternion and back

I am using glm to create a camera class, and I am running into some problems with a lookat function. I am using a quaternion to represent rotation, but I want to use glm's prewritten lookat function to avoid duplicating code. This is my lookat…
jbills
  • 694
  • 1
  • 7
  • 22
9
votes
2 answers

How does this Quaternion rotation code work?

I'm trying to understand how the quaternion rotations work, I found this mini tutorial http://www.julapy.com/blog/2008/12/22/quaternion-rotation/ but He makes some assumptions that I can't workout, like how can I do "work out the rotation vectors…
Ricardo Sanchez
  • 4,935
  • 11
  • 56
  • 86
9
votes
4 answers

Correcting the Yaw part of one Quaternion by the Yaw part of another one

I have the following problem: A quaternion (q1) from a motion capturing device needs to be corrected by the yaw angle (and only yaw!) from another orientation quaternion (q2) derived by a second tracked object, so that the pitch and roll of q1 is…
Raboon
  • 91
  • 1
  • 2
9
votes
2 answers

Rotate a 3D object on 3 axis in JavaFX properly

So the method that I've used so far to rotate objects in JavaFX was that I layered it in 3 groups, each of them with a Rotate attached and locked to a single axis like so: Rotate heading, roll, pitch; Group normalrotate, rollrotate,…
Moff Kalast
  • 1,024
  • 1
  • 12
  • 22
9
votes
1 answer

Adding an euler angle to a Quaternion

I want to add an euler angle to an existing quaternion. Here is what i got: Quaternion oldTransform = transform.Rotation; float YawRotation = mouseDiff.x * RotationSpeed; Quaternion YawRotationQuaternion = new…
jsf
  • 913
  • 3
  • 14
  • 22
9
votes
3 answers

Is Yaw, Pitch and Roll respectively the same thing as Heading, Pitch and Bank?

I have two different systems (Engine A, Engine B). Engine A (Motive Tracking Software) generates (Yaw, Pitch, Roll) and Engine B (Cinema 4D) expects (Heading, Pitch, Bank). My research brought me to the result that there is no difference between…
user1767754
  • 23,311
  • 18
  • 141
  • 164
9
votes
3 answers

Can I interpolate rotation from two Quaternions created from Yaw/Pitch/roll?

Quaternions are good for interpolate rotations between them. so far so good. If I have a networking game, will it suffice to transfer the rotation as vector3f or should I use a quaternion? To make the game smoother I may have to interpolate between…
codymanix
  • 28,510
  • 21
  • 92
  • 151
9
votes
1 answer

Quaternion to Euler angles algorithm - How to convert to 'Y = Up' and between handedness?

I have an algorithm for converting between a Quaternion and Euler angles. public static Vector3 ToEulerAngles(this Quaternion q) { // Store the Euler angles in radians Vector3 pitchYawRoll = new Vector3(); double sqw…
user1423893
  • 766
  • 4
  • 15
  • 26
8
votes
1 answer

How to find vector for the quaternion from X Y Z rotations

I am creating a very simple project on OpenGL and I'm stuck with rotations. I am trying to rotate an object indepentdently in all 3 axes: X, Y, and Z. I've had sleepless nights due to the "gimbal lock" problem after rotating about one axis. I've…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389