quaternions

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

孤人 提交于 2019-12-04 07:29:24
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 = motion.gaze(atOrientation: UIApplication.sharedApplication().statusBarOrientation) cameraNode.orientation = orientation } } This works beautifully, however, I'd like to block the rotation (roll) and only allow the camera to turn around (yaw) and pitch. I tried to convert the quaternion back to Euler angles and simply leave roll at 0: cameraNode.eulerAngles =

How do you rotate 2 quaternions back to starting position and then calculate the relative rotation?

拜拜、爱过 提交于 2019-12-04 07:06:18
I have 2 IMU's (Inertial measurement units) and I want to calculate their relative rotation. Unfortunately, the output of the IMU's gives me both quaternions relative to global (I'm assuming that's how quaternions work). However, I need measurements of the rotation of one of the sensors relative to the other. All the while, these two sensors have been rotated from their initial orientation in the global axis. For example: I have one sensor attached to the chest and the other attached the arm. Both sensors are calibrated to the global axis. If I maintain that orientation, I can calculate the

Quaternion math for rotation?

安稳与你 提交于 2019-12-04 04:45:09
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 rotation? I remember this can be calculated using Quaternions but I can't seem to remember the math. The solution should be pretty straightforward, and shouldn't require quarternions. The axis of rotation to get from Normal1 to Normal2 must be orthogonal to both, so just take their vector cross-product . The amount of rotation is easily derived

Rotate a quaternion by Euler angles input

扶醉桌前 提交于 2019-12-04 01:42:45
问题 I am writing a code to control robotic arm in 3D space. The robotic arm handle the rotation by quaternion but I want user to control it by changing yaw, pitch and roll since its more sensible for human to use these. I wrote function to get the amount that user wants to rotate the arm in each of directions(roll, pitch, yaw) and output the new quaternion. I saved the current_quaternion as a global variable. I am using C++ and Eigen. Eigen::Quaterniond euler2Quaternion( const double roll, const

Euler angles vs. Quaternions - problems caused by the tension between internal storage and presentation to the user?

穿精又带淫゛_ 提交于 2019-12-04 00:11:20
问题 Quaternions are arguably an appropriate choice for representing object rotations internally. They are simple and efficient to interpolate and represent a single orientation unambiguously. However, presenting quaternions in the user interface is generally inappropriate - Euler angles are generally much more familiar to users, and their values are a little more intuitive and predictable. Euler angles suffer from being complicated at the code level - they require that an order of rotation is

Quaternion is flipping sign for very similar rotations?

时光毁灭记忆、已成空白 提交于 2019-12-03 22:16:08
Consider the following minimal working example: #include <iostream> #include <math.h> #include <eigen3/Eigen/Dense> int main() { // Set the rotation matrices that give an example of the problem Eigen::Matrix3d rotation_matrix_1, rotation_matrix_2; rotation_matrix_1 << 0.15240781108708346, -0.98618841818279246, -0.064840288106743013, -0.98826031445019891, -0.1527775600229907, 0.00075368177315370682, -0.0106494132438156, 0.063964216524108775, -0.99789536976680049; rotation_matrix_2 << -0.12448670851248633, -0.98805453458380521, -0.090836645094957508, -0.99167686914182451, 0.12086367053038971, 0

Can someone explain how I can use Quanternions to use the mouse to look around like a FPS?

故事扮演 提交于 2019-12-03 17:19:11
Yesterday I asked: How could simply calling Pitch and Yaw cause the camera to roll? Basically, I found out because of "Gimbal Lock" that if you pitch + yaw you will inevitably produce a rolling effect. For more information you can read that question. I'm trying to stop this from happening. When you look around in a normal FPS shooter you don't have your camera rolling all over the place! Here is my current passive mouse func: int windowWidth = 640; int windowHeight = 480; int oldMouseX = -1; int oldMouseY = -1; void mousePassiveHandler(int x, int y) { int snapThreshold = 50; if (oldMouseX !=

Can i switch X Y Z in a quaternion?

百般思念 提交于 2019-12-03 17:17:52
问题 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? 回答1: 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

Faster quaternion vector multiplication doesn't work

岁酱吖の 提交于 2019-12-03 17:17:17
I need a faster quaternion-vector multiplication routine for my math library. Right now I'm using the canonical v' = qv(q^-1) , which produces the same result as multiplying the vector by a matrix made from the quaternion, so I'm confident in it's correctness. So far I've implemented 3 alternative "faster" methods: #1, I have no idea where I got this one from: v' = (q.xyz * 2 * dot(q.xyz, v)) + (v * (q.w*q.w - dot(q.xyz, q.zyx))) + (cross(q.xyz, v) * q.w * w) Implemented as: vec3 rotateVector(const quat& q, const vec3& v) { vec3 u(q.x, q.y, q.z); float s = q.w; return vec3(u * 2.0f * vec3::dot

Converting a direction vector to a quaternion rotation

邮差的信 提交于 2019-12-03 12:13:34
I can find a ton of questions about turning a quaternion into a direction vector but none for the other way around which makes me think I'm doing something wrong, but bear with me. What I'm trying to do is simply display the direction of a directional light using an arrow model. The directional light's direction is a unit vector but models are rotated using quaternions. So.. How do I rotate this model to match the direction of the light? Or am I crazy and I can't really do that, given that the light has no position but the model does? A direction vector is not a defined rotation, it still has