# Moving an object toward another object on sphere knowing their quaternions

I have a sphere centered in world origin. On the sphere surface I have two objects and I know their quaternions (rotation around sphere).

Currently my movement works on Vector2 inputs (cannot change distance from sphere surface) concatenating the current movement quaternion to existing quaternion:

 RotationQuaternion *= Quaternion.CreateFromRotationMatrix(
Matrix.CreateRotationX(-_movementDirection.Y * Speed * deltaSeconds) *
Matrix.CreateRotationY(_movementDirection.X * Speed * deltaSeconds));


How would I move one object toward another? I have looked into quaternion lerping functionality, but this does not really help, as what I would ideally want is movement direction and apply my own speed and acceleration to it.

Thanks for any help - geometry is not my strongest suite!

On a sphere, the distance between two points is a product of the angular distance between them (ie: the angle between the vectors pointing from the sphere's center to those two points) and the radius of the sphere. The distance around a circle, the circumference is 2 * pi * r, where r is the radius. We can therefore divide the circumference by the ratio of the angle and 2pi (assuming angles in radians). So given the angle between two points on a circle, the distance between them is:

d = (angle / (2pi)) * (2pi * r)
d = angle * r


Once you have the distance between them, you can now pick any speed you want. With the distance, you can convert this into an angle; This angle represents the distance you want the object to move this frame. Given a speed of s and a frame time delta t, the distance you want to move is s * t. Therefore, the delta angle that represents this distance is:

d = angle * r
s * t = angle * r
angle = (s * t) / r


We now have an angle, but we need an axis to rotate around. That's easy too: it's the (normalized) cross-product between the two vectors. The order of the cross product is important. Use the right-hand rule: to go from P to Q, you want P x Q, not Q x P.

Given an angle and an axis, simply compute a quaternion from them with the usual means. Multiply that by your current quaternion to get the new one.

• What I'm doing currently is taking a cross product between 2 positions, normalizing it to get the rotation axis and then creating a quaternion from this axis providing the angle of how much to rotate and finally multiplying that to current quaternion. However I'm getting some really weird behavior... EDIT: Ah, silly me, I was multiplying my quaternions in the wrong order! Got it working, thanks! – Jaanus Varus Mar 7 '13 at 21:47