# Quaternion - rotating rigidBody to particular angle over time

Using Bullet Physics.

There's a rigid body that is rotated. For some delta-time I need to rotate that body to have rotation of (0, y, 0) - keep the old y value rotation but reset x and z. The position of the body is described by Quaternion. And, of course, I can modify the angular velocity.

So, how to calculate what angular velocity should I set for rigidBody to rotate to necessary rotation angle in delta-time? Seen this article: http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation, but it would be exageration to say if I understand how to implement those formulas...

Here's what I have as initial state of the rigidBody:

 rigidBody.getWorldTransform(tmpM1);
Quaternion rotation = new Quaternion();
tmpM1.getRotation(rotation);
Vector3 angles = new Vector3();
rotation.getAxisAngle(angles);

• Surely you mean the rotation is described by a quaternion? I don't see what's wrong with simply zeroning angles.x and angles.z, then using rotation.setAxisAngle(angles), constructing a new rotation matrix and setting the body's world transform. – jeffythedragonslayer Apr 24 '14 at 20:02
• Yes, rotation is described by a quaternion, and I can force it to be 0, y, 0, 0 if I want, and it's actually working. But the problem is that I need this rotation to go smoothly over time. Imagine rigid body hovering. When you put it into the air it can have some rotation, but when object reaches the top hovering altitude it needs to be straightened. I need to apply rotation tick by tick while object flies up – AAverin Apr 25 '14 at 3:09
• are you familiar with quaternion slerp? – jeffythedragonslayer Apr 25 '14 at 17:25
• No, just read about it. In library I use slerp looks like: public Quaternion slerp(Quaternion end, float alpha), where alpha is [0,1] range. Not sure how to apply this for smooth rotation though – AAverin Apr 26 '14 at 5:27
• Ok, reading more on lepr/slepr, looks like that 'alpha' is actually interpolation value, and the function yields rotation quaternion for current step. Thanks a lot, will try this out, should work. But still, would be interested to see a solution via AngularVelocity so the physics would work – AAverin Apr 26 '14 at 6:55