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
3 answers

Converting angular velocity to quaternion in OpenCV

I need the angular velocity expressed as a quaternion for updating the quaternion every frame with the following expression in OpenCV: q(k)=q(k-1)*qwt; My angular velocity is Mat w; //1x3 I would like to obtain a quaternion form of the angles Mat…
Mar de Romos
  • 719
  • 2
  • 9
  • 22
6
votes
1 answer

Rotating 6 sides of a block

I've been following a XNA tutorial by The Hazy Mind I have a base object that has a Position (Vector3) and a Rotation (Quaternion). The object model looks like this From the camera implementation in the tutorial, i've made a copy of the Rotation…
thmsn
  • 1,976
  • 1
  • 18
  • 25
6
votes
7 answers

Quaternion Comparison?

Is quaternion comparison possible? I'm writing a Java class of Quaternions and I want to implement the Comparable interface to use the Collections.sort(List) facility. I'm not expert at math, I really don't understand the things I read…
anarhikos
  • 1,415
  • 3
  • 15
  • 19
6
votes
1 answer

Compute Altitude and Azimuth from CMAttitude using either Roll, pitch and Yaw or Quaternion or Rotation Matrix

I am struck with a problem. I want to convert the CMAttitude information of an iPhone to Altitude (0 to 90deg) and Azimuth (0 to 360 deg). I have googled around and hit some threads which discuss about it, but none of threads turn out with a…
6
votes
1 answer

Quaternion division and hyperbolic tangent tanh

Quaternion multiplication is well-defined, and is known to me as "Hamilton product": // hamilton product vec4 qmul(in vec4 q1, in vec4 q2) { return vec4( q1.w * q2.xyz + q2.w * q1.xyz - cross(q1.xyz, q2.xyz), q1.w*q2.w -…
xakepp35
  • 2,878
  • 7
  • 26
  • 54
6
votes
3 answers

Longitude / Latitude to quaternion

I've got a longitude and latitude and want to convert this to a quaternion and wondering how I can do this? I want to use this, because I've got an app which projects the earth on a sphere and I want to rotate from one location to another one. Best!
rick
  • 61
  • 1
  • 3
6
votes
1 answer

Cesiumjs calculating pitch, yaw, heading from vector

I have one of Cesium's models loaded into the scene, and I have two points which I want to use in order to calculate the orientation of the model and this is the function I created. // calculate the direction which the model is…
ArmenB
  • 2,125
  • 3
  • 23
  • 47
6
votes
1 answer

glm::quat why the order of x,y,z,w components are mixed

I just started working with quaternions and noticed that the order of glm::quat elements are mixed. This is what I mean by this. If I declare a glm::quat like this glm::quat quat = glm::quat(1, 2, 3, 4); and then print the x,y,z,w like…
Saik
  • 993
  • 1
  • 16
  • 40
6
votes
2 answers

Integrate angular velocity as quaternion rotation

I have (somewhat blindly) been using quaternions for rotations in physics rigid body simulation for a while, but recently started getting confused about how quaternion rotations are generally defined and how I do it (based on the book Physics for…
JoeTaicoon
  • 1,383
  • 1
  • 12
  • 28
6
votes
1 answer

Quaternion cube rotation animation

I created this Rubiks Cube with Papervison3D. With some resources I created a Cube with 27 minicubes inside (3*3*3 = 27). Rotating the Rubiks Cube on mouse move is already done. (I do not rotate the camera.) All the behavior of a Rubiks Cube is in…
Jos Koomen
  • 372
  • 1
  • 3
  • 15
6
votes
1 answer

Convert a Unit Vector to a Quaternion

So I'm very new to quaternions, but I understand the basics of how to manipulate stuff with them. What I'm currently trying to do is compare a known quaternion to two absolute points in space. I'm hoping what I can do is simply convert the points…
Hmm
  • 71
  • 1
  • 2
6
votes
2 answers

Overhead of using classes for matrix of algebraic structures in C++

I am using C++ to code some complicated FFT algorithm, so I need to implement such algebraic structures as quaternions and Hamilton-Eisenstein codes. Algorithm works with 2D array of that structures. What would be the overhead of implementing them…
user517893
  • 471
  • 4
  • 14
6
votes
3 answers

Quaternion is flipping sign for very similar rotations?

Consider the following minimal working example: #include #include #include int main() { // Set the rotation matrices that give an example of the problem Eigen::Matrix3d rotation_matrix_1,…
space_voyager
  • 1,984
  • 3
  • 20
  • 31
6
votes
0 answers

How to avoid roll in SceneKit camera controlled by Core Motion?

I'm setting my SceneKit camera to the current CMDeviceMotion attitude using the CMDeviceMotion extension described in this answer: func deviceDidMove(motion: CMDeviceMotion?, error: NSError?) { if let motion = motion { let orientation =…
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
6
votes
2 answers

Flipping issue when interpolating Rotations using Quaternions

I use slerp to interpolate between two quaternions representing rotations. The resulting rotation is then extracted as Euler angles to be fed into a graphics lib. This kind of works, but I have the following problem; when rotating around two (one…
uhuu
  • 181
  • 1
  • 2
  • 4