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

Direction vector from Quaternion?

I have a Quaternion representing the rotation of a 3D characters upper arm. I also have a line that is supposed to represent the new position of that characters' arm. That lines position is given by two 3D points. This is the only data I have, and…
Nicros
  • 5,031
  • 12
  • 57
  • 101
8
votes
3 answers

Quaternion math for rotation?

I'm drawing a flat disk using gluDisk() in my scene. gluDisk() draws the disk facing the positive Z axis but I want it to be facing some arbitrary normal I have. Clearly I need to use glRotate() to get the disk facing properly but what should be the…
shoosh
  • 76,898
  • 55
  • 205
  • 325
8
votes
4 answers

Nearest Neighbours using Quaternions

Given a quaternion value, I would like to find its nearest neighbour in a set of quaternions. To do this, I clearly need a way to compare the "distance" between two quaternions. What distance representation is needed for such a comparison and how is…
Josh
  • 1,357
  • 2
  • 23
  • 45
8
votes
2 answers

Quaternion (0,0,0,0) signifies what

After performing quaternion multiplication I am getting (0,0,0,0). Could anyone let me know what it signifies. (1 0 0 0) - Identity quaternion, no rotation, (0 1 0 0) - 180° turn around X axis, (0 0 1 0) - 180° turn around Y axis, (0 0 0 1) - 180°…
8
votes
4 answers

How to generate a random quaternion quickly?

I searched around and it turns out the answer to this is surprising hard to find. Theres algorithm out there that can generate a random orientation in quaternion form but they involve sqrt and trig functions. I dont really need a uniformly…
user17739521
  • 185
  • 1
  • 6
8
votes
2 answers

Average and Measure of Spread of 3D Rotations

I've seen several similar questions, and have some ideas of what I might try, but I don't remember seeing anything about spread. So: I am working on a measurement system, ultimately computer vision based. I take N captures, and process them using…
8
votes
6 answers

How can I read/transform the range images of the stanford bunny .ply-files?

I want to read the not reconstructed data from the Stanford Bunny. The point data is stored as several range images, which have to be transformed to be combined to one big point cloud, like written in the README: These data files were obtained with…
DanceIgel
  • 714
  • 8
  • 25
8
votes
1 answer

How to get the euler-angles from the rotation vector (Sensor.TYPE_ROTATION_VECTOR)

I rotated my android device in x direction (from -180 degree to 180 degree), see image below. And I assume only Rotation vector x value is changed. Y and z maybe have some noise, but it should be not much difference among the values. However, I…
Charles Brown
  • 917
  • 2
  • 10
  • 20
8
votes
2 answers

"Distance" (or angular magnitude) between two quaternions?

I want to find the "distance" between two quaternions. By "distance" I mean a single float or int, not another quaternion (that would be the difference, i.e. inverse(q1)*q2). I guess you could call what I want "angular magnitude". I need to apply…
Clonkex
  • 3,373
  • 7
  • 38
  • 55
8
votes
1 answer

Using quaternions for tangent space normal mapping - Problems I'm having

Inspired by crytek's presentation on using quaternions to store tangent space in quaternions for smaller vertices, I came to the logical conclusion that if you can use quaternions to store tangent space, then you could also lerp quaternions between…
Haydn V. Harach
  • 1,265
  • 1
  • 18
  • 36
8
votes
2 answers

Using quaternion instead of roll, pitch and yaw to track device motion

Please bear with my long question, I am trying to make it as clear as possible. What i am trying to do is, get the attitude(roll pitch and yaw) when a picture is taken using camera and then save the attitude values to nsuserdefaults. After saving,…
iSeeker
  • 776
  • 1
  • 8
  • 24
8
votes
3 answers

Convert Unity transforms to THREE.js rotations

How can I match the rotation of a THREE.js camera or object to a transform from a Unity GameObject? Unity uses a left-handed system with a ZXY euler order. THREE.js uses a right-handed system with an XYZ euler order. What transformations need to be…
Simon Cave
  • 3,971
  • 4
  • 24
  • 28
8
votes
2 answers

SSE with doubles, not worth it?

I read a bit about using SSE intrinsics and tried my luck with implementing quaternion rotation with doubles. Below are the normal and SSE functions I wrote, void quat_rot(quat_t a, REAL* restrict b){ …
Grieverheart
  • 510
  • 5
  • 16
8
votes
2 answers

How to derive "standard" rotations from three.js when using quaternions?

Newbie stackoverflow participant, newbie 3D programmer, and far from a math wiz... so I'll try to frame this question as clearly as I can, hoping it makes sense, and hoping for an answer that's not a mile over my head. I've written a very cool app…
J Sprague
  • 1,008
  • 11
  • 15
8
votes
4 answers

View Matrix from Quaternion

I'm currently building my own quaternion camera. As far as I know, you only need one quaternion to fully specify the camera's orientation (correct me if I'm wrong). So, how would I go about creating the view matrix? I'm using C++ as a programming…
l3utterfly
  • 2,106
  • 4
  • 32
  • 58