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
19
votes
2 answers

Using Quaternions for OpenGL Rotations

So I'm writing a program where objects move around spacesim-style, in order to learn how to move things smoothly through 3D space. After messing around with Euler angles a bit, it seems they aren't really appropriate for free-form 3D movement in…
GarrickW
  • 2,181
  • 5
  • 31
  • 38
19
votes
3 answers

Three.js Object3d cylinder rotation to align to a vector

I have searched far and wide, but can't seem to figure this pretty basic thing out. I have seen other examples on stackoverflow and elsewhere from a year or two ago, but they fail to work with the latest version of Three.js. Here is a version of…
coder99
  • 191
  • 1
  • 1
  • 4
19
votes
3 answers

Convert Quaternion representing rotation from one coordinate system to another

I am getting a quaternion from sensor data that is in the coordinate system Y=up, X=right, and Z= backwards.Mine is X=forward, Y=right, Z=up. So OX=Y, OY=Z and OZ=-X. I have a function that can convert quaternions into 4by4 matrices, but no idea…
Craig Delancy
  • 191
  • 1
  • 1
  • 3
18
votes
2 answers

SceneKit – Mapping physical 360 rotation

I am having a hard time mapping device motion (sensor fusion) to SceneKit node rotation. The premise of the problem is as follows, I have sphere, and the camera is positioned to be inside the the sphere such that the geometric center of sphere and…
egghese
  • 2,193
  • 16
  • 26
18
votes
1 answer

Eigen: convert Matrix3d rotation to Quaternion

I'm trying to convert a Matrix3d rotation to a Quaternion, but I got only weird compiler errors so far. The code I'm using is: Quaternion getQuaternionFromRotationMatrix(const Matrix3d& mat) { AngleAxisd aa; aa = mat; …
Esparver
  • 1,515
  • 1
  • 15
  • 28
17
votes
2 answers

rotating a quaternion on 1 axis?

I have a model rotated by a quaternion. I can only set the rotation, I can't add or subtract from anything. I need to get the value of an axis, and than add an angle to it (maybe a degree or radian?) and than re-add the modified quaternion. How can…
William
  • 8,630
  • 23
  • 77
  • 110
17
votes
3 answers

Should Quaternion based 3D Cameras accumulate Quaternions or Euler angles?

So I have written a Quaternion based 3D Camera oriented toward new programmers so it is ultra easy for them to integrate and begin using. While I was developing it, at first I would take user input as Euler angles, then generate a Quaternion based…
Adam
  • 25,966
  • 23
  • 76
  • 87
14
votes
1 answer

3ds max to C++/DirectX application orientation conversion

I want to export object from 3ds max to my C++/DirectX application and I have an problem with orientation exporting. 3ds max uses right-handed Z-up coordinate system and my application makes use of left-handed Y-up coordinate system. I use {x, y, z,…
PolGraphic
  • 3,233
  • 11
  • 51
  • 108
14
votes
1 answer

Normals rotates wrong way when object is rotated

I am rendering a simple torus in WebGL. Rotating the vertices works fine but I have a problem with the normals. When rotated around a single axis, they keep the correct direction but when the rotation around a second axis increases, the normals…
Jave
  • 31,598
  • 14
  • 77
  • 90
14
votes
3 answers

Quaternions -> Euler Angles -> Rotation Matrix trouble (GLM)

I'm writing a program that loads a file containing a scene description and then displays it using OpenGL. I'm using GLM for all of my math operations. Rotations in the scene file are stored in quaternion format. My scene management systems takes…
iondune
  • 283
  • 1
  • 2
  • 7
14
votes
4 answers

Euler angle to Quaternion then Quaternion to euler angle

I'm using lib glm (http://glm.g-truc.net/) for test quaternion but I've a problem; when I convert euler angle to quaternion then immediatly quaternion to euler angles, my result are totally different from my initial euler angles. Is this normal?…
user1466739
  • 143
  • 1
  • 1
  • 4
13
votes
4 answers

Look-at quaternion using up vector

I have a camera (in a custom 3D engine) that accepts a quaternion for the rotation transform. I have two 3D points representing a camera and an object to look at. I want to calculate the quaternion that looks from the camera to the object, while…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
13
votes
2 answers

Quaternion reaching gimbal lock

In attempt to avoid angle lock when performing rotations I've tried to switch over to Quaternions. Somehow, I'm still managing to reach gimbal lock. I'm not sure if its due to the math I've implemented, or a design error, so please point out if I…
Yattabyte
  • 1,280
  • 14
  • 28
13
votes
3 answers

Quaternion "lookAt" function

Im struggling with the following problem. Im working with bone animation and I want (ie) the head of the player to follow an another object in space. My up axis is +Z my forward axis is +Y, and the magnitude of the quaternion is in W. I tried to use…
McBob
  • 1,011
  • 2
  • 13
  • 25
12
votes
2 answers

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…
Sindre
  • 337
  • 2
  • 3
  • 8
1
2
3
97 98