quaternions

Nearest Neighbours using Quaternions

血红的双手。 提交于 2019-12-03 09:55:31
问题 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 it computed? Thanks, Josh 回答1: Is your quaternion just a point in 3D space with an orientation? Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by: distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2) , assuming that

Quaternion to Euler angles algorithm - How to convert to 'Y = Up' and between handedness?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:38:09
问题 I have an algorithm for converting between a Quaternion and Euler angles. public static Vector3 ToEulerAngles(this Quaternion q) { // Store the Euler angles in radians Vector3 pitchYawRoll = new Vector3(); double sqw = q.W * q.W; double sqx = q.X * q.X; double sqy = q.Y * q.Y; double sqz = q.Z * q.Z; // If quaternion is normalised the unit is one, otherwise it is the correction factor double unit = sqx + sqy + sqz + sqw; double test = q.X * q.Y + q.Z * q.W; if (test > 0.4999f * unit) // 0

“Distance” (or angular magnitude) between two quaternions?

社会主义新天地 提交于 2019-12-03 09:31:36
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 more torque to a physics object the further it's rotated from its original angle. I don't understand the maths involved in quaternions, so a code-based example would be most helpful. I've looked at several other questions but I don't believe any answer my question, or at least not in a way I understand it. Find the difference quaternion qd = inverse

When I have two orientation quaternions, how do I find the rotation quaternion needed to go from one to the other?

隐身守侯 提交于 2019-12-03 07:10:33
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 missing from my vocabulary. In equations, what I'm doing when I rotate from the first one to the other is as follows: q2 = r * q1 However, now r is the unknown. Do the rules of algebra count here too? If that's the case, I'd end up dividing a quaternion by another, something I can't find a good explanation for on the internet. I'm using a program called

Can i switch X Y Z in a quaternion?

一曲冷凌霜 提交于 2019-12-03 06:37:55
i have a coordinate system where the Y axis is UP. I need to convert it to a coordinate system where Z is UP. I have the rotations stored in quaternions, so my question is : if i have a quaternion X,Y,Z can i switch the Y with the Z and get the result that Z is actually UP? Just swpping two axes in a quaternions? No this doesn't work because this flips the chirality. However if you flip the chirality and negate the quaternion's real part then you're back in the original chirality. In general form you can write this as Q'(Q, i'j'k') = ε i'j'k' Q w _w + Q i _i + Q j _j + Q k _k where is the

When do I need to use quaternions?

拟墨画扇 提交于 2019-12-03 05:47:01
问题 I have been carrying out 2D and 3D operations, including graphics, for many years and have never used quaternions so I don't have a feel for them. I know that they can be used for certain operations that are difficult in Euler angles and also that they can be used to find the rotation required to best fit one set of coordinates (X1, X2...XN, X=(xyz)) onto another (X1', X2'... XN'). Are there places where quaternions are essential? And are there places where they make solutions more elegant or

Euler to Quaternion / Quaternion to Euler using Eigen

六眼飞鱼酱① 提交于 2019-12-03 03:39:35
I'm trying to implement a functionality that can convert an Euler angle into an Quaternion and back "YXZ"-convention using Eigen. Later this should be used to let the user give you Euler angles and rotate around as Quaternion and convert Back for the user. In fact i am realy bad at math but tried my best. I have no Idea if this matrices are correct or anything. The code Works, but my results are way to off, i suppose. Any idea where i take the wrong turn? This is what my Quat.cpp looks like: #include "Quat.h" #include <Eigen/Geometry> #include <Eigen/Dense> #include <cmath> #include <iostream>

Extracting Yaw from a Quaternion

醉酒当歌 提交于 2019-12-03 01:43:17
问题 I have a rotation quaternion and want to extract the angle of rotation about the Up axis (the yaw). I am using XNA and as far as I can tell there is no inbuilt function for this. What is the best way to do this? Thanks for any help, Venatu 回答1: The quaternion representation of rotation is a variation on axis and angle. So if you rotate by r radians around axis x , y , z , then your quaternion q is: q[0] = cos(r/2); q[1] = sin(r/2)*x; q[2] = sin(r/2)*y; q[3] = sin(r/2)*z; If you want to create

rotating a quaternion on 1 axis?

一个人想着一个人 提交于 2019-12-03 00:40:59
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 I do this? (answer on each axis). You can multiply two quaternions together to produce a third quaternion that is the result of the two rotations. Note that quaternion multiplication is not commutative, meaning order matters (if you do this in your head a few times, you can see why). You can produce a quaternion that represents a rotation by a given

Nearest Neighbours using Quaternions

爱⌒轻易说出口 提交于 2019-12-03 00:27:10
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 it computed? Thanks, Josh Olhovsky Is your quaternion just a point in 3D space with an orientation? Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by: distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2) , assuming that the w component is used for orientation. I.e. this is the same as the distance between two 3D points