Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate object around a point using quaternions?

Tags:

math

3d

In my 3D application I store object's position in a vector and it's rotation around the origin in a quaternion. I need to rotate the object around a vector with an arbitrary origin. I tried converting the position - vectorOrigin and the rotation into a matrix, rotating the matrix and then extracting the position and rotation as a vector and a quaternion from the resulting matrix. The position comes up ok, but the rotation remains constant (the object rotates around the given vector but it always faces in the same direction).

Is my method wrong or do I have a bug?

like image 683
user17544 Avatar asked May 22 '09 16:05

user17544


People also ask

How do you rotate a point with quaternions?

Rotate Point Using Quaternion Vector For convenient visualization, define the point on the x-y plane. Create a quaternion vector specifying two separate rotations, one to rotate the point 45 and another to rotate the point -90 degrees about the z-axis. Use rotatepoint to perform the rotation. Plot the rotated points.


2 Answers

I'm not sure why do you expect the rotation to change. You have programmatic "creatures" representing the origin point, the destination point, and a rotation. Computing the destination point based on the other two "creatures" shouldn't affect them.

What about the usual approach? If you need to rotate the position (x, y, z) around the point (a, b, c), first translate the position so that the rotation will be around the origin: use (x-a, y-b, z-c) as the position, rotate around the origin as usual to get the new translated position (x'-a, y'-b, z'-c), and translate back and get your new position (x', y', z').

like image 186
Oren Shalev Avatar answered Oct 16 '22 00:10

Oren Shalev


I'm not familiar with quaternions, and maybe this is totally offtopic, but you can't rotate a 3d object around a point, the axis of rotation must be a line.

like image 24
Aric TenEyck Avatar answered Oct 16 '22 01:10

Aric TenEyck