0

I have a 3D scene in which in the imaginary sphere I position few objects, now I want to rotate them within device motion.

I use spherical coordinate system and calculate position in sphere like below:

x   = ρ * sin⁡ϕ * cos⁡θ
y   = ρ * sin⁡ϕ * sin⁡θ
z   = ρ * cos⁡ϕ. 

Also, I use angles (from 0 to 2_M_PI) for performing rotation horizontally (in z-x)

enter image description here

As result all works perfect until I want to use Quaternion from motion matrix.

I can extract values like pitch, yaw, roll

    GLKQuaternion quat = GLKQuaternionMakeWithMatrix4(motionMatrix);
    CGFloat adjRoll = atan2(2 * (quat.y * quat.w - quat.x * quat.z), 1 - 2 * quat.y * quat.y - 2 * quat.z * quat.z);
    CGFloat adjPitch = atan2(2 * (quat.x * quat.w + quat.y * quat.z), 1 - 2 * quat.x * quat.x - 2 * quat.z * quat.z);
    CGFloat adjYaw = asin(2 * quat.x * quat.y + 2 * quat.w * quat.z);

or try also

    CMAttitude *currentAttitude = [MotionDataProvider sharedProvider].attitude; //from CoreMotion
    CGFloat roll = currentAttitude.roll; 
    CGFloat pitch = currentAttitude.pitch;
    CGFloat yaw = currentAttitude.yaw; 

*the values that i got is different for this methods

The problem is that pitch, yaw, roll is not applicable in this format to my scheme.

How can I convert pitch, yaw, roll or quaternion or motionMatrix to required angles in x-z for my rotation model? Am I on correct way of things doing, or I missed some milestone point?

How to get rotation around y axis from received rotation matrix/quaternion from CoreMotion, converting current z and x to 0, so displayed object can be rotated only around y axis?

I use iOS, by the way, but guess this is not important here.

hbk
  • 10,908
  • 11
  • 91
  • 124
  • The whole point of quaternions is that you do _not_ convert them to pitch roll and yaw. Pitch roll and yaw are fatally flawed. – matt Nov 14 '16 at 21:39
  • @matt can u advice hot to do this in correct way? – hbk Nov 14 '16 at 21:40
  • I don't know what "do this" is. I have no idea what you _want_ to do. – matt Nov 14 '16 at 21:41
  • @matt I want to get rotation around y axis from received rotation matrix/quaternion from CoreMotion, converting current z and x to 0, so displayed object can be rotated only around y axis – hbk Nov 14 '16 at 21:46
  • Is this possible? – hbk Nov 14 '16 at 21:47
  • I don't know, but i don't see that anywhere in your question. If that is what your question is, I suggest that that is what you should be asking. – matt Nov 14 '16 at 21:49
  • By the way, I see this, which might help you: http://stackoverflow.com/questions/29830109/rotate-a-quaternion-by-euler-angles-input – matt Nov 14 '16 at 21:50
  • @matt update question, thanks for suggestion – hbk Nov 14 '16 at 21:51

0 Answers0