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
7
votes
1 answer

How to use quaternion rotation in Three.js json scene

I am working on L-system interpreter and I use quaternion as internal representation of rotation. I need to export result to ThreeJs JavaScript scene and I found json scene as the best way how to do that. I found one example of scene on…
NightElfik
  • 4,328
  • 5
  • 27
  • 34
7
votes
3 answers

Global Rotation

in GLScene we have three parameters (RollAngle, PitchAngle and TurnAngle) for rotation around local orientation. in the image below, how can I rotate cube around global orientation (orange axis)?
Ata
  • 273
  • 1
  • 7
  • 13
7
votes
3 answers

Interpolate between two quaternions the long way

We can do a slerp interpolation between two quaternions like this: quat slerp(quat q1, quat q2, float t) { float angle = acos(dotProduct(q1, q2)); float denom = sin(angle); //check if denom is zero return…
Lenny White
  • 406
  • 4
  • 8
7
votes
1 answer

How do I rotate a Quaternion with 2nd Quaternion on its local or world axes without using transform.Rotate?

Transform.Rotate has a very helpful interface for selecting whether or not a rotation should be made relative to world axes or the local axes. Behind the scenes, it's doing some math to the transform's rotation, a Quaternion, with another…
Ruzihm
  • 19,749
  • 5
  • 36
  • 48
7
votes
1 answer

ENU -> NED frame conversion using quaternions

What I am looking for: A uniform way to rotate a vector (X, Y, Z) from ENU to NED and vice versa The same uniform way to rotate a quaternion from ENU to NED and vice versa It would be appreciated if there can be given a solution in python, but it is…
Tom Vos
  • 410
  • 1
  • 5
  • 13
7
votes
4 answers

opengl matrix rotation quaternions

Im trying to do a simple rotation of a cube about the x and y axis: I want to always rotate the cube over the x axis by an amount x and rotate the cube over the yaxis by an amount y independent of the x axis rotation first i naively did…
yeahdixon
  • 6,647
  • 1
  • 41
  • 43
7
votes
3 answers

Why is my straightforward quaternion multiplication faster than SSE?

I've been going through a few different quaternion multiplication implementations, but I've been rather surprised to see that the reference implementation is, so far, my fastest. This is the implementation in question: inline static quat…
Haydn V. Harach
  • 1,265
  • 1
  • 18
  • 36
7
votes
3 answers

How to find correct rotation from one vector to another?

I have two objects, and each object has two vectors: normal vector up vector Like on this image: Up vector is perpendicular to normal vector. Now I want to find unique rotation from one object to another, how to do that? I have one method to find…
Tom
  • 1,027
  • 2
  • 16
  • 35
7
votes
3 answers

How to multiply two quaternions

I have two quaternions, as example: w x y z 1: 0.98 0.08 0.17 -0.01 2: 0.70 0.70 0.0 0.0 I need to multiply them, to get third one, with all rotations in it, but have no ideas. It would be perfect, if there is a function in…
therainycat
  • 324
  • 1
  • 2
  • 14
7
votes
2 answers

Gravity Compensation in Accelerometer Data

Given an Accelerometer with 9 DOF (Accelerometer, Gyroscope and Magnetometer) I want to remove/compensate the effect of the gravity in accelerometer reading (Accelerometer can rotate freely). The sensor gives the orientation in quaternion…
dragsu
  • 111
  • 1
  • 1
  • 10
7
votes
6 answers

Calculating quaternion for transformation between 2 3D cartesian coordinate systems

I have two cartesian coordinate systems with known unit vectors: System A(x_A,y_A,z_A) and System B(x_B,y_B,z_B) Both systems share the same origin (0,0,0). I'm trying to calculate a quaternion, so that vectors in system B can be expressed in system…
Mo3bius
  • 642
  • 1
  • 8
  • 18
7
votes
3 answers

Quaternion from Orthogonal Basis

I have a projectile object that is moving along a velocity vector. I need to ensure that the object is always facing in the direction of the velocity vector. Furthermore, I am representing object rotation using quaternions, not matrices. I know…
Matt Fichman
  • 5,458
  • 4
  • 39
  • 59
7
votes
1 answer

How to rotate a CannonJS RigidBody?

Does anyone know how I can rotate a CannonJS (the physics library) CANNON.RigidBody? I'm trying to make the object rotate with the camera, so both are facing the same direction. I know I have to modify the quaternion, but this doesn't work…
Joey Morani
  • 25,431
  • 32
  • 84
  • 131
7
votes
3 answers

How to rotate a GLM quaternion correctly?

I want to rotate my car by 90 degrees to the left in the game I have. When I use this code: glm::quat rot(info.Rotation.w,info.Rotation.x,info.Rotation.y,info.Rotation.z); glm::quat…
user1182183
7
votes
2 answers

Create a full 3d skeleton with Kinect SDK

This is for my first graphics subject at uni, and some parts of the implementation just aren't working for me. I can get the joints to draw properly, but I'm trying to write a function that puts in 'bones' between the joints. At this point the bones…
Vince Noir
  • 171
  • 1
  • 7