quaternions

Madgwick sensor fusion on LSM9DS0

孤人 提交于 2019-12-01 08:57:33
I'm trying to implement Madgwick sensor fusion algorithm from here on LSM9DS0 sensor (accelerometer, gyroscope and magnetometer) on STM Cortex M3 microcontroller. Raw data from all sensors seems to be fine. My problem is: when I hold sensor with it's z-axis horizontal or downwards (i.e. roll or pitch angle is more than 90 degrees) - quaternion from filter becomes really unstable and randomly flips 180 degrees. More correctly, q0 and q3 are constantly changing signs, resulting in 180 degree flip of rotation. I tried using constant values instead of real sensor output and still got this behavior

Madgwick sensor fusion on LSM9DS0

人盡茶涼 提交于 2019-12-01 05:38:57
问题 I'm trying to implement Madgwick sensor fusion algorithm from here on LSM9DS0 sensor (accelerometer, gyroscope and magnetometer) on STM Cortex M3 microcontroller. Raw data from all sensors seems to be fine. My problem is: when I hold sensor with it's z-axis horizontal or downwards (i.e. roll or pitch angle is more than 90 degrees) - quaternion from filter becomes really unstable and randomly flips 180 degrees. More correctly, q0 and q3 are constantly changing signs, resulting in 180 degree

Look-at quaternion using up vector

放肆的年华 提交于 2019-11-30 14:19:29
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 respecting the world up axis . This question asks for the same thing without the "up" vector. All three answers result in the camera pointing in the correct direction, but rolling (as in yaw/pitch/roll; imagine leaning your head onto your ear while looking at something). I can calculate an orthonormal basis of vectors that match the desired coordinate

Is there an algorithm for converting quaternion rotations to Euler angle rotations?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 10:12:44
问题 Is there an existing algorithm for converting a quaternion representation of a rotation to an Euler angle representation? The rotation order for the Euler representation is known and can be any of the six permutations (i.e. xyz, xzy, yxz, yzx, zxy, zyx). I've seen algorithms for a fixed rotation order (usually the NASA heading, bank, roll convention) but not for arbitrary rotation order. Furthermore, because there are multiple Euler angle representations of a single orientation, this result

Quaternion “lookAt” function

别来无恙 提交于 2019-11-30 09:45:31
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 the mesa code for gluLookAt and use the 3x3 matrix to transform to a quaternion but it doesn't work as expected so I go in another direction... So far I got the following code that is "almost" working at least the head of the player is rotating (however the X angle seems to affect the Y rotation axis) in the good direction but its looking straight

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

為{幸葍}努か 提交于 2019-11-30 09:45:10
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 using three.js that lets the user fly through 3D space and explore a solar system. The flight model is loosely based on the Fly.Controller example/extension in the three.js package which taught me to use quaternions for keeping all the axis rotations sensible relative to each other. The flying part all works great. Here's my dilemma: When using

How to animate the camera in three.js to look at an object?

允我心安 提交于 2019-11-30 07:45:17
In Three.js, I would like to have the camera looking at an object in the scene, and when I click on another object, to have the camera rotate smoothly to look at the new object. (i.e animate the rotation of the camera). I´ve checked in SO and this is the most similar question : Three.js How to use quaternion to rotate camera I've also tried modifying the code in this website and I manage to get something like this http://jsfiddle.net/F7Bh3/ var quat0 = mesh2.quaternion; var eye = mesh2.position; var center = mesh.position; var mat = new THREE.Matrix4(); mat.lookAt(center, eye, new THREE

Efficient C++ quaternion multiplication using cv::Mat

无人久伴 提交于 2019-11-30 07:00:47
I want to multiply 2 quaternions, which are stored in a cv::Mat structure. I want the function to be as efficient as possible. I have the following code so far: /** Quaternion multiplication * */ void multiplyQuaternion(const Mat& q1,const Mat& q2, Mat& q) { // First quaternion q1 (x1 y1 z1 r1) const float x1=q1.at<float>(0); const float y1=q1.at<float>(1); const float z1=q1.at<float>(2); const float r1=q1.at<float>(3); // Second quaternion q2 (x2 y2 z2 r2) const float x2=q2.at<float>(0); const float y2=q2.at<float>(1); const float z2=q2.at<float>(2); const float r2=q2.at<float>(3); q.at<float

How to multiply two quaternions with minimal instructions?

天涯浪子 提交于 2019-11-30 05:13:44
After some thought, I came up with the following code for multiplying two quaternions using SSE: #include <pmmintrin.h> /* SSE3 intrinsics */ /* multiplication of two quaternions (x, y, z, w) x (a, b, c, d) */ __m128 _mm_cross4_ps(__m128 xyzw, __m128 abcd) { /* The product of two quaternions is: */ /* (X,Y,Z,W) = (xd+yc-zb+wa, -xc+yd+za+wb, xb-ya+zd+wc, -xa-yb-zc+wd) */ __m128 wzyx = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(0,1,2,3)); __m128 baba = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(0,1,0,1)); __m128 dcdc = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(2,3,2,3)); /* variable names below are for

quaternion libraries in C/C++ [closed]

爱⌒轻易说出口 提交于 2019-11-30 04:37:48
Any good libraries for quaternion calculations in C/C++ ? Side note: any good tutorials/examples? I've google it and been to the first few pages but maybe you have have some demos/labs from compsci or math courses you could/would share? Thanks I'm a fan of the Irrlicht quaternion class. It is zlib licensed and is fairly easy to extract from Irrlicht: Irrlicht Quaternion Documentation quaternion.h You could try with Boost - usually good place to start with. They have a dedicated sublibrary for that. As for the examples look at the documentation and the unit tests that come along with Boost.